📄 player.java
字号:
package org.yushang.jumpchess.pkg;
import org.yushang.jumpchess.pub.*;
public abstract class Player {
private String name = "anonymity";
private Color color = null;
private BoardArea area = null;
protected ChessBoard chessboard = null;
protected Chess[] chesses = null;
protected Position[] path = null;
protected Chess GoChess = null;
protected Player oppsitePlayer = null;
final static public int CHESSCOUNT = 10;
final static public int MouseClick = 100;
final static public int MouseRight = 101;
final static public int MouseNull = 102;
public Player(ChessBoard chessboard, String name, Color color, BoardArea area) {
this.chessboard = chessboard;
this.name = name;
this.color = color;
this.area = area;
chesses = CreateChesses();
}
public boolean Winned() {
Position[] AreaPositions = area.getOppsiteArea().getAreaPositions();
Chess chess = null;
for (int i = 0; i < AreaPositions.length; i++) {
chess = chessboard.getChess(AreaPositions[i]);
if (chess == null) {
return false;
}
if (chess.GetColor() != this.GetColor()) {
return false;
}
}
return true;
}
public void Go(Chess chess, Position position) {
if (chess.GetColor() != this.GetColor()) {
throw new RuntimeException("棋子不是该玩家的");
}
chessboard.Go(chess, position);
}
public abstract boolean Run(int Mouse, Position position);
public Color GetColor() {
return color;
}
public String getName() {
return name;
}
public BoardArea getArea() {
return area;
}
public Chess getGoChess() {
return GoChess;
}
public Position[] getPath() {
return path;
}
public Player getOppsite() {
return oppsitePlayer;
}
public void setOppsite(Player player) {
oppsitePlayer = player;
}
private Chess[] CreateChesses() {
Chess[] chesses = new Chess[10];
int index = 0;
for (int i = 0; i < chessboard.getChessCount(); i++) {
if (chessboard.getChess(i).GetColor() == color) {
chesses[index] = chessboard.getChess(i);
index++;
if (index == 10) {
break;
}
}
}
return chesses;
}
public Chess[] getChesses() {
return chesses;
}
protected Position[] CreatePath(Chess GoChess, Position destPosition) {
Map map = chessboard.CanGo(GoChess);
int source = map.indexOfByData(chessboard.getPosition(GoChess));
int dest = map.indexOfByData(destPosition);
if (dest == -1) {
GoChess = null;
return null;
}
Node sourceNode = map.get(source);
Node destNode = map.get(dest);
Nodes nodes = map.getShotestPath(sourceNode, destNode);
//System.out.println("------Path--------");
Position[] positions = new Position[nodes.size()];
for (int i = 0; i < positions.length; i++) {
positions[i] = (Position) nodes.get(positions.length - i - 1).data;
//System.out.println(positions[i].toString());
}
return positions;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -