This commit is contained in:
Aubin DORIVAL
2025-04-07 10:53:35 +02:00
parent a7214f796f
commit 0151a74e4b

View File

@@ -26,10 +26,13 @@ public class GomokuGame {
int currentPlayerInt;
Coordinate cellCoor = null;
GomokuGame(boolean renderer){
this.playRenderer = renderer;
}
public static void main(String[] args) {
// Test
GomokuGame g = new GomokuGame();
GomokuGame g = new GomokuGame(false);
System.out.println(g.load(Path.of(".cache/test.dat")));
g.renderer = new ConsoleRenderer();
g.renderer.init(g);
@@ -38,6 +41,14 @@ public class GomokuGame {
g.renderer.update();
}
/**
* This method init the game with these parameters.
* @param bot If the player want to play with a bot it's true.
* @param name1 Name of player one.
* @param name2 Name of player two.
* @param tokens Number of tokens for each player.
*/
public void newGame(boolean bot, String name1, String name2, int tokens) {
Color[] possible = { Color.WHITE, Color.BLACK };
int rnd = new Random().nextInt(possible.length);
@@ -61,6 +72,9 @@ public class GomokuGame {
}
/**
* This method is the main loop of the game
*/
public void startGame() {
/*
GomokuCell actualPlayedCell = play(player1);
@@ -80,6 +94,7 @@ public class GomokuGame {
this.renderer.updateStatus("Le joueur " + this.currentPlayer + "a gagné !");
return;
}
this.currentPlayer.tokens -= 1;
this.currentPlayer = this.nextPlayer();
}
this.renderer.updateStatus("Match nul, il ne reste plus de jeton.");
@@ -103,7 +118,7 @@ public class GomokuGame {
}
}
cellToPlay= this.board.get(this.cellCoor.x, this.cellCoor.y);
if (!cellToPlay.isPlayable()) { // If the cell is not playable we return null to not play.
if (cellToPlay == null || !cellToPlay.isPlayable()) { // If the cell is not playable we return null to not play.
return null;
}
cellToPlay.setState(player.color);
@@ -118,7 +133,11 @@ public class GomokuGame {
}
/**
* This method save the game on a file.
* @param filename The file to save.
* @return True if successful and false if not.
*/
public boolean save(Path filename) {
// save the game state to the file
// 1. Open the file
@@ -177,6 +196,11 @@ public class GomokuGame {
return true;
}
/**
* This method load a game on the file.
* @param filename The file to load.
* @return True if successful and False if not.
*/
public boolean load(Path filename) {
// load the game state from the file
// 1. Open the file
@@ -259,6 +283,10 @@ public class GomokuGame {
return true;
}
/**
* This method return the next player to play.
* @return The next player.
*/
private Player nextPlayer(){
if (this.currentPlayer == this.player1){
return this.player2;
@@ -266,6 +294,9 @@ public class GomokuGame {
return player1;
}
/**
* Get the board.
*/
public GomokuBoard getBoard() {
return this.board;
}