From e88476eb1094370b5665520d5ff9afa8dca59cc9 Mon Sep 17 00:00:00 2001 From: punchready Date: Tue, 1 Jun 2021 19:26:29 +0200 Subject: [PATCH] cleanup: optimize imports, remove unused code, fix warnings --- .../marvelous/gamelibrary/entities/Entity.java | 15 ++------------- .../marvelous/gamelibrary/events/Event.java | 2 +- .../gamelibrary/events/NotificationEvent.java | 2 +- .../gamelibrary/gamelogic/GameInstance.java | 6 ++++++ .../gamelibrary/gamelogic/GameLogic.java | 2 +- .../gamelibrary/gamelogic/GameState.java | 4 +++- .../gamelogic/GameStateManager.java | 2 +- .../gamelibrary/gamelogic/ParticipantType.java | 9 --------- .../gamelibrary/gamelogic/GameLogicTest.java | 18 ++++++++++++++++++ 9 files changed, 33 insertions(+), 27 deletions(-) delete mode 100644 src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/ParticipantType.java diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Entity.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Entity.java index 9f77fe5..0854b5b 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Entity.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Entity.java @@ -12,9 +12,6 @@ import java.util.Objects; @JsonDeserialize(using = EntityDeserializer.class) @JsonSerialize(using = EntitySerializer.class) public abstract class Entity { - /** Whether or not the entity is currently active in the game */ - protected boolean active = true; - /** Whether or not the entity blocks movement */ protected boolean solid = false; @@ -43,10 +40,6 @@ public abstract class Entity { */ public abstract Entity clone(); - public boolean isActive() { - return active; - } - public boolean blocksMovement() { return solid; } @@ -55,10 +48,6 @@ public abstract class Entity { return opaque; } - public void setActive(boolean active) { - this.active = active; - } - public IntVector2 getPosition() { return position; } @@ -72,12 +61,12 @@ public abstract class Entity { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Entity entity = (Entity) o; - return active == entity.active && Objects.equals(position, entity.position) && Objects.equals(id, entity.id); + return Objects.equals(position, entity.position) && Objects.equals(id, entity.id); } @Override public int hashCode() { - return Objects.hash(active, position, id); + return Objects.hash(position, id); } } diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/events/Event.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/events/Event.java index 97e151e..cd24dbc 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/events/Event.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/events/Event.java @@ -1,8 +1,8 @@ package uulm.teamname.marvelous.gamelibrary.events; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize.EventDeserializer; import uulm.teamname.marvelous.gamelibrary.json.basic.EventMessage; +import uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize.EventDeserializer; import java.util.Objects; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/events/NotificationEvent.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/events/NotificationEvent.java index 22579c5..15da838 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/events/NotificationEvent.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/events/NotificationEvent.java @@ -1,6 +1,6 @@ package uulm.teamname.marvelous.gamelibrary.events; -/** Represents a notification event for: {@link EventType#Ack}, {@link EventType#Nack}, {@link EventType#Req}. */ +/** Represents a notification event for: {@link EventType#Ack}, {@link EventType#Nack}. */ public class NotificationEvent extends Event { } 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 72925da..d5f3bd5 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameInstance.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameInstance.java @@ -45,6 +45,8 @@ public class GameInstance { result.addAll(result2); + result.add(GameLogic.buildGameStateEvent(_state)); + return Optional.of(result); } @@ -102,6 +104,10 @@ public class GameInstance { manager.applyEvents(events); } + protected GameState getState() { + return _state; + } + @Override public String toString() { StringBuilder sb = new StringBuilder(); 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 feaa832..6f7690f 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java @@ -429,7 +429,7 @@ class GameLogic { * Verifies that a {@link Character} is alive. */ private static void requireAlive(Character entity) throws InvalidRequestException { - if(!entity.isAlive() || !entity.isActive()) { + if(!entity.isAlive()) { throw new InvalidRequestException(); } } 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 8de64ba..e561bcd 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameState.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameState.java @@ -1,7 +1,9 @@ package uulm.teamname.marvelous.gamelibrary.gamelogic; import uulm.teamname.marvelous.gamelibrary.IntVector2; -import uulm.teamname.marvelous.gamelibrary.entities.*; +import uulm.teamname.marvelous.gamelibrary.entities.Entity; +import uulm.teamname.marvelous.gamelibrary.entities.EntityID; +import uulm.teamname.marvelous.gamelibrary.entities.StoneType; import uulm.teamname.marvelous.gamelibrary.json.config.CharacterConfig; import uulm.teamname.marvelous.gamelibrary.json.config.PartyConfig; import uulm.teamname.marvelous.gamelibrary.json.config.ScenarioConfig; 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 123000e..66d174e 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameStateManager.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameStateManager.java @@ -12,7 +12,7 @@ class GameStateManager { private final GameState state; /** The queue of {@link Event}s to be applied during {@link Request} processing */ - private final ArrayDeque queue = new ArrayDeque(); + private final ArrayDeque queue = new ArrayDeque<>(); /** * Constructs a new {@link GameStateManager}. diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/ParticipantType.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/ParticipantType.java deleted file mode 100644 index 8af79fb..0000000 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/ParticipantType.java +++ /dev/null @@ -1,9 +0,0 @@ -package uulm.teamname.marvelous.gamelibrary.gamelogic; - -/** Specifies a participant type. */ -public enum ParticipantType { - None, - Player1, - Player2, - Spectator -} diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogicTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogicTest.java index 6014df7..22f26d5 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogicTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogicTest.java @@ -172,6 +172,24 @@ class GameLogicTest { assertEquals(EventType.GamestateEvent, actual.type, "First event should be a GameStateEvent"); System.out.println(game.toString()); + + game.applyEvents(GameLogic.spawnThanos(game.getState())); + + System.out.println(game.toString()); + + NPC thanos = (NPC)game.state.getEntities().findEntity(new EntityID(EntityType.NPC, 2)); + + game.applyEvents(GameLogic.handleThanos(game.getState(), thanos)); + + System.out.println(game.toString()); + + game.applyEvents(GameLogic.handleThanos(game.getState(), thanos)); + + System.out.println(game.toString()); + + game.applyEvents(GameLogic.handleThanos(game.getState(), thanos)); + + System.out.println(game.toString()); }