2021-04-29 17:15:29 +00:00
|
|
|
package uulm.teamname.marvelous.gamelibrary.gamelogic;
|
|
|
|
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.Tuple;
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** Contains game logic handling. */
|
2021-04-29 17:15:29 +00:00
|
|
|
class GameLogic {
|
2021-04-30 18:54:34 +00:00
|
|
|
/**
|
|
|
|
* Produces resulting {@link Event}s from a given {@link Request} independently of any {@link GameState}.
|
|
|
|
* @return The list of resulting events
|
2021-04-29 17:15:29 +00:00
|
|
|
*/
|
|
|
|
public static ArrayList<Event> executeRequest(Request request) {
|
|
|
|
ArrayList<Event> result = new ArrayList<Event>();
|
|
|
|
|
|
|
|
//TODO: implement GameLogic.executeRequest
|
|
|
|
|
|
|
|
/* Example Code:
|
|
|
|
switch (event.type) {
|
|
|
|
case EventType.MeleeAttack:
|
|
|
|
result.add(Event.Construct(EventType.APReduced, event.sourceEntity, event.ap));
|
|
|
|
result.add(Event.Construct(EventType.DamageTaken, event.targetEntity, event.value));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/**
|
|
|
|
* Checks a {@link Request} for validity for a {@link GameState}.
|
|
|
|
* @param state The game state to check on
|
|
|
|
* @param request The request to validate
|
2021-04-29 17:15:29 +00:00
|
|
|
* @return Whether or not the request is valid
|
|
|
|
*/
|
|
|
|
public static boolean checkRequest(GameState state, Request request) {
|
|
|
|
//TODO: implement GameLogic.checkRequest
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/**
|
|
|
|
* Applies an {@link Event} to a {@link GameState}.
|
|
|
|
* @param state The game state to apply to
|
|
|
|
* @param event The event to apply
|
2021-04-29 17:15:29 +00:00
|
|
|
*/
|
|
|
|
public static void applyEvent(GameState state, Event event) {
|
|
|
|
//TODO: implement GameLogic.applyEvent
|
|
|
|
}
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/**
|
|
|
|
* 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
|
2021-04-29 17:15:29 +00:00
|
|
|
*/
|
|
|
|
public static ParticipantType checkWinConditions(GameState state) {
|
|
|
|
//TODO: GameLogic.checkWinConditions is kind of ugly
|
|
|
|
|
|
|
|
Tuple<ParticipantType, WinCondition> player1;
|
|
|
|
Tuple<ParticipantType, WinCondition> player2;
|
|
|
|
int value1;
|
|
|
|
int value2;
|
|
|
|
for(WinCondition condition: WinCondition.values()) {
|
|
|
|
player1 = new Tuple<ParticipantType, WinCondition>(ParticipantType.Player1, condition);
|
|
|
|
player2 = new Tuple<ParticipantType, WinCondition>(ParticipantType.Player2, condition);
|
|
|
|
value1 = 0;
|
|
|
|
value2 = 0;
|
|
|
|
|
|
|
|
if(state.winConditions.containsKey(player1)) {
|
|
|
|
value1 = state.winConditions.get(player1);
|
|
|
|
}
|
|
|
|
if(state.winConditions.containsKey(player2)) {
|
|
|
|
value2 = state.winConditions.get(player2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(value1 > value2) {
|
|
|
|
return ParticipantType.Player1;
|
|
|
|
}
|
|
|
|
if(value2 > value1) {
|
|
|
|
return ParticipantType.Player2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ParticipantType.None;
|
|
|
|
}
|
|
|
|
}
|