diff --git a/backend/src/main/java/com/softdesign/plagueinc/util/EventReference.java b/backend/src/main/java/com/softdesign/plagueinc/util/EventReference.java index 7521e93..5a926d8 100644 --- a/backend/src/main/java/com/softdesign/plagueinc/util/EventReference.java +++ b/backend/src/main/java/com/softdesign/plagueinc/util/EventReference.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.IntStream; +import java.util.concurrent.CompletableFuture; import com.softdesign.plagueinc.models.events.EventCard; import com.softdesign.plagueinc.models.events.EventCard.GameStateAction; @@ -38,7 +39,14 @@ public static EventCard birdMigration(){ public static EventCard bombedInfectedCities(){ //TODO: Implement condition & event - GameStateAction condition = (plague, gameState) -> {}; + GameStateAction condition = (plague, gameState) -> { + if(gameState.getPlayState()!= PlayState.END_OF_TURN){ + throw new IllegalStateException("PlayState is not END_OF_TERM"); + } + if(!gameState.getCurrTurn().equals(plague)){ + throw new IllegalStateException("It is not this players turn"); + } + }; GameStateAction event = (plague, gameState) -> {}; return new EventCard("bombed_infected_cities", condition, event); }//end of bombedInfectedCities @@ -89,7 +97,16 @@ public static EventCard emergencyCare(){ public static EventCard executeInfected(){ //TODO: Implement condition & event - GameStateAction condition = (plague, gameState) -> {}; + GameStateAction condition = (plague, gameState) -> { + if(gameState.getPlayState() != PlayState.END_OF_TURN){ + throw new IllegalStateException("PlayState is not END_OF_TURN"); + } + if(!gameState.getCurrTurn().equals(plague)){ + throw new IllegalStateException("It is not this players turn"); + } + + //TODO: Add logic for other conditions on card (if killed a country) + }; GameStateAction event = (plague, gameState) -> {}; return new EventCard("execute_infected", condition, event); }//end of executeInfected @@ -113,28 +130,64 @@ public static EventCard geneticSurge(){ public static EventCard governmentCollapse(){ //TODO: Implement condition & event - GameStateAction condition = (plague, gameState) -> {}; + GameStateAction condition = (plague, gameState) -> { + if(gameState.getPlayState() != PlayState.END_OF_TURN){ + throw new IllegalStateException("PlayState is not END_OF_TURN"); + } + if(!gameState.getCurrTurn().equals(plague)){ + throw new IllegalStateException("It is not this players turn"); + } + + //TODO: add additional conditions for card + }; GameStateAction event = (plague, gameState) -> {}; return new EventCard("government_collapse", condition, event); }//end of governmentCollapse public static EventCard hereOnBusiness(){ //TODO: Implement condition & event - GameStateAction condition = (plague, gameState) -> {}; + GameStateAction condition = (plague, gameState) -> { + if(gameState.getPlayState() != PlayState.START_OF_TURN){ + throw new IllegalStateException("PlayState is not START_OF_TURN"); + } + if(!gameState.getCurrTurn().equals(plague)){ + throw new IllegalStateException("It is not this players turn"); + } + + //TODO: add aditional conditions + }; GameStateAction event = (plague, gameState) -> {}; return new EventCard("here_on_business", condition, event); }//end of hereOnBusiness public static EventCard immuneReaction(){ //TODO: Implement condition & event - GameStateAction condition = (plague, gameState) -> {}; + GameStateAction condition = (plague, gameState) -> { + if(gameState.getPlayState() != PlayState.START_OF_TURN){ + throw new IllegalStateException("PlayState is not START_OF_TURN"); + } + if(!gameState.getCurrTurn().equals(plague)){ + throw new IllegalStateException("It is not this players turn"); + } + + //TODO: add aditional conditions + }; GameStateAction event = (plague, gameState) -> {}; return new EventCard("immune_reaction", condition, event); }//end of immuneReaction public static EventCard infectedRefugees(){ //TODO: Implement condition & event - GameStateAction condition = (plague, gameState) -> {}; + GameStateAction condition = (plague, gameState) -> { + if(gameState.getPlayState() != PlayState.END_OF_TURN){ + throw new IllegalStateException("PlayState is not END_OF_TURN"); + } + if(!gameState.getCurrTurn().equals(plague)){ + throw new IllegalStateException("It is not this players turn"); + } + + //TODO: add aditional conditions + }; GameStateAction event = (plague, gameState) -> {}; return new EventCard("infected_refugees", condition, event); }//end of infectedRefugees @@ -162,84 +215,203 @@ public static EventCard neutralise(){ public static EventCard newTradeRoute(){ //TODO: Implement condition & event - GameStateAction condition = (plague, gameState) -> {}; + GameStateAction condition = (plague, gameState) -> { + if(gameState.getPlayState() != PlayState.START_OF_TURN){ + throw new IllegalStateException("PlayState is not START_OF_TURN"); + } + if(!gameState.getCurrTurn().equals(plague)){ + throw new IllegalStateException("It is not this players turn"); + } + + //TODO: add aditional conditions + }; GameStateAction event = (plague, gameState) -> {}; return new EventCard("new_trade_route", condition, event); }//end of newTradeRoute public static EventCard nuclearStrike(){ //TODO: Implement condition & event - GameStateAction condition = (plague, gameState) -> {}; + GameStateAction condition = (plague, gameState) -> { + if(gameState.getPlayState() != PlayState.END_OF_TURN){ + throw new IllegalStateException("PlayState is not END_OF_TURN"); + } + if(!gameState.getCurrTurn().equals(plague)){ + throw new IllegalStateException("It is not this players turn"); + } + + //TODO: add aditional conditions + }; GameStateAction event = (plague, gameState) -> {}; return new EventCard("nuclear_strike", condition, event); }//end of nuclearStrike public static EventCard olympics(){ //TODO: Implement condition & event - GameStateAction condition = (plague, gameState) -> {}; + GameStateAction condition = (plague, gameState) -> { + if(gameState.getPlayState() != PlayState.START_OF_TURN){ + throw new IllegalStateException("PlayState is not START_OF_TURN"); + } + if(!gameState.getCurrTurn().equals(plague)){ + throw new IllegalStateException("It is not this players turn"); + } + + //TODO: add aditional conditions + }; GameStateAction event = (plague, gameState) -> {}; return new EventCard("olympics", condition, event); }//end of olympics public static EventCard opportunisticBreakdown(){ //TODO: Implement condition & event - GameStateAction condition = (plague, gameState) -> {}; + GameStateAction condition = (plague, gameState) -> { + if(gameState.getPlayState() != PlayState.END_OF_TURN){ + throw new IllegalStateException("PlayState is not END_OF_TURN"); + } + if(!gameState.getCurrTurn().equals(plague)){ + throw new IllegalStateException("It is not this players turn"); + } + + //TODO: add aditional conditions + }; GameStateAction event = (plague, gameState) -> {}; return new EventCard("opportunitstic_breakdown", condition, event); }//end of opportunisticBreakDown public static EventCard pandemicAlert(){ //TODO: Implement condition & event - GameStateAction condition = (plague, gameState) -> {}; + GameStateAction condition = (plague, gameState) -> { + if(gameState.getPlayState() != PlayState.END_OF_TURN){ + throw new IllegalStateException("PlayState is not END_OF_TURN"); + } + if(!gameState.getCurrTurn().equals(plague)){ + throw new IllegalStateException("It is not this players turn"); + } + + //TODO: add aditional conditions + }; GameStateAction event = (plague, gameState) -> {}; return new EventCard("pandemic_alert", condition, event); }//end of pandemicAlert public static EventCard pilgrimage(){ //TODO: Implement condition & event - GameStateAction condition = (plague, gameState) -> {}; + GameStateAction condition = (plague, gameState) -> { + if(gameState.getPlayState() != PlayState.START_OF_TURN){ + throw new IllegalStateException("PlayState is not START_OF_TURN"); + } + if(!gameState.getCurrTurn().equals(plague)){ + throw new IllegalStateException("It is not this players turn"); + } + + //TODO: add aditional conditions + }; GameStateAction event = (plague, gameState) -> {}; return new EventCard("pilgrimage", condition, event); }//end of pilgrimage public static EventCard rioting(){ //TODO: Implement condition & event - GameStateAction condition = (plague, gameState) -> {}; - GameStateAction event = (plague, gameState) -> {}; + GameStateAction condition = (plague, gameState) -> { + if(!gameState.getPlayState.equals(PlayState.END_OF_TURN)){ + throw new IllegalStateException("Game is not at end of turn"); + } + if(!gameState.getCurrTurn().equals(plague)){ + throw new IllegalStateException("It is not this players turn"); + } + }; + FutureInterface> createFuture = (plague) -> { + return new CompletableFuture<>().whenComplete((country, ex) -> { + if(ex != null){ + //TODO implement error checking + } + else{ + if(country.getInfectionByPlayer().keySet().contains(plague)){ + country.infectCountry(plague); + country.infectCountry(plague); + } + else{ + //TODO implement error checking + } + } + }) + }; + GameStateAction event = (plague, gameState) -> { + gameState.setCountrySelectionFuture(createFuture.op(plague)); + }; + + return new EventCard("rioting", condition, event); }//end of rioting public static EventCard soapShortage(){ //TODO: Implement condition & event - GameStateAction condition = (plague, gameState) -> {}; + GameStateAction condition = (plague, gameState) -> { + if(gameState.getPlayState() != PlayState.START_OF_TURN){ + throw new IllegalStateException("PlayState is not START_OF_TURN"); + } + if(!gameState.getCurrTurn().equals(plague)){ + throw new IllegalStateException("It is not this players turn"); + } + + //TODO: add aditional conditions + }; GameStateAction event = (plague, gameState) -> {}; return new EventCard("soap_shortage", condition, event); }//end of soap_shortage public static EventCard summerVacation(){ //TODO: Implement condition & event - GameStateAction condition = (plague, gameState) -> {}; + GameStateAction condition = (plague, gameState) -> { + if(gameState.getPlayState() != PlayState.START_OF_TURN){ + throw new IllegalStateException("PlayState is not START_OF_TURN"); + } + if(!gameState.getCurrTurn().equals(plague)){ + throw new IllegalStateException("It is not this players turn"); + } + + //TODO: add aditional conditions + }; GameStateAction event = (plague, gameState) -> {}; return new EventCard("summerVacation", condition, event); }//end of summerVacation public static EventCard temporaryMutation(){ //TODO: Implement condition & event - GameStateAction condition = (plague, gameState) -> {}; + GameStateAction condition = (plague, gameState) -> { + if(gameState.getPlayState() != PlayState.START_OF_TURN){ + throw new IllegalStateException("PlayState is not START_OF_TURN"); + } + if(!gameState.getCurrTurn().equals(plague)){ + throw new IllegalStateException("It is not this players turn"); + } + + //TODO: add aditional conditions + }; GameStateAction event = (plague, gameState) -> {}; return new EventCard("temporary_mutation", condition, event); }//end of temporaryMutation public static EventCard winterVacation(){ //TODO: Implement condition & event - GameStateAction condition = (plague, gameState) -> {}; + GameStateAction condition = (plague, gameState) -> { + if(gameState.getPlayState() != PlayState.START_OF_TURN){ + throw new IllegalStateException("PlayState is not START_OF_TURN"); + } + if(!gameState.getCurrTurn().equals(plague)){ + throw new IllegalStateException("It is not this players turn"); + } + + //TODO: add aditional conditions + }; GameStateAction event = (plague, gameState) -> {}; return new EventCard("winter_vacation", condition, event); }//end of winterVacation - + private static interface FutureInterface{ + public CompletableFuture op(); + }