Changed the way turns are being stored in TurnBasedGame.

This commit is contained in:
2025-11-27 18:37:34 +01:00
parent 6ea94fe658
commit 0cb025edb9

View File

@@ -1,26 +1,25 @@
package org.toop.game;
public abstract class TurnBasedGame extends Game {
private final int turns;
private int currentTurn;
private final int playerCount; // How many players are playing
private int turn = 0; // What turn it is in the game
protected TurnBasedGame(int rowSize, int columnSize, int turns) {
protected TurnBasedGame(int rowSize, int columnSize, int playerCount) {
super(rowSize, columnSize);
assert turns >= 2;
this.turns = turns;
this.playerCount = playerCount;
}
protected TurnBasedGame(TurnBasedGame other) {
super(other);
turns = other.turns;
currentTurn = other.currentTurn;
playerCount = other.playerCount;
turn = other.turn;
}
protected void nextTurn() {
currentTurn = (currentTurn + 1) % turns;
turn += 1;
}
public int getCurrentTurn() {
return currentTurn;
return turn % playerCount;
}
}