fix: add configs to GameInstance and fix GameState snapshots

This commit is contained in:
punchready 2021-05-31 18:07:43 +02:00
parent ab011e54da
commit 7c36ea5c5c
4 changed files with 31 additions and 9 deletions

View File

@ -3,6 +3,9 @@ package uulm.teamname.marvelous.gamelibrary.gamelogic;
import uulm.teamname.marvelous.gamelibrary.IntVector2;
import uulm.teamname.marvelous.gamelibrary.events.Event;
import uulm.teamname.marvelous.gamelibrary.events.EventType;
import uulm.teamname.marvelous.gamelibrary.json.config.CharacterConfig;
import uulm.teamname.marvelous.gamelibrary.json.config.PartyConfig;
import uulm.teamname.marvelous.gamelibrary.json.config.ScenarioConfig;
import uulm.teamname.marvelous.gamelibrary.requests.Request;
import java.util.Observer;
@ -22,8 +25,8 @@ public class GameInstance {
private final EventEmitter emitter = new EventEmitter();
/** Constructs a new {@link GameInstance}. */
public GameInstance(IntVector2 mapSize) {
_state = new GameState(mapSize);
public GameInstance(PartyConfig partyConfig, CharacterConfig characterConfig, ScenarioConfig scenarioConfig) {
_state = new GameState(partyConfig, characterConfig, scenarioConfig);
this.state = new GameStateView(_state);
manager = new GameStateManager(_state);
}

View File

@ -2,6 +2,9 @@ package uulm.teamname.marvelous.gamelibrary.gamelogic;
import uulm.teamname.marvelous.gamelibrary.IntVector2;
import uulm.teamname.marvelous.gamelibrary.entities.*;
import uulm.teamname.marvelous.gamelibrary.json.config.CharacterConfig;
import uulm.teamname.marvelous.gamelibrary.json.config.PartyConfig;
import uulm.teamname.marvelous.gamelibrary.json.config.ScenarioConfig;
import java.util.ArrayList;
import java.util.Arrays;
@ -12,6 +15,10 @@ class GameState {
/** The size of the map */
public final IntVector2 mapSize;
public final PartyConfig partyConfig;
public final CharacterConfig characterConfig;
public final ScenarioConfig scenarioConfig;
/** The list of {@link Entity}s inside the game */
public final EntityManager entities = new EntityManager();
@ -40,11 +47,13 @@ class GameState {
public final WinConditionManager winConditions = new WinConditionManager();
/**
* Constructs a new {@link GameState}.
* @param mapSize The size of the map
* Constructs a new {@link GameState} with the given config.
*/
public GameState(IntVector2 mapSize) {
this.mapSize = mapSize;
public GameState(PartyConfig partyConfig, CharacterConfig characterConfig, ScenarioConfig scenarioConfig) {
this.mapSize = new IntVector2(scenarioConfig.scenario[0].length, scenarioConfig.scenario.length);
this.partyConfig = partyConfig;
this.characterConfig = characterConfig;
this.scenarioConfig = scenarioConfig;
}
/**
@ -52,10 +61,12 @@ class GameState {
* @return The cloned game state
*/
public GameState snapshot() {
GameState clone = new GameState(this.mapSize);
GameState clone = new GameState(partyConfig, characterConfig, scenarioConfig);
clone.entities.cloneFrom(entities);
clone.unvomitedStones = new HashSet<>(unvomitedStones);
clone.roundNumber = roundNumber;
clone.turnOrder = new ArrayList<>();
@ -85,6 +96,8 @@ class GameState {
entities.cloneFrom(state.entities);
unvomitedStones = new HashSet<>(state.unvomitedStones);
roundNumber = state.roundNumber;
turnOrder = new ArrayList<>();

View File

@ -7,6 +7,9 @@ import uulm.teamname.marvelous.gamelibrary.entities.*;
import uulm.teamname.marvelous.gamelibrary.entities.Character;
import uulm.teamname.marvelous.gamelibrary.events.Event;
import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
import uulm.teamname.marvelous.gamelibrary.json.config.CharacterConfig;
import uulm.teamname.marvelous.gamelibrary.json.config.PartyConfig;
import uulm.teamname.marvelous.gamelibrary.json.config.ScenarioConfig;
import uulm.teamname.marvelous.gamelibrary.requests.*;
import java.util.ArrayList;
@ -20,7 +23,7 @@ class GameLogicTest {
@Test
void executeRequest() {
GameState state = new GameState(new IntVector2(10, 10));
GameState state = new GameState(new PartyConfig(), new CharacterConfig(), new ScenarioConfig());
//build a nice state (add entities and stuff)
ArrayList<Event> result = GameLogic.executeRequest(state, new RequestBuilder(RequestType.MeleeAttackRequest)
//build a nice request to check

View File

@ -6,6 +6,9 @@ import uulm.teamname.marvelous.gamelibrary.entities.EntityID;
import uulm.teamname.marvelous.gamelibrary.entities.EntityType;
import uulm.teamname.marvelous.gamelibrary.entities.Rock;
import uulm.teamname.marvelous.gamelibrary.events.Event;
import uulm.teamname.marvelous.gamelibrary.json.config.CharacterConfig;
import uulm.teamname.marvelous.gamelibrary.json.config.PartyConfig;
import uulm.teamname.marvelous.gamelibrary.json.config.ScenarioConfig;
import uulm.teamname.marvelous.gamelibrary.requests.CharacterRequest;
import java.util.ArrayList;
@ -18,7 +21,7 @@ class GameStateTest {
//TODO: test all properties in GameStateTest.testSnapshot
//base state
GameState state = new GameState(new IntVector2(10, 10));
GameState state = new GameState(new PartyConfig(), new CharacterConfig(), new ScenarioConfig());
//set up game
state.entities.addEntity(new Rock(new EntityID(EntityType.Rocks, 0), new IntVector2(0, 0), 100));