timer start when you touch a piece for the first time
This commit is contained in:
parent
7ec9b00a44
commit
2132234667
|
|
@ -20,6 +20,7 @@ public class Board {
|
||||||
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 boolean timerSwitch = false;
|
||||||
|
public boolean timerStart = true;
|
||||||
|
|
||||||
public Board(int colNum, int lineNum) {
|
public Board(int colNum, int lineNum) {
|
||||||
this.width = colNum;
|
this.width = colNum;
|
||||||
|
|
@ -214,6 +215,7 @@ public class Board {
|
||||||
|
|
||||||
public void userTouch(int x, int y) {
|
public void userTouch(int x, int y) {
|
||||||
if ((this.select == false && board.get(y).get(x) != null && this.board.get(y).get(x).isWhite() == turnColor) || (select == true && board.get(y).get(x) != null && board.get(y).get(x).isWhite() == board.get(ym).get(xm).isWhite())) {
|
if ((this.select == false && board.get(y).get(x) != null && this.board.get(y).get(x).isWhite() == turnColor) || (select == true && board.get(y).get(x) != null && board.get(y).get(x).isWhite() == board.get(ym).get(xm).isWhite())) {
|
||||||
|
timerStart = false;
|
||||||
this.xm = x;
|
this.xm = x;
|
||||||
this.ym = y;
|
this.ym = y;
|
||||||
select = true;
|
select = true;
|
||||||
|
|
@ -407,7 +409,10 @@ public class Board {
|
||||||
public void setTimerSwitch(boolean timerSwitch) {
|
public void setTimerSwitch(boolean timerSwitch) {
|
||||||
this.timerSwitch = timerSwitch;
|
this.timerSwitch = timerSwitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getTimerStart() {
|
||||||
|
return timerStart;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/////
|
/////
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,9 @@ public class Game extends Thread {
|
||||||
System.out.println("Click out of bounds");
|
System.out.println("Click out of bounds");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (board.getTimerStart()) {
|
||||||
|
mjf.startTimer(board.isTurnColor());
|
||||||
|
}
|
||||||
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);
|
||||||
|
|
|
||||||
|
|
@ -181,7 +181,6 @@ public class MyInterface extends JFrame {
|
||||||
if (timerManager == null)
|
if (timerManager == null)
|
||||||
timerManager = new TimerManager(whiteTimerLabel, blackTimerLabel, () -> gameOverByTimeout(), time);
|
timerManager = new TimerManager(whiteTimerLabel, blackTimerLabel, () -> gameOverByTimeout(), time);
|
||||||
timerManager.reset(time);
|
timerManager.reset(time);
|
||||||
timerManager.start(true); // white starts
|
|
||||||
}
|
}
|
||||||
public void clickButtonAdder() {
|
public void clickButtonAdder() {
|
||||||
panelDraw.toggleAdderMode();
|
panelDraw.toggleAdderMode();
|
||||||
|
|
@ -376,7 +375,10 @@ public class MyInterface extends JFrame {
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void startTimer(boolean isWhite) {
|
||||||
|
timerManager.start(isWhite);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void gameOverByTimeout() {
|
public void gameOverByTimeout() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue