chessshi.java

来自「ajax chessajax chessajax chessajax chess」· Java 代码 · 共 37 行

JAVA
37
字号
package chs;

public class ChessShi extends ChessItem {

	public ChessShi(String id, int x, int y) {
		super(id, x, y);
		// TODO Auto-generated constructor stub
	}

	public ChessShi(ChessBoard b, String id, int x, int y) {
		super(b, id, x, y);
		// TODO Auto-generated constructor stub
	}

	public boolean isOnDiag(int x, int y){
		int dx = Math.abs(this.x - x);
		int dy = Math.abs(this.y - y);
		return dx == dy && dy == 1;
	}

	public boolean moveTo(int x, int y) {
		if (!this.isOnDiag(x, y)) {
			System.err.println("not on a diag.");
			return false;
		}

		// 不在王宫里
		if (this.isInBase(x, y)) {
			System.err.println("move out of palace.");
			return false;
		}
		
		return true;
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?