chesspao.java

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

JAVA
45
字号
package chs;

import java.util.List;

public class ChessPao extends ChessItem {

	public ChessPao(String id, int x, int y) {
		super(id, x, y);
	}

	public ChessPao(ChessBoard b, String id, int x, int y) {
		super(b, id, x, y);
	}

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

		boolean bTgt = (null != b.findItemAt(x, y));
		List lst = b.findItemOnLine(this.getX(), this.getY(), x, y);
		// 中间没子
		if (lst == null || lst.size() == 0) {
			// 目标点有子
			if (bTgt) {
				System.err.println("could not move to.");
				return false;
			}
		} else if (lst.size() == 1) {// 中间有1子
			// 目标点没有子
			if (!bTgt) {
				System.err.println("kill target is null.");
				return false;
			}
		} else {
			// 中间有超过1子
			System.err.println("more than 1 base for fire.");
			return false;
		}

		return true;
	}
}

⌨️ 快捷键说明

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