package Core;

/**
 * Represents a field on the playboard
 */
public class Field {
	/**
	 * Instance variables
	 */
	private int x;
	private int y;
	private boolean passable = true;
	private boolean explodable = true;

	/********* Constructor *********/
	
	/**
	 * Constructor
	 * @param x   x-coordiante 
	 * @param y   y-coordiante 
	 */
	public Field(int x, int y) {
		this.x = x;
		this.y = y;
	}
	
	/**
	 * Constructor
	 * @param x				x-coordiante 
	 * @param y				y-coordiante 
	 * @param passable		is the field passable?
	 * @param explodable	is the field explodable?
	 */
	public Field(int x, int y, boolean passable, boolean explodable) {
		this.x = x;
		this.y = y;
		this.passable = passable;
		this.explodable = explodable;
	}

	/**
	 * Constructor for clone
	 * @param field
	 */
	private Field(Field field) {
		this.x = field.x;
		this.y = field.y;
		this.passable = field.passable;
		this.explodable = field.explodable;
	}
	
	/**
	 * Returns a exact copy of the object
	 */
	public Field clone() {
		return new Field(this);
	}
	
	/********* Getters *********/
	
	/**
	 * Returns the x-coordinate of the field
	 * @return x
	 */	
	public int getX() {
		return x;
	}	

	/**
	 * Returns the y-coordinate of the field
	 * @return y
	 */	
	public int getY() {
		return y;
	}

	/**
	 * Is the field passable?
	 * @return passable?
	 */
	public boolean isPassable() {
		return passable;
	}
	
	/**
	 * Is the field explodable?
	 * @return explodable?
	 */
	public boolean isExplodable() {
		return explodable;
	}	

	/**
	 * Is the field not explodable and not passable?
	 * @return wall?
	 */
	public boolean isWall(){
		return !passable && !explodable;
	}
	
	/********* Setters *********/
	
	/**
	 * Sets the x-coordiante
	 * @param x
	 */
	public void setX(int x) {
		this.x = x;
	}

	/**
	 * Sets the y-coordiante
	 * @param y
	 */
	public void setY(int y) {
		this.y = y;
	}
	
	/**
	 * Sets whether the field is passable or not
	 * @param passable
	 */
	public void setPassable(boolean passable) {
		this.passable = passable;
	}
	
	/**
	 * Sets whether the field is explodable or not
	 * @param explodable
	 */	
	public void setExplodable(boolean explodable) {
		this.explodable = explodable;
	}

	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + x;
		result = prime * result + y;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Field other = (Field) obj;
		if (x != other.x)
			return false;
		if (y != other.y)
			return false;
		return true;
	}

}
最近下载更多
adap12345  LV5 2023年6月8日
hkxyyz  LV6 2023年3月2日
总有人间一两风  LV8 2022年12月12日
liangge2115  LV27 2022年11月7日
微信网友_6004879537377280  LV3 2022年6月22日
jytjyt  LV1 2021年12月16日
ssssqweq  LV1 2021年11月1日
此次东方  LV1 2021年10月20日
qliu0130  LV1 2021年10月10日
zpy123  LV1 2021年7月18日
最近浏览更多
ClydeSon  LV5 2023年12月27日
bangyiyang  LV2 2023年12月21日
1112WHQ  LV7 2023年11月3日
微信网友_6672184532766720  LV3 2023年10月6日
srrrrrr 2023年9月19日
暂无贡献等级
adap12345  LV5 2023年6月8日
laa94698 2023年4月21日
暂无贡献等级
hkxyyz  LV6 2023年3月2日
k麝神k  LV10 2022年12月21日
wwfl02  LV3 2022年12月16日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友