repared timer
This commit is contained in:
parent
47f14401a2
commit
b494861f8d
|
|
@ -19,6 +19,7 @@ public class Board {
|
||||||
private Move lastMove; // new field
|
private Move lastMove; // new field
|
||||||
private ArrayList<ArrayList<Boolean>> possibleMoves = new ArrayList<>();
|
private ArrayList<ArrayList<Boolean>> possibleMoves = new ArrayList<>();
|
||||||
private LinkedList<BoardHistory> boardHistory = new LinkedList<>();
|
private LinkedList<BoardHistory> boardHistory = new LinkedList<>();
|
||||||
|
public boolean timerSwitch = false;
|
||||||
|
|
||||||
public Board(int colNum, int lineNum) {
|
public Board(int colNum, int lineNum) {
|
||||||
this.width = colNum;
|
this.width = colNum;
|
||||||
|
|
@ -225,6 +226,7 @@ public class Board {
|
||||||
if (isHighlighted(x,y)) {
|
if (isHighlighted(x,y)) {
|
||||||
this.movePiece(x, y);
|
this.movePiece(x, y);
|
||||||
select = false;
|
select = false;
|
||||||
|
timerSwitch = true;
|
||||||
|
|
||||||
this.turnColor = !this.turnColor;
|
this.turnColor = !this.turnColor;
|
||||||
|
|
||||||
|
|
@ -397,6 +399,14 @@ public class Board {
|
||||||
public Move getLastMove() {
|
public Move getLastMove() {
|
||||||
return lastMove;
|
return lastMove;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isTimerSwitch() {
|
||||||
|
return timerSwitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimerSwitch(boolean timerSwitch) {
|
||||||
|
this.timerSwitch = timerSwitch;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ public class Game extends Thread {
|
||||||
private AutoPlayer aiPlayer;
|
private AutoPlayer aiPlayer;
|
||||||
private Board board;
|
private Board board;
|
||||||
|
|
||||||
private MyInterface mjf;
|
public MyInterface mjf;
|
||||||
private int COL_NUM = 8;
|
private int COL_NUM = 8;
|
||||||
private int LINE_NUM = 8;
|
private int LINE_NUM = 8;
|
||||||
private int loopDelay = 250;
|
private int loopDelay = 250;
|
||||||
|
|
@ -41,7 +41,7 @@ public class Game extends Thread {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isAITurn() {
|
private boolean isAITurn() {
|
||||||
return activationAIFlags[board.isTurnWhite()?1:0];
|
return activationAIFlags[board.isTurnWhite()?1:0];
|
||||||
}
|
}
|
||||||
|
|
@ -53,6 +53,7 @@ public class Game extends Thread {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
board.playMove(aiPlayer.computeBestMove(board.getBoard(),board.isTurnWhite(),board.getLastMove()));
|
board.playMove(aiPlayer.computeBestMove(board.getBoard(),board.isTurnWhite(),board.getLastMove()));
|
||||||
|
mjf.timerManager.switchTurn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -67,13 +68,17 @@ public class Game extends Thread {
|
||||||
if(!isAITurn()) {
|
if(!isAITurn()) {
|
||||||
if (aiPlayer.getAllLegalMoves(board.getBoard(), board.isTurnWhite(),board.getLastMove()).size() != 0){
|
if (aiPlayer.getAllLegalMoves(board.getBoard(), board.isTurnWhite(),board.getLastMove()).size() != 0){
|
||||||
board.userTouch(x, y);
|
board.userTouch(x, y);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mjf.showGameOverMessage("Game Over");
|
mjf.showGameOverMessage("Game Over");
|
||||||
}
|
}
|
||||||
|
if (board.isTimerSwitch()) {
|
||||||
|
mjf.timerManager.switchTurn();
|
||||||
|
board.setTimerSwitch(false);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPiece(int x, int y, PieceType type, boolean isWhite) {
|
public void setPiece(int x, int y, PieceType type, boolean isWhite) {
|
||||||
|
|
@ -100,11 +105,11 @@ public class Game extends Thread {
|
||||||
public Iterable<Piece> getPieces() {
|
public Iterable<Piece> getPieces() {
|
||||||
return board.getPieces();
|
return board.getPieces();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCheck(int x, int y) {
|
public boolean isCheck(int x, int y) {
|
||||||
return board.isCheck(x, y);
|
return board.isCheck(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSelected(int x, int y) {
|
public boolean isSelected(int x, int y) {
|
||||||
return board.isSelected(x, y);
|
return board.isSelected(x, y);
|
||||||
}
|
}
|
||||||
|
|
@ -118,25 +123,25 @@ public class Game extends Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toggleAI(boolean isWhite) {
|
public void toggleAI(boolean isWhite) {
|
||||||
// System.out.println(isWhite);
|
// System.out.println(isWhite);
|
||||||
this.activationAIFlags[isWhite?1:0] = !this.activationAIFlags[isWhite?1:0];
|
this.activationAIFlags[isWhite?1:0] = !this.activationAIFlags[isWhite?1:0];
|
||||||
if (this.activationAIFlags[isWhite?1:0]) {
|
if (this.activationAIFlags[isWhite?1:0]) {
|
||||||
soundEffect.aiSound();
|
soundEffect.aiSound();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTurnNumber(int turnNumber) {
|
public void setTurnNumber(int turnNumber) {
|
||||||
board.setTurnNumber(turnNumber);
|
board.setTurnNumber(turnNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTurnColor(boolean turnColor) {
|
public void setTurnColor(boolean turnColor) {
|
||||||
board.setTurnColor(turnColor);
|
board.setTurnColor(turnColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTurnNumber() {
|
public int getTurnNumber() {
|
||||||
return board.getTurnNumber();
|
return board.getTurnNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getTurnColor() {
|
public boolean getTurnColor() {
|
||||||
return board.isTurnColor();
|
return board.isTurnColor();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue