📄 position.java
字号:
/*
Copyright (C) 2004 Julia Handl
Email: Julia.Handl@gmx.de
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*****************************************************************
Julia Handl - 18004385
Monash University, 1.7.2001
File: Position.java
Package: JavaAnts
Description:
* Represents a poition on the grid
*****************************************************************/
package javaants;
import java.io.*;
import java.lang.*;
/** A two dimensional position on the grid */
public class Position implements Serializable {
private int x;
private int y;
/** Constructor with provided coordinate values
* @param x x-coordinate
* @param y y-coordinate
*/
public Position(int y, int x) {
this.y = y;
this.x = x;
}
/** Default constructor, initialising position to (0, 0) */
public Position() {
this.y = 0;
this.x = 0;
}
/** Get x coordinate
* @return x-coordinate
*/
public int getX() {
return this.x;
}
/** Get y coordinate
* @return y-coordinate
*/
public int getY() {
return this.y;
}
/** Change coordinates
* @param x new x-coordinate
* @param y new y-coordinate
*/
public void set(int y, int x) {
this.x = x;
this.y = y;
}
/** Overwrite current position
* @param pos new position
*/
public void set(Position pos) {
this.y = pos.getY();
this.x = pos.getX();
}
/** Translate position
* @param y translation in y direction
* @param x translation in x direction
*/
public void move(int y, int x) {
this.y += y;
this.x += x;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -