From 0f50efa121103f3d8fa9deab9760280cf3c732db Mon Sep 17 00:00:00 2001 From: punchready Date: Thu, 27 May 2021 17:18:36 +0200 Subject: [PATCH] feat: add handling for overtime victories --- .../gamelibrary/entities/EntityType.java | 4 +- .../gamelibrary/gamelogic/GameLogic.java | 42 ++++++------------- .../gamelibrary/gamelogic/GameState.java | 6 +-- .../gamelibrary/gamelogic/GameStateView.java | 3 +- 4 files changed, 21 insertions(+), 34 deletions(-) diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/EntityType.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/EntityType.java index 6ad9c95..acbc9f4 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/EntityType.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/EntityType.java @@ -11,5 +11,7 @@ public enum EntityType { /** Represents a Rock entity */ Rocks, /** Represents an InfinityStone entity */ - InfinityStones + InfinityStones, + /** Represents nothing */ + None } 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 9179b37..e8aee84 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java @@ -13,7 +13,6 @@ import uulm.teamname.marvelous.gamelibrary.requests.RequestType; import java.awt.*; import java.awt.geom.Line2D; import java.util.*; -import java.util.concurrent.atomic.AtomicInteger; /** Contains game logic handling. */ class GameLogic { @@ -549,13 +548,13 @@ class GameLogic { } if(character.inventory.getFreeSlots() == 0) { // no slots => has all infinity stones - result.addAll(handlePlayerWin(state, character)); + result.addAll(handlePlayerWin(state, character.id.type)); return result; } } if(alive.isEmpty()) { - result.addAll(handleThanosWin(state)); + result.addAll(handlePlayerWin(state, checkWinConditions(state))); return result; } @@ -745,48 +744,33 @@ class GameLogic { * @param winner The winning character * @return The list of resulting {@link Event}s */ - public static ArrayList handlePlayerWin(GameState state, Character winner) { + public static ArrayList handlePlayerWin(GameState state, EntityType winner) { ArrayList result = new ArrayList<>(); state.won = true; result.add(new EventBuilder(EventType.WinEvent) - .withPlayerWon(winner.id.id) + .withPlayerWon(winner == EntityType.P1 ? 1 : 2) .buildGameEvent()); return result; } - /** - * Handles the special victory conditions after all characters are knocked out. - * @param state The game state to work on - * @return The list of resulting {@link Event}s - */ - public static ArrayList handleThanosWin(GameState state) { - ArrayList result = new ArrayList<>(); - - state.won = true; - - //TODO: add thanos victory event - - return result; - } - /** * Checks a {@link GameState} for the current overtime win condition. * @param state The game state to check - * @return The {@link ParticipantType} that is currently winning the game according to overtime ruling + * @return The {@link EntityType} that is currently winning the game according to overtime ruling */ - public static ParticipantType checkWinConditions(GameState state) { + public static EntityType checkWinConditions(GameState state) { //TODO: GameLogic.checkWinConditions is kind of ugly - Tuple player1; - Tuple player2; + Tuple player1; + Tuple player2; int value1; int value2; for(WinCondition condition: WinCondition.values()) { - player1 = new Tuple(ParticipantType.Player1, condition); - player2 = new Tuple(ParticipantType.Player2, condition); + player1 = new Tuple(EntityType.P1, condition); + player2 = new Tuple(EntityType.P2, condition); value1 = 0; value2 = 0; @@ -798,13 +782,13 @@ class GameLogic { } if(value1 > value2) { - return ParticipantType.Player1; + return EntityType.P1; } if(value2 > value1) { - return ParticipantType.Player2; + return EntityType.P2; } } - return ParticipantType.None; + return EntityType.None; } } diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameState.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameState.java index ede2d08..9e75b2d 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameState.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameState.java @@ -39,7 +39,7 @@ class GameState { public final StoneCooldownManager stoneCooldown = new StoneCooldownManager(); /** The store of the {@link WinCondition} data for every win condition for each player */ - public final HashMap, Integer> winConditions = new HashMap<>(); + public final HashMap, Integer> winConditions = new HashMap<>(); /** * Constructs a new {@link GameState}. @@ -73,7 +73,7 @@ class GameState { clone.stoneCooldown.cloneFrom(stoneCooldown); - for(Tuple condition: winConditions.keySet()) { + for(Tuple condition: winConditions.keySet()) { clone.winConditions.put(condition, winConditions.get(condition)); } @@ -104,7 +104,7 @@ class GameState { stoneCooldown.cloneFrom(state.stoneCooldown); - for(Tuple condition: state.winConditions.keySet()) { + for(Tuple condition: state.winConditions.keySet()) { winConditions.put(condition, state.winConditions.get(condition)); } } diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameStateView.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameStateView.java index b5a0de9..95ac621 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameStateView.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameStateView.java @@ -3,6 +3,7 @@ package uulm.teamname.marvelous.gamelibrary.gamelogic; import uulm.teamname.marvelous.gamelibrary.IntVector2; import uulm.teamname.marvelous.gamelibrary.entities.Entity; import uulm.teamname.marvelous.gamelibrary.entities.EntityID; +import uulm.teamname.marvelous.gamelibrary.entities.EntityType; import uulm.teamname.marvelous.gamelibrary.entities.StoneType; import java.util.ArrayList; @@ -53,7 +54,7 @@ public class GameStateView { return state.stoneCooldown.getCooldown(stone); } - public ParticipantType getWinnerAccordingToWinConditions() { + public EntityType getWinnerAccordingToWinConditions() { return GameLogic.checkWinConditions(state); } }