startplay with update render

This commit is contained in:
Aubin DORIVAL
2025-04-07 10:17:46 +02:00
parent 23dec92e66
commit a7214f796f

View File

@@ -24,7 +24,6 @@ public class GomokuGame {
Color colorP1; Color colorP1;
int currentPlayerInt; int currentPlayerInt;
int nbTokens1, nbTokens2;
Coordinate cellCoor = null; Coordinate cellCoor = null;
@@ -58,8 +57,7 @@ public class GomokuGame {
this.colorP1 = colorPlayer1; this.colorP1 = colorPlayer1;
currentPlayer = this.player1.color == Color.WHITE ? this.player1: this.player2; currentPlayer = this.player1.color == Color.WHITE ? this.player1: this.player2;
this.currentPlayerInt = this.player1.color == Color.WHITE ? 1 : 2; this.currentPlayerInt = this.player1.color == Color.WHITE ? 1 : 2;
this.nbTokens1 = 60; this.renderer = new SwingRenderer();
this.nbTokens2 = 60;
} }
@@ -71,21 +69,21 @@ public class GomokuGame {
System.out.println("c'est gangée !"); System.out.println("c'est gangée !");
} }
*/ */
while(this.nbTokens1 > 0 && this.nbTokens2 > 0){ while(this.player1.tokens > 0 || this.player2.tokens > 0){
}
GomokuCell currentPlay = null; GomokuCell currentPlay = null;
while (currentPlay == null) { while (currentPlay == null) {
currentPlay = this.play(this.currentPlayer); currentPlay = this.play(this.currentPlayer);
} }
this.currentPlayer = this.nextPlayer();
if( NB_CELL_PLAY <= board.countMax(board.countAlignedCells(currentPlay))) if( NB_CELL_PLAY <= board.countMax(board.countAlignedCells(currentPlay)))
{ {
System.out.println("c'est gangée !"); this.renderer.updateStatus("Le joueur " + this.currentPlayer + "a gagné !");
return; return;
} }
this.currentPlayer = this.nextPlayer();
}
this.renderer.updateStatus("Match nul, il ne reste plus de jeton.");
return;
} }
/** /**
@@ -142,8 +140,8 @@ public class GomokuGame {
this.getBoard().getHeight(), this.getBoard().getHeight(),
colorP1, colorP1,
currentPlayerInt, currentPlayerInt,
nbTokens1, this.player1.tokens,
nbTokens2 this.player2.tokens
)); ));
// Write the board // Write the board
@@ -205,8 +203,8 @@ public class GomokuGame {
h = Integer.parseInt(parts[1]); h = Integer.parseInt(parts[1]);
colorP1 = Color.valueOf(parts[2]); colorP1 = Color.valueOf(parts[2]);
currentPlayerInt = Integer.parseInt(parts[3]); currentPlayerInt = Integer.parseInt(parts[3]);
nbTokens1 = Integer.parseInt(parts[4]); this.player1.tokens = Integer.parseInt(parts[4]);
nbTokens2 = Integer.parseInt(parts[5]); this.player2.tokens = Integer.parseInt(parts[5]);
if (w <= 0 || h <= 0) { if (w <= 0 || h <= 0) {
throw new IllegalArgumentException("Invalid board dimensions"); throw new IllegalArgumentException("Invalid board dimensions");