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; package org.toop.game;
public abstract class TurnBasedGame extends Game { public abstract class TurnBasedGame extends Game {
private final int turns; private final int playerCount; // How many players are playing
private int currentTurn; 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); super(rowSize, columnSize);
assert turns >= 2; this.playerCount = playerCount;
this.turns = turns;
} }
protected TurnBasedGame(TurnBasedGame other) { protected TurnBasedGame(TurnBasedGame other) {
super(other); super(other);
turns = other.turns; playerCount = other.playerCount;
currentTurn = other.currentTurn; turn = other.turn;
} }
protected void nextTurn() { protected void nextTurn() {
currentTurn = (currentTurn + 1) % turns; turn += 1;
} }
public int getCurrentTurn() { public int getCurrentTurn() {
return currentTurn; return turn % playerCount;
} }
} }