mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 02:44:50 +00:00
Changed the way turns are being stored in TurnBasedGame.
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user