timer start when you touch a piece for the first time

This commit is contained in:
Romain MURPHY 2025-05-09 15:05:54 +02:00
parent 7ec9b00a44
commit 2132234667
3 changed files with 13 additions and 3 deletions

View File

@ -20,6 +20,7 @@ public class Board {
private ArrayList<ArrayList<Boolean>> possibleMoves = new ArrayList<>();
private LinkedList<BoardHistory> boardHistory = new LinkedList<>();
public boolean timerSwitch = false;
public boolean timerStart = true;
public Board(int colNum, int lineNum) {
this.width = colNum;
@ -214,6 +215,7 @@ public class Board {
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())) {
timerStart = false;
this.xm = x;
this.ym = y;
select = true;
@ -408,6 +410,9 @@ public class Board {
this.timerSwitch = timerSwitch;
}
public boolean getTimerStart() {
return timerStart;
}
}
/////

View File

@ -65,6 +65,9 @@ public class Game extends Thread {
System.out.println("Click out of bounds");
return;
}
if (board.getTimerStart()) {
mjf.startTimer(board.isTurnColor());
}
if(!isAITurn()) {
if (aiPlayer.getAllLegalMoves(board.getBoard(), board.isTurnWhite(),board.getLastMove()).size() != 0){
board.userTouch(x, y);

View File

@ -181,7 +181,6 @@ public class MyInterface extends JFrame {
if (timerManager == null)
timerManager = new TimerManager(whiteTimerLabel, blackTimerLabel, () -> gameOverByTimeout(), time);
timerManager.reset(time);
timerManager.start(true); // white starts
}
public void clickButtonAdder() {
panelDraw.toggleAdderMode();
@ -377,6 +376,9 @@ public class MyInterface extends JFrame {
return 1;
}
public void startTimer(boolean isWhite) {
timerManager.start(isWhite);
}
public void gameOverByTimeout() {