diff --git a/.gitignore b/.gitignore index 99eb4a8..4e00fab 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,8 @@ gradle-app.setting # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 +.idea + # User-specific stuff .idea/**/workspace.xml .idea/**/tasks.xml diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/Tuple.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/Tuple.java index b679e90..809d70d 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/Tuple.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/Tuple.java @@ -6,8 +6,7 @@ public class Tuple { public final X item1; public final Y item2; - /** Constructs a new {@link Tuple} based on the given objects. - */ + /** Constructs a new {@link Tuple} based on the given objects. */ public Tuple(X item1, Y item2) { this.item1 = item1; this.item2 = item2; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Character.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Character.java index 7d71c8b..a5b18e5 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Character.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Character.java @@ -2,51 +2,43 @@ package uulm.teamname.marvelous.gamelibrary.entities; import uulm.teamname.marvelous.gamelibrary.IntVector2; -/** Represents a playable character inside a match. - */ +/** Represents a playable character inside a match. */ public class Character extends Entity { - /** The name of the character. - */ + /** The name of the character */ public final String name; - /** The hp stat of the character. - */ + /** The hp stat of the character */ public final Stat hp; - /** The mp stat of the character. - */ + /** The mp stat of the character */ public final Stat mp; - /** The ap stat of the character. - */ + /** The ap stat of the character */ public final Stat ap; - /** The ranged attack range of the character. - */ + /** The ranged attack range of the character */ public final int attackRange; - /** The ranged attack damage of the character. - */ + /** The ranged attack damage of the character */ public final int rangedDamage; - /** The melee attack damage of the character. - */ + /** The melee attack damage of the character */ public final int meleeDamage; - /** The {@link Inventory} of the character. - */ + /** The {@link Inventory} of the character */ public final Inventory inventory = new Inventory(); - /** Constructs a new {@link Character} with an empty inventory. - * @param id The {@link EntityID} of the character. - * @param position The position of the character. - * @param name The name of the character. - * @param hp The maximum hp of the character. - * @param mp The maximum mp of the character. - * @param ap The maximum ap of the character. - * @param attackRange The ranged attack range of the character. - * @param rangedDamage The ranged damage of the character. - * @param meleeDamage The melee damage of the character. + /** + * Constructs a new {@link Character} with an empty inventory. + * @param id The {@link EntityID} of the character + * @param position The position of the character + * @param name The name of the character + * @param hp The maximum hp of the character + * @param mp The maximum mp of the character + * @param ap The maximum ap of the character + * @param attackRange The ranged attack range of the character + * @param rangedDamage The ranged damage of the character + * @param meleeDamage The melee damage of the character */ public Character(EntityID id, IntVector2 position, String name, int hp, int mp, int ap, int attackRange, int rangedDamage, int meleeDamage) { super(id, position); @@ -59,8 +51,9 @@ public class Character extends Entity { this.meleeDamage = meleeDamage; } - /** Checks if the character is still alive. - * @return Whether or not the characters hp is greater than 0. + /** + * Checks if the character is still alive. + * @return Whether or not the characters hp is greater than 0 */ public boolean isAlive() { return hp.getValue() > 0; 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 68e7f5f..eeee9dd 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Entity.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Entity.java @@ -2,24 +2,21 @@ package uulm.teamname.marvelous.gamelibrary.entities; import uulm.teamname.marvelous.gamelibrary.IntVector2; -/** Represents an abstract entity. - */ +/** Represents an abstract entity. */ public abstract class Entity { - /** Whether or not the entity is currently active in the game. - */ + /** Whether or not the entity is currently active in the game */ private boolean active = true; - /** The position of the entity. - */ + /** The position of the entity */ private IntVector2 position; - /** The {@link EntityID} of the entity. - */ + /** The {@link EntityID} of the entity */ public final EntityID id; - /** Constructs a new {@link Entity}. - * @param id The {@link EntityID} of the entity. - * @param position The position of the entity. + /** + * Constructs a new {@link Entity}. + * @param id The {@link EntityID} of the entity + * @param position The position of the entity */ protected Entity(EntityID id, IntVector2 position) { this.position = position; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/EntityID.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/EntityID.java index b7ba74c..8916b31 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/EntityID.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/EntityID.java @@ -1,35 +1,35 @@ package uulm.teamname.marvelous.gamelibrary.entities; -/** Represents a distinct identification for every {@link Entity} in a game. - */ +/** Represents a distinct identification for every {@link Entity} in a game. */ public class EntityID { - /** The index of the entity. - */ + /** The index of the entity */ public final int id; - /** The type of the entity. - */ + /** The type of the entity */ public final EntityType type; - /** Constructs a new {@link Entity}-{@link EntityID} based on the given index and {@link EntityType}. - * @param id The index of the entity. - * @param type The type of the entity. + /** + * Constructs a new {@link Entity}-{@link EntityID} based on the given index and {@link EntityType}. + * @param id The index of the entity + * @param type The type of the entity */ public EntityID(int id, EntityType type) { this.id = id; this.type = type; } - /** Checks if the id has the same {@link EntityType} as the given one. - * @param other The type to compare to. - * @return Whether or not the id has the same type. + /** + * Checks if the id has the same {@link EntityType} as the given one. + * @param other The type to compare to + * @return Whether or not the id has the same type */ public boolean isSameType(EntityType other) { return type == other; } - /** Serializes the id for debugging. - * @return A debug string containing all the necessary information about the id. + /** + * Serializes the id for debugging. + * @return A debug string containing all the necessary information about the id */ public String toString() { return "["+type.toString()+":"+id+"]"; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/EntityList.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/EntityList.java new file mode 100644 index 0000000..e98ad01 --- /dev/null +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/EntityList.java @@ -0,0 +1,50 @@ +package uulm.teamname.marvelous.gamelibrary.entities; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; + +/** Represents a list of {@link Entity}s. */ +public class EntityList { + /** The internal collection of {@link Entity}s */ + private final HashSet entities = new HashSet<>(); + + /** + * Clears the list of entities. + */ + public void clear() { + entities.clear(); + } + + /** + * Adds an entity to the list. + * @param entity The {@link Entity} to add + */ + public void addEntity(Entity entity) { + entities.add(entity); + } + + /** + * Adds multiple entities to the list. + * @param entities The entities to add + */ + public void addEntities(Entity... entities) { + this.entities.addAll(Arrays.asList(entities)); + } + + /** + * Removes an entity from the list. + * @param entity The {@link Entity} to remove + */ + public boolean removeEntity(Entity entity) { + return entities.remove(entity); + } + + /** + * Iterates over all entities inside the list. + * @return An iterator over every {@link Entity} + */ + public Iterator getEntities() { + return entities.iterator(); + } +} 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 b8d0612..6ad9c95 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/EntityType.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/EntityType.java @@ -1,21 +1,15 @@ package uulm.teamname.marvelous.gamelibrary.entities; -/** Specifies the type of an {@link Entity}. - */ +/** Specifies the type of an {@link Entity}. */ public enum EntityType { - /** Represents an NPC entity. - */ + /** Represents an NPC entity */ NPC, - /** Represents the first Player. - */ + /** Represents the first Player */ P1, - /** Represents the second Player. - */ + /** Represents the second Player */ P2, - /** Represents a Rock entity. - */ + /** Represents a Rock entity */ Rocks, - /** Represents an InfinityStone entity. - */ + /** Represents an InfinityStone entity */ InfinityStones } diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/InfinityStone.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/InfinityStone.java index 0bfe215..45e5997 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/InfinityStone.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/InfinityStone.java @@ -2,17 +2,16 @@ package uulm.teamname.marvelous.gamelibrary.entities; import uulm.teamname.marvelous.gamelibrary.IntVector2; -/** Represents an infinity stone {@link Entity}. Can only exist on the map. - */ +/** Represents an infinity stone {@link Entity}. Can only exist on the map. */ public class InfinityStone extends Entity { - /** The {@link StoneType} of the infinity stone. - */ + /** The {@link StoneType} of the infinity stone */ public final StoneType type; - /** Constructs a new {@link InfinityStone}. - * @param id The {@link EntityID} of the stone. - * @param position The position of the stone. - * @param type The {@link StoneType} of the stone. + /** + * Constructs a new {@link InfinityStone}. + * @param id The {@link EntityID} of the stone + * @param position The position of the stone + * @param type The {@link StoneType} of the stone */ public InfinityStone(EntityID id, IntVector2 position, StoneType type) { super(id, position); diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Inventory.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Inventory.java index a5f132c..abf84ba 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Inventory.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Inventory.java @@ -4,19 +4,17 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; -/** Represents an inventory of 6 slots of {@link StoneType}s that can be manipulated. - */ +/** Represents an inventory of 6 slots of {@link StoneType}s that can be manipulated. */ public class Inventory implements Iterable { - /** The size of the inventory. - */ + /** The size of the inventory */ private final int size = 6; - /** The content of the inventory. - */ + /** The content of the inventory */ private final HashSet content = new HashSet<>(size); - /** Constructs a new {@link Inventory}. - * @param content The starting content of the inventory. + /** + * Constructs a new {@link Inventory}. + * @param content The starting content of the inventory */ public Inventory(ArrayList content) { if(content.size() > size) { @@ -31,27 +29,27 @@ public class Inventory implements Iterable { } } - /** Constructs a new empty {@link Inventory}. - */ + /** Constructs a new empty {@link Inventory}. */ public Inventory() { } - /** Returns the number of free slots the inventory has. - */ + /** Returns the number of free slots the inventory has. */ public int getFreeSlots() { return size - content.size(); } - /** Checks if the inventory contains the given stone. - * @param stone The {@link StoneType} to check for. + /** + * Checks if the inventory contains the given stone. + * @param stone The {@link StoneType} to check for */ public boolean hasStone(StoneType stone) { return content.contains(stone); } - /** Adds a stone to the inventory. - * @param stone The {@link StoneType} to add. + /** + * Adds a stone to the inventory. + * @param stone The {@link StoneType} to add */ public void addStone(StoneType stone) { if(content.contains(stone)) { @@ -64,8 +62,9 @@ public class Inventory implements Iterable { content.add(stone); } - /** Removes a stone from the inventory. - * @param stone The {@link StoneType} to remove. + /** + * Removes a stone from the inventory. + * @param stone The {@link StoneType} to remove */ public void removeStone(StoneType stone) { if(!content.contains(stone)) { @@ -75,8 +74,7 @@ public class Inventory implements Iterable { content.remove(stone); } - /** Iterates over the inventory. - */ + /** Iterates over the inventory. */ @Override public Iterator iterator() { return content.iterator(); diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/NPC.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/NPC.java index 1b1e854..3ede8b1 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/NPC.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/NPC.java @@ -4,26 +4,26 @@ import uulm.teamname.marvelous.gamelibrary.IntVector2; import java.util.ArrayList; -/** Represents an NPC inside the game. - */ +/** Represents an NPC inside the game. */ public class NPC extends Entity { - /** The {@link Inventory} of the NPC. - */ + /** The {@link Inventory} of the NPC */ public final Inventory inventory; - /** Constructs a new {@link NPC}. - * @param id The {@link EntityID} of the NPC. - * @param position The position of the NPC. - * @param inventory The starting inventory the NPC should have. + /** + * Constructs a new {@link NPC}. + * @param id The {@link EntityID} of the NPC + * @param position The position of the NPC + * @param inventory The starting inventory the NPC should have */ public NPC(EntityID id, IntVector2 position, ArrayList inventory) { super(id, position); this.inventory = new Inventory(inventory); } - /** Constructs a new {@link NPC} with an empty inventory. - * @param id The {@link EntityID} of the NPC. - * @param position The position of the NPC. + /** + * Constructs a new {@link NPC} with an empty inventory. + * @param id The {@link EntityID} of the NPC + * @param position The position of the NPC */ public NPC(EntityID id, IntVector2 position) { super(id, position); diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/NPCType.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/NPCType.java index a9ec4fc..b4b339e 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/NPCType.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/NPCType.java @@ -1,15 +1,8 @@ package uulm.teamname.marvelous.gamelibrary.entities; -/** Specifies the type of an {@link NPC}. - */ +/** Specifies the type of an {@link NPC}. */ public enum NPCType { - /** Represents the Goose. - */ Goose, - /** Represents Stan Lee. - */ Stan, - /** Represents Thanos. - */ Thanos } diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Rock.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Rock.java index e95cd8e..bf1fde7 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Rock.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Rock.java @@ -2,21 +2,19 @@ package uulm.teamname.marvelous.gamelibrary.entities; import uulm.teamname.marvelous.gamelibrary.IntVector2; -/** Represents a rock entity on the map. - */ +/** Represents a rock entity on the map. */ public class Rock extends Entity { - /** The maximum hp of the rock. - */ + /** The maximum hp of the rock */ public final int maxHP; - /** The current hp of the rock. - */ + /** The current hp of the rock */ private int hp; - /** Constructs a new {@link Rock}. - * @param id The {@link EntityID} of the rock. - * @param position The position of the rock. - * @param hp The hp of the rock. + /** + * Constructs a new {@link Rock}. + * @param id The {@link EntityID} of the rock + * @param position The position of the rock + * @param hp The hp of the rock */ public Rock(EntityID id, IntVector2 position, int hp) { super(id, position); diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Stat.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Stat.java index 197566d..7d64c55 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Stat.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Stat.java @@ -1,23 +1,20 @@ package uulm.teamname.marvelous.gamelibrary.entities; -/** Represents a stat property of a {@link Character}. - */ +/** Represents a stat property of a {@link Character}. */ public class Stat { - /** The {@link StatType} of the stat. - */ + /** The {@link StatType} of the stat */ public final StatType type; - /** The maximum value of the stat. - */ + /** The maximum value of the stat */ public final int max; - /** The current value of the stat. - */ + /** The current value of the stat */ private int value; - /** Constructs a new {@link Stat} with the initial value set to the maximum value. - * @param type The {@link StatType} of the stat. - * @param max The maximum value of the stat. + /** + * Constructs a new {@link Stat} with the initial value set to the maximum value. + * @param type The {@link StatType} of the stat + * @param max The maximum value of the stat */ public Stat(StatType type, int max) { this.type = type; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/StatType.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/StatType.java index 7186699..9c48943 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/StatType.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/StatType.java @@ -1,15 +1,11 @@ package uulm.teamname.marvelous.gamelibrary.entities; -/** Specifies the type of a {@link Stat}. - */ +/** Specifies the type of a {@link Stat}. */ public enum StatType { - /** Represents the life points of a character. - */ + /** Represents the life points of a character */ HP, - /** Represents the mana points of a character. - */ + /** Represents the mana points of a character */ MP, - /** Represents thr action points of a character. - */ + /** Represents thr action points of a character */ AP } diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/StoneType.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/StoneType.java index f4e4c9c..c2cecca 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/StoneType.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/StoneType.java @@ -1,7 +1,6 @@ package uulm.teamname.marvelous.gamelibrary.entities; -/** Specifies the type of an {@link InfinityStone}. - */ +/** Specifies the type of an {@link InfinityStone}. */ public enum StoneType { SpaceStone, MindStone, diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/ChecksumCalculator.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/ChecksumCalculator.java index 9c441dd..d170369 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/ChecksumCalculator.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/ChecksumCalculator.java @@ -1,20 +1,21 @@ package uulm.teamname.marvelous.gamelibrary.gamelogic; -/** Contains checksum calculations. - */ +/** Contains checksum calculations. */ class ChecksumCalculator { - /** Compares a checksum to the checksum of a {@link GameState}. - * @param state The state to check. - * @param input the checksum to compare to. - * @return Whether or not the checksum matches the state's checksum. + /** + * Compares a checksum to the checksum of a {@link GameState}. + * @param state The state to check + * @param input the checksum to compare to + * @return Whether or not the checksum matches the state's checksum */ public static boolean checkChecksum(GameState state, long input) { return calculateChecksum(state) == input; } - /** Calculates the corresponding checksum to a {@link GameState}. - * @param state The state to check. - * @return The checksum. + /** + * Calculates the corresponding checksum to a {@link GameState}. + * @param state The state to check + * @return The checksum */ public static long calculateChecksum(GameState state) { //TODO: implement ChecksumCalculator.calculateChecksum diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/EventEmitter.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/EventEmitter.java index 98b31f5..fdf8872 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/EventEmitter.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/EventEmitter.java @@ -2,8 +2,7 @@ package uulm.teamname.marvelous.gamelibrary.gamelogic; import java.util.Observable; -/** Represents an event emitter for game events fired by a game instance. - */ +/** Represents an event emitter for game events fired by a game instance. */ class EventEmitter extends Observable { } 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 700ae9e..a27845f 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameInstance.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameInstance.java @@ -6,51 +6,48 @@ import uulm.teamname.marvelous.gamelibrary.requests.Request; import java.util.Observer; -/** Represents a game instance. - */ +/** Represents a game instance. */ public class GameInstance { - /** The private {@link GameState} of the instance. - */ + /** The private {@link GameState} of the instance */ private final GameState _state; - /** The public view for the underlying {@link GameState} of the instance. - */ + /** The public view for the underlying {@link GameState} of the instance */ public final GameStateView state; - /** The {@link GameStateManager} managing the {@link GameState} of the instance. - */ + /** The {@link GameStateManager} managing the {@link GameState} of the instance */ private final GameStateManager manager; - /** The {@link EventEmitter} for {@link Event}s resulting from {@link Request}s. - */ + /** The {@link EventEmitter} for {@link Event}s resulting from {@link Request}s */ private final EventEmitter emitter = new EventEmitter(); - /** Constructs a new {@link GameInstance}. - */ + /** Constructs a new {@link GameInstance}. */ public GameInstance(IntVector2 mapSize) { _state = new GameState(mapSize); this.state = new GameStateView(_state); manager = new GameStateManager(_state); } - /** Checks a checksum with the current one. - * @param input The checksum to compare to. - * @return Whether or not the checksum matches. + /** + * Checks a checksum with the current one. + * @param input The checksum to compare to + * @return Whether or not the checksum matches */ public boolean checkChecksum(long input) { return ChecksumCalculator.checkChecksum(_state, input); } - /** Calculates the current checksum of the game state. - * @return The calculated checksum. + /** + * Calculates the current checksum of the game state. + * @return The calculated checksum */ public long calculateChecksum() { return ChecksumCalculator.calculateChecksum(_state); } - /** Checks an array of {@link Request}s for validity and automatically applies them if valid. - * @param requests The requests to check. - * @return Whether or not the given set of requests was valid. + /** + * Checks an array of {@link Request}s for validity and automatically applies them if valid. + * @param requests The requests to check + * @return Whether or not the given set of requests was valid */ public boolean checkRequestsAndApply(Request... requests) { if(manager.processRequests(requests, true)) { @@ -60,30 +57,34 @@ public class GameInstance { return false; } - /** Checks an array of {@link Request}s for validity without applying it. - * @param requests The requests to check. - * @return Whether or not the given set of requests is valid. + /** + * Checks an array of {@link Request}s for validity without applying it. + * @param requests The requests to check + * @return Whether or not the given set of requests is valid */ public boolean checkRequestsSilent(Request... requests) { return manager.processRequests(requests, false); } - /** Applies an array of {@link Event}s to the game state. + /** + * Applies an array of {@link Event}s to the game state. * @param events The events to apply. */ public void applyEvents(Event... events) { manager.applyEvents(events); } - /** Adds an {@link Observer} for events. - * @param observer The observer to add. + /** + * Adds an {@link Observer} for events. + * @param observer The observer to add */ public void addObserver(Observer observer) { emitter.addObserver(observer); } - /** Emits an array of {@link Event}s. - * @param events The events to emit. + /** + * Emits an array of {@link Event}s. + * @param events The events to emit */ private void emit(Event... events) { emitter.notifyObservers(events); 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 9528860..aba06bb 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java @@ -7,11 +7,11 @@ import uulm.teamname.marvelous.gamelibrary.requests.Request; import java.util.ArrayList; import java.util.HashMap; -/** Contains game logic handling. - */ +/** Contains game logic handling. */ class GameLogic { - /** Produces resulting {@link Event}s from a given {@link Request} independently of any {@link GameState}. - * @return The list of resulting events. + /** + * Produces resulting {@link Event}s from a given {@link Request} independently of any {@link GameState}. + * @return The list of resulting events */ public static ArrayList executeRequest(Request request) { ArrayList result = new ArrayList(); @@ -30,9 +30,10 @@ class GameLogic { return result; } - /** Checks a {@link Request} for validity for a {@link GameState}. - * @param state The game state to check on. - * @param request The request to validate. + /** + * Checks a {@link Request} for validity for a {@link GameState}. + * @param state The game state to check on + * @param request The request to validate * @return Whether or not the request is valid */ public static boolean checkRequest(GameState state, Request request) { @@ -40,17 +41,19 @@ class GameLogic { return false; } - /** Applies an {@link Event} to a {@link GameState}. - * @param state The game state to apply to. - * @param event The event to apply. + /** + * Applies an {@link Event} to a {@link GameState}. + * @param state The game state to apply to + * @param event The event to apply */ public static void applyEvent(GameState state, Event event) { //TODO: implement GameLogic.applyEvent } - /** 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. + /** + * 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 */ public static ParticipantType checkWinConditions(GameState state) { //TODO: GameLogic.checkWinConditions is kind of ugly 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 c70ea64..c1c02fc 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameState.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameState.java @@ -3,60 +3,53 @@ 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.EntityList; import uulm.teamname.marvelous.gamelibrary.entities.StoneType; import uulm.teamname.marvelous.gamelibrary.Tuple; import java.util.ArrayList; import java.util.HashMap; -/** Represents the state of a game instance. - */ +/** Represents the state of a game instance. */ class GameState { - /** The size of the map. - */ + /** The size of the map */ public final IntVector2 mapSize; - /** The list of {@link Entity}'s inside the game. - */ - public ArrayList entities; + /** The list of {@link Entity}s inside the game */ + public final EntityList entities = new EntityList(); - /** The total amount of full turn cycles that occurred. - */ + /** The total amount of full turn cycles that occurred */ public int roundNumber = 0; - /** The turn order of every character. - */ + /** The turn order of every character */ public ArrayList turnOrder; - /** The total amount of turns that occurred. - */ + /** The total amount of turns that occurred */ public int turnNumber = 0; - /** The {@link EntityID} of the active character. - */ + /** The {@link EntityID} of the active character */ public EntityID activeCharacter; - /** Whether or not the game was won. - */ + /** Whether or not the game was won */ public boolean won = false; - /** The global cooldown of every infinity stone. - */ - public HashMap stoneCooldown; + /** The global cooldown of every infinity stone */ + public final HashMap stoneCooldown = new HashMap<>(); - /** The store of the {@link WinCondition} data for every win condition for each player. - */ - public HashMap, Integer> winConditions; + /** The store of the {@link WinCondition} data for every win condition for each player */ + public final HashMap, Integer> winConditions = new HashMap<>(); - /** Constructs a new {@link GameState}. - * @param mapSize The size of the map. + /** + * Constructs a new {@link GameState}. + * @param mapSize The size of the map */ public GameState(IntVector2 mapSize) { this.mapSize = mapSize; } - /** Clones the state into a new {@link GameState} object. - * @return The cloned game state. + /** + * Clones the state into a new {@link GameState} object. + * @return The cloned game state */ public GameState snapshot() { //TODO: implement GameState.snapshot 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 19ce7aa..ec6984b 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameStateManager.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameStateManager.java @@ -6,27 +6,26 @@ import uulm.teamname.marvelous.gamelibrary.requests.Request; import java.util.ArrayDeque; import java.util.ArrayList; -/** Represents manager for a game state. - */ +/** Represents manager for a game state. */ class GameStateManager { - /** The managed {@link GameState}. - */ + /** The managed {@link GameState} */ private final GameState state; - /** The queue of {@link Event}s to be applied during {@link Request} processing. - */ + /** The queue of {@link Event}s to be applied during {@link Request} processing */ private final ArrayDeque queue = new ArrayDeque(); - /** Constructs a new {@link GameStateManager}. - * @param state A reference to the state to be managed. + /** + * Constructs a new {@link GameStateManager}. + * @param state A reference to the state to be managed */ public GameStateManager(GameState state) { this.state = state; } - /** Checks a list of {@link Request}s for validity and optionally produces resulting {@link Event}s. - * @param requests The requests to check. - * @param apply True if resulting events should be stored for later application. + /** + * Checks a list of {@link Request}s for validity and optionally produces resulting {@link Event}s. + * @param requests The requests to check + * @param apply True if resulting events should be stored for later application */ public boolean processRequests(Request[] requests, boolean apply) { GameState snapshot = state.snapshot(); @@ -46,8 +45,9 @@ class GameStateManager { return true; } - /** Applies an array of {@link Event}s to the game state. - * @param events The events to apply. + /** + * Applies an array of {@link Event}s to the game state. + * @param events The events to apply */ public void applyEvents(Event[] events) { for(Event event: events) { @@ -55,8 +55,9 @@ class GameStateManager { } } - /** Applies the result of the last processRequests call. - * @return A list of applied events. + /** + * Applies the result of the last processRequests call. + * @return A list of applied events */ public Event[] apply() { Event[] toReturn = new Event[queue.size()]; 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 e805f3d..1b34930 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameStateView.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameStateView.java @@ -3,16 +3,16 @@ package uulm.teamname.marvelous.gamelibrary.gamelogic; import uulm.teamname.marvelous.gamelibrary.entities.Entity; import java.util.ArrayList; +import java.util.Iterator; -/** Represents a game state view containing getters for all the properties of a {@link GameState}. - */ +/** Represents a game state view containing getters for all the properties of a {@link GameState}. */ public class GameStateView { - /** The managed {@link GameState}. - */ + /** The managed {@link GameState} */ private final GameState state; - /** Constructs a new {@link GameStateView}. - * @param state A reference to the state to be viewable. + /** + * Constructs a new {@link GameStateView}. + * @param state A reference to the state to be viewable */ public GameStateView(GameState state) { this.state = state; @@ -20,7 +20,7 @@ public class GameStateView { //TODO: add immutable getters for all state properties - public ArrayList getEntities() { - return new ArrayList<>(state.entities); + public Iterator getEntities() { + return state.entities.getEntities(); } } diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/ParticipantType.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/ParticipantType.java index f192fdd..8af79fb 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/ParticipantType.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/ParticipantType.java @@ -1,7 +1,6 @@ package uulm.teamname.marvelous.gamelibrary.gamelogic; -/** Specifies a participant type. - */ +/** Specifies a participant type. */ public enum ParticipantType { None, Player1, diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/WinCondition.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/WinCondition.java index 86f3a48..5dd4e16 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/WinCondition.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/WinCondition.java @@ -1,15 +1,11 @@ package uulm.teamname.marvelous.gamelibrary.gamelogic; -/** Specifies a win condition. The order is important here. - */ +/** Specifies a win condition. The order is important here. */ enum WinCondition { - /** The maximum amount of total infinity stones the player had at a time. - */ + /** The maximum amount of total infinity stones the player had at a time */ MaxStones, - /** The total amount of enemy characters the player knocked out. - */ + /** The total amount of enemy characters the player knocked out */ TotalKnockouts, - /** The total amount of damage the player did to enemy characters. - */ + /** The total amount of damage the player did to enemy characters */ TotalDamage } diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/JSON.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/JSON.java index 9e165d3..eb67bd1 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/JSON.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/JSON.java @@ -8,8 +8,7 @@ import uulm.teamname.marvelous.gamelibrary.json.ingame.MessageStructure; public class JSON { /** Deserializes an incoming network message into a {@link MessageStructure}. * @param input The JSON to deserialize. - * @return The parsed message. - */ + * @return The parsed message. */ public static MessageStructure[] parse(String input) throws ExecutionControl.NotImplementedException { //TODO: implement JSON.parse throw new ExecutionControl.NotImplementedException("JSON.parse is not implemented"); @@ -17,8 +16,7 @@ public class JSON { /** Serializes a {@link MessageStructure} into a JSON string. * @param input The message to serialize. - * @return The message as JSON. - */ + * @return The message as JSON. */ public static String stringify(MessageStructure input) throws ExecutionControl.NotImplementedException { //TODO: implement JSON.stringify throw new ExecutionControl.NotImplementedException("JSON.stringify is not implemented");