📄 chessboardimpl.java
字号:
/* * ChessboardImpl.java * * Created on 2007-9-28, 16:03:53 * * To change this template, choose Tools | Templates * and open the template in the editor. */package org.yangcq.logic.chessboard;import org.yangcq.logic.exception.BaseException;import org.yangcq.logic.player.IPlayer;import org.yangcq.logic.step.Step;/** * * @author Administrator */public final class ChessboardImpl implements IChessboard{ private IPlayer[] players; //两个选手,0号执黑,1号执白 private IPlayer currentPlayer; //当前选手 private int index = 0; private Step[][] chessboard; //棋盘 private static IChessboard board; //单例 public boolean chess(int x, int y) { if (this.chessboard[x][y] == null || this.chessboard[x][y].getColor() == null) { this.chessboard[x][y] = new Step(x, y, new Boolean(this.currentPlayer.isChessmanBlack())); index = 1 - index; this.currentPlayer = this.players[index]; return true; } return false; } private ChessboardImpl() { this.chessboard = new Step[8][8]; this.chessboard[3][3] = new Step(3, 3, new Boolean(false)); this.chessboard[4][4] = new Step(4, 4, new Boolean(false)); this.chessboard[3][4] = new Step(3, 4, new Boolean(true)); this.chessboard[4][3] = new Step(4, 3, new Boolean(true)); } public static IChessboard getChessboard() { if (board == null) { board = new ChessboardImpl(); } return board; } public void setPlayers(IPlayer[] players) throws BaseException { if (players == null || players.length != 2) { throw new BaseException("未提供正确的选手"); } this.players = players; this.currentPlayer = this.players[0]; } public Step[][] getBoard() { return this.chessboard; } public void setBoard(Step[][] board) { this.chessboard = board; } public IPlayer[] getPlayers() { return this.players; } public IPlayer getCurrentPlayer() { return this.currentPlayer; } public Step[][] getBoardCopy() { Step[][] copy = new Step[this.chessboard.length][this.chessboard.length]; for (int i = 0; i < this.chessboard.length; i++) { for (int j = 0; j < this.chessboard.length; j++) { if (this.chessboard[i][j] != null) { copy[i][j] = this.chessboard[i][j].clone(); } } } return copy; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -