feat: add handling for overtime victories
This commit is contained in:
parent
a416698adf
commit
0f50efa121
@ -11,5 +11,7 @@ public enum EntityType {
|
||||
/** Represents a Rock entity */
|
||||
Rocks,
|
||||
/** Represents an InfinityStone entity */
|
||||
InfinityStones
|
||||
InfinityStones,
|
||||
/** Represents nothing */
|
||||
None
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/** Contains game logic handling. */
|
||||
class GameLogic {
|
||||
@ -549,13 +548,13 @@ class GameLogic {
|
||||
}
|
||||
|
||||
if(character.inventory.getFreeSlots() == 0) { // no slots => has all infinity stones
|
||||
result.addAll(handlePlayerWin(state, character));
|
||||
result.addAll(handlePlayerWin(state, character.id.type));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if(alive.isEmpty()) {
|
||||
result.addAll(handleThanosWin(state));
|
||||
result.addAll(handlePlayerWin(state, checkWinConditions(state)));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -745,48 +744,33 @@ class GameLogic {
|
||||
* @param winner The winning character
|
||||
* @return The list of resulting {@link Event}s
|
||||
*/
|
||||
public static ArrayList<Event> handlePlayerWin(GameState state, Character winner) {
|
||||
public static ArrayList<Event> handlePlayerWin(GameState state, EntityType winner) {
|
||||
ArrayList<Event> result = new ArrayList<>();
|
||||
|
||||
state.won = true;
|
||||
|
||||
result.add(new EventBuilder(EventType.WinEvent)
|
||||
.withPlayerWon(winner.id.id)
|
||||
.withPlayerWon(winner == EntityType.P1 ? 1 : 2)
|
||||
.buildGameEvent());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the special victory conditions after all characters are knocked out.
|
||||
* @param state The game state to work on
|
||||
* @return The list of resulting {@link Event}s
|
||||
*/
|
||||
public static ArrayList<Event> handleThanosWin(GameState state) {
|
||||
ArrayList<Event> result = new ArrayList<>();
|
||||
|
||||
state.won = true;
|
||||
|
||||
//TODO: add thanos victory event
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return The {@link EntityType} that is currently winning the game according to overtime ruling
|
||||
*/
|
||||
public static ParticipantType checkWinConditions(GameState state) {
|
||||
public static EntityType checkWinConditions(GameState state) {
|
||||
//TODO: GameLogic.checkWinConditions is kind of ugly
|
||||
|
||||
Tuple<ParticipantType, WinCondition> player1;
|
||||
Tuple<ParticipantType, WinCondition> player2;
|
||||
Tuple<EntityType, WinCondition> player1;
|
||||
Tuple<EntityType, 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);
|
||||
player1 = new Tuple<EntityType, WinCondition>(EntityType.P1, condition);
|
||||
player2 = new Tuple<EntityType, WinCondition>(EntityType.P2, condition);
|
||||
value1 = 0;
|
||||
value2 = 0;
|
||||
|
||||
@ -798,13 +782,13 @@ class GameLogic {
|
||||
}
|
||||
|
||||
if(value1 > value2) {
|
||||
return ParticipantType.Player1;
|
||||
return EntityType.P1;
|
||||
}
|
||||
if(value2 > value1) {
|
||||
return ParticipantType.Player2;
|
||||
return EntityType.P2;
|
||||
}
|
||||
}
|
||||
|
||||
return ParticipantType.None;
|
||||
return EntityType.None;
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ class GameState {
|
||||
public final StoneCooldownManager stoneCooldown = new StoneCooldownManager();
|
||||
|
||||
/** The store of the {@link WinCondition} data for every win condition for each player */
|
||||
public final HashMap<Tuple<ParticipantType, WinCondition>, Integer> winConditions = new HashMap<>();
|
||||
public final HashMap<Tuple<EntityType, WinCondition>, Integer> winConditions = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Constructs a new {@link GameState}.
|
||||
@ -73,7 +73,7 @@ class GameState {
|
||||
|
||||
clone.stoneCooldown.cloneFrom(stoneCooldown);
|
||||
|
||||
for(Tuple<ParticipantType, WinCondition> condition: winConditions.keySet()) {
|
||||
for(Tuple<EntityType, WinCondition> condition: winConditions.keySet()) {
|
||||
clone.winConditions.put(condition, winConditions.get(condition));
|
||||
}
|
||||
|
||||
@ -104,7 +104,7 @@ class GameState {
|
||||
|
||||
stoneCooldown.cloneFrom(state.stoneCooldown);
|
||||
|
||||
for(Tuple<ParticipantType, WinCondition> condition: state.winConditions.keySet()) {
|
||||
for(Tuple<EntityType, WinCondition> condition: state.winConditions.keySet()) {
|
||||
winConditions.put(condition, state.winConditions.get(condition));
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ 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.EntityType;
|
||||
import uulm.teamname.marvelous.gamelibrary.entities.StoneType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -53,7 +54,7 @@ public class GameStateView {
|
||||
return state.stoneCooldown.getCooldown(stone);
|
||||
}
|
||||
|
||||
public ParticipantType getWinnerAccordingToWinConditions() {
|
||||
public EntityType getWinnerAccordingToWinConditions() {
|
||||
return GameLogic.checkWinConditions(state);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user