软件构造Lab2-Playing Chess
ADT设计/实现方案
对于Player、Board、Piece、Action都设计一个接口和go、chess两个继承类。以下展示接口中的方法以及类中除实现接口中已存在的方法的独立方法。
Player接口:
方法说明
public void addPiece(Piece addPiece); 用于添加棋子到玩家集合
public void removePiece(Piece removePiece); 用于从玩家集合移除棋子
public Set getPiecesSet(); 获取玩家的棋子集合
goPlayer:
方法说明
public goPlayer(String playerName) 设置棋子名
ChessPlayer:
方法说明
public chessPlayer(String playerName) 设置初始棋子集合与棋子名
Board接口:
//获取棋子
public Piece getPiece(int x,int y);
//检查点
public boolean checkPoint(int x,int y);
//在棋盘上添加
public void add(Piece position,int x,int y);
//在棋盘上移除
public void remove(int x,int y);
//在棋盘上移动
public void move(int x,int y,int x1,int y1);
goBoard:
private final int boardSize = 19;
Piece boardJuzhen[][] = new Piece[boardSize][boardSize];
goAction action1 = new goAction();
方法说明
public goBoard() 初始化棋盘
public void showGoBoard() 展示棋盘
public void showGoBoard() 展示棋盘
Chessboard:
private final int boardSize = 8;
Piece theboard[][] = new Piece[boardSize][boardSize];
chessAction action1 = new chessAction();
方法说明
public chessBoard(chessPlayer chessPlayer1, chessPlayer chessPlayer2) 调用棋盘初始化
public void initChessBoard 初始化棋盘
public void showChessBoard 展示棋盘
Piece接口:
//get the type of piece
public String getType();
//get the wether the piece is used
public boolean getUsed();
//set piece
public void setPiece(String pieceName);
//set the wether the piece is used
public void setUsed();
public void setBackUsed();
Gopiece:
方法 说明
public goPiece(String color) 构造棋子
Chesspiece:
方法 说明
public chessPiece(String pieceName) 构造象棋棋子
Action接口:
//添加
public void add(Piece theboard[][],Piece piece1,int x,int y);
//移除
public void remove(Piece theboard[][],int x,int y);
//移动
public void move(Piece theboard[][],int x,int y,int x1,int y1);
goaction和chessaction都只需按照需要重写action中的方法即可。
以下是ADT中的其他类:
Position:
int x;
int y;
Piece Piece1;
方法 说明
public Position 构造位置
public int getX() 获取x
public int getY() 获取y
Game:
String gameTypeString;
List historyList = new ArrayList();
方法 说明
public Game(String gameTypeString) 初始游戏类型
private static void ChessMenu() 象棋菜单
private static void GoMenu() 围棋菜单
public void gameStart() 游戏主程序
public void showHistory() 展示游戏历史
主程序MyChessAndGoGame设计/实现方案
GAMEmenu:
GAMEmenu类用来运行游戏主界面如下:
选择分支如下:
接下来进入GAME类中执行public void gameStart()方法。
读取用户的选择,若移动棋子,再输入相应坐标,调用ADT的各个部分执行操作。