chessbing.java

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

JAVA
55
字号
package chs;

public class ChessBing extends ChessItem {

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

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

	public boolean isBackward(int y){
		if(id.charAt(0) == 'r'){
			return this.y > y;
		}else{
			return this.y < y;
		}
	}
	
	public boolean isCrab(int x){
		return this.x != x;
	}
	
	public boolean canCrab(){
		if(id.charAt(0) == 'r'){
			return this.y >= 6;
		}else{
			return this.y <= 5;
		}
	}

	public boolean moveTo(int x, int y){
		if(!this.isOnStep(x, y)){
			System.err.println("move over 1 step.");
			return false;
		}
		
		if(this.isBackward( y)){
			System.err.println("backward move for bing.");
			return false;
		}
		
		// 横着走了
		if(!this.canCrab() && this.isCrab(x)){
			System.err.println("crab move on self kingdom.");
			return false;
		}
		
		return true;
	}
};

⌨️ 快捷键说明

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