feat: implement GameState.snapshot and make entities cloneable
This commit is contained in:
@ -9,6 +9,7 @@ import uulm.teamname.marvelous.gamelibrary.Tuple;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
/** Represents the state of a game instance. */
|
||||
class GameState {
|
||||
@ -22,13 +23,13 @@ class GameState {
|
||||
public int roundNumber = 0;
|
||||
|
||||
/** The turn order of every character */
|
||||
public ArrayList<EntityID> turnOrder;
|
||||
public ArrayList<EntityID> turnOrder = new ArrayList<>();
|
||||
|
||||
/** The total amount of turns that occurred */
|
||||
public int turnNumber = 0;
|
||||
|
||||
/** The {@link EntityID} of the active character */
|
||||
public EntityID activeCharacter;
|
||||
public EntityID activeCharacter = null;
|
||||
|
||||
/** Whether or not the game was won */
|
||||
public boolean won = false;
|
||||
@ -48,11 +49,37 @@ class GameState {
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones the state into a new {@link GameState} object.
|
||||
* Clones the state into a new {@link GameState} object. This is slow.
|
||||
* @return The cloned game state
|
||||
*/
|
||||
public GameState snapshot() {
|
||||
//TODO: implement GameState.snapshot
|
||||
return this;
|
||||
GameState clone = new GameState(this.mapSize);
|
||||
|
||||
for(Iterator<Entity> it = this.entities.getEntities(); it.hasNext(); ) {
|
||||
clone.entities.addEntity(it.next().clone());
|
||||
}
|
||||
|
||||
clone.roundNumber = roundNumber;
|
||||
|
||||
clone.turnOrder = new ArrayList<>();
|
||||
for(EntityID id: turnOrder) {
|
||||
clone.turnOrder.add(id.clone());
|
||||
}
|
||||
|
||||
clone.turnNumber = turnNumber;
|
||||
|
||||
clone.activeCharacter = activeCharacter != null ? activeCharacter.clone() : null;
|
||||
|
||||
clone.won = won;
|
||||
|
||||
for(StoneType type: stoneCooldown.keySet()) {
|
||||
clone.stoneCooldown.put(type, stoneCooldown.get(type));
|
||||
}
|
||||
|
||||
for(Tuple<ParticipantType, WinCondition> condition: winConditions.keySet()) {
|
||||
clone.winConditions.put(condition, winConditions.get(condition));
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user