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

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

View File

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

View File

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

View File

@ -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<Event> executeRequest(Request request) {
ArrayList<Event> result = new ArrayList<Event>();
@ -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

View File

@ -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<Entity> 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<EntityID> 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<StoneType, Float> stoneCooldown;
/** The global cooldown of every infinity stone */
public final HashMap<StoneType, Float> stoneCooldown = new HashMap<>();
/** The store of the {@link WinCondition} data for every win condition for each player.
*/
public HashMap<Tuple<ParticipantType, WinCondition>, Integer> winConditions;
/** The store of the {@link WinCondition} data for every win condition for each player */
public final HashMap<Tuple<ParticipantType, WinCondition>, 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

View File

@ -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<Event> queue = new ArrayDeque<Event>();
/** 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()];

View File

@ -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<Entity> getEntities() {
return new ArrayList<>(state.entities);
public Iterator<Entity> getEntities() {
return state.entities.getEntities();
}
}

View File

@ -1,7 +1,6 @@
package uulm.teamname.marvelous.gamelibrary.gamelogic;
/** Specifies a participant type.
*/
/** Specifies a participant type. */
public enum ParticipantType {
None,
Player1,

View File

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