refactor: unify comment styles

feat: add entity list class
This commit is contained in:
2021-04-30 20:54:34 +02:00
parent 67a7ab35f9
commit 3f7d393d5d
25 changed files with 269 additions and 263 deletions

View File

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

View File

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

View File

@ -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+"]";

View File

@ -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<Entity> 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<Entity> getEntities() {
return entities.iterator();
}
}

View File

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

View File

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

View File

@ -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<StoneType> {
/** 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<StoneType> 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<StoneType> content) {
if(content.size() > size) {
@ -31,27 +29,27 @@ public class Inventory implements Iterable<StoneType> {
}
}
/** 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<StoneType> {
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<StoneType> {
content.remove(stone);
}
/** Iterates over the inventory.
*/
/** Iterates over the inventory. */
@Override
public Iterator<StoneType> iterator() {
return content.iterator();

View File

@ -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<StoneType> 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);

View File

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

View File

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

View File

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

View File

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

View File

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