diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameInstance.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameInstance.java index 52b1722..5c06777 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameInstance.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameInstance.java @@ -57,6 +57,13 @@ public class GameInstance { return manager.processRequests(requests, false); } + /** + * Initializes and starts the game. + */ + public void startGame() { + emit(manager.startGame()); + } + /** * Produces a {@link EventType#GamestateEvent} for the current {@link GameState}. * @return The resulting event diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java index 99f2caa..9f72431 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java @@ -490,7 +490,7 @@ class GameLogic { * @param state The game state to work on * @return The list of resulting {@link Event}s */ - private static ArrayList handleTurnEnd(GameState state) { + public static ArrayList handleTurnEnd(GameState state) { ArrayList result = new ArrayList<>(); ArrayList order = state.turnOrder; @@ -521,8 +521,8 @@ class GameLogic { }else { - int activeIndex = alive.indexOf(state.activeCharacter); - if(activeIndex == alive.size() - 1) { + int activeIndex = state.activeCharacter != null ? alive.indexOf(state.activeCharacter) : -1; + if(activeIndex == -1 || activeIndex == alive.size() - 1) { state.activeCharacter = alive.get(0); //reached end of turn order, new round state.roundNumber++; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameStateManager.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameStateManager.java index 8b6f33b..cc6117c 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameStateManager.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameStateManager.java @@ -53,6 +53,14 @@ class GameStateManager { return (Event[])GameLogic.checkTurnEnd(state).toArray(); } + /** + * Starts the game. + * @return The resulting {@link Event}s + */ + public Event[] startGame() { + return (Event[])GameLogic.handleTurnEnd(state).toArray(); + } + /** * Applies an array of {@link Event}s to the game state. * @param events The events to apply