feat: implement method to start a game

This commit is contained in:
punchready 2021-05-19 20:04:10 +02:00
parent f3b5fc277e
commit 596ace355a
3 changed files with 18 additions and 3 deletions

View File

@ -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

View File

@ -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<Event> handleTurnEnd(GameState state) {
public static ArrayList<Event> handleTurnEnd(GameState state) {
ArrayList<Event> result = new ArrayList<>();
ArrayList<EntityID> 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++;

View File

@ -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