Commit 5c7c303c authored by Corentin Guillevic's avatar Corentin Guillevic
Browse files

Small refactoring ; Add some tests to upgrade the PowerApplicator cover

parent 350118ed
......@@ -758,7 +758,7 @@ public class Game implements GameInterface {
Phase toApplied = trackingCard.getPhaseToApply();
if(toApplied.equals(state)) {
creature.removeTrackingCardToApplied(trackingCard);
applyPlayerCard(creature.getInGameId(), trackingCard, this);
applyPlayerCard(this, creature.getInGameId(), trackingCard);
trackingCardPioche.throwAway(trackingCard);
}
else {
......@@ -852,13 +852,13 @@ public class Game implements GameInterface {
traque.addSurvivalCardToApplied(survivalCard);
}
else{
applyPlayerCard(traque.getInGameId(), survivalCard, this);
applyPlayerCard(this, traque.getInGameId(), survivalCard);
traque.removeSurvivalCardToApplied(survivalCard);
survivalCardPioche.throwAway(survivalCard);
}
}
else{
applyPlayerCard(traque.getInGameId(), survivalCard, this);
applyPlayerCard(this, traque.getInGameId(), survivalCard);
traque.playSurvivalCard(survivalCard);
survivalCardPioche.throwAway(survivalCard);
}
......@@ -1066,7 +1066,7 @@ public class Game implements GameInterface {
for(Traque traque : traques) {
chosenPlaceCards = choosePlaceCardsToReveal(traque);
for(PlaceCard placeCard : chosenPlaceCards) {
resolvePlace(traque.getInGameId(), placeCard, this);
resolvePlace(this, traque.getInGameId(), placeCard);
}
sendDescription();
}
......
......@@ -36,48 +36,48 @@ public class PowerApplicator {
/**
* Apply the power of a PlayerCard on the player
* @param game The game
* @param idPlayer The id of the player
* @param playerCard The player card
* @param game The game
*/
public static void applyPlayerCard(int idPlayer, PlayerCard playerCard, Game game){
public static void applyPlayerCard(Game game, int idPlayer, PlayerCard playerCard){
if(playerCard.getType().equals(Card.CardType.TRACKING)) {
applyTrackingCardPower(idPlayer, game, playerCard.getCardName());
applyTrackingCardPower(game, playerCard.getCardName(), idPlayer);
}
else{
applySurvivalCardPower(idPlayer, game, playerCard.getCardName());
applySurvivalCardPower(game, idPlayer, playerCard.getCardName());
}
}
/**
* A traque resolve a PlaceCard
* @param game The game
* @param idPlayer The id of the traque
* @param placeCard The place card
* @param game The game
*/
public static void resolvePlace(int idPlayer, PlaceCard placeCard, Game game) {
if(filterSpecialCaseBlockPlace(idPlayer, placeCard, game)) {
public static void resolvePlace(Game game, int idPlayer, PlaceCard placeCard) {
if(filterSpecialCaseBlockPlace(game, idPlayer, placeCard)) {
return;
}
if(filterJetonBlockPlace(idPlayer, placeCard, game)) {
if(filterJetonBlockPlace(game, idPlayer, placeCard)) {
return;
}
if(! isABlockedPlaceCard(game, placeCard)){
if(game.getGameRoundVariables().getPlayersWhoHavePlayDrone().contains(idPlayer)) {
chooseCardFromReserve(idPlayer, game);
chooseCardFromReserve(game, idPlayer);
}
else if(game.getGameRoundVariables().getPlayersWhoHavePlayPortail().contains(idPlayer)) {
copyPowerOfOneAdjacentCard(idPlayer, game, placeCard);
copyPowerOfOneAdjacentCard(game, idPlayer, placeCard);
}
else if(game.getGameRoundVariables().getPlayersWhoHavePlayRegeneration().contains(idPlayer)) {
copyPowerOfOneCardInDefausse(idPlayer, game);
copyPowerOfOneCardInDefausse(game, idPlayer);
}
else{
if(game.getPlanet().isASurvivalCardOnPlace(placeCard)) {
Traque traque = (Traque) game.getPlayer(idPlayer);
traque.addSurvivalCard(game.getPlanet().takeSurvivalCardOnPlace(placeCard));
}
applyPlaceCardPower(idPlayer, placeCard.getCardName(), game);
applyPlaceCardPower(game, placeCard.getCardName(), idPlayer);
}
}
......@@ -85,12 +85,12 @@ public class PowerApplicator {
/**
* Apply the special case power and return true if place can't be resolved, false otherwise
* @param game The game
* @param idPlayer The id of player
* @param placeCard The place card resolve
* @param game The game
* @return true if place can't be resolved, false otherwise
*/
private static boolean filterSpecialCaseBlockPlace(int idPlayer, PlaceCard placeCard, Game game) {
private static boolean filterSpecialCaseBlockPlace(Game game, int idPlayer, PlaceCard placeCard) {
Planet planet = game.getPlanet();
GameRoundVariables variables = game.getGameRoundVariables();
if(variables.getPlayersWhoIsTargetRetraite().contains(idPlayer)) {
......@@ -98,7 +98,7 @@ public class PowerApplicator {
}
if(checkEpidemieCondition(game, placeCard)){
if(idPlayer != variables.getIdPlayerTargetByTrackingCardEpidemie()){
subWillingness(idPlayer, game, 1);
subWillingness(game, idPlayer, 1);
}
return true;
}
......@@ -112,7 +112,7 @@ public class PowerApplicator {
if(checkIfAdjacentToJetonCible(game, placeCard)) {
if(variables.isJetonCibleAdjacentPlaceMoveTraque()) {
PlaceCard newPlaceCard = findPlaceCardWhereTheJetonCibleIsAndAdjacent(game, placeCard);
resolvePlace(idPlayer, newPlaceCard, game);
resolvePlace(game, idPlayer, newPlaceCard);
return true;
}
else{
......@@ -124,12 +124,12 @@ public class PowerApplicator {
/**
* Check if a jeton is applied on the place card and return true if place can't be resolved, false otherwise
* @param game The game
* @param idPlayer The id of player
* @param placeCard The place card resolve
* @param game The game
* @return true if place can't be resolve, false otherwise
*/
private static boolean filterJetonBlockPlace(int idPlayer, PlaceCard placeCard, Game game) {
private static boolean filterJetonBlockPlace(Game game, int idPlayer, PlaceCard placeCard) {
Planet planet = game.getPlanet();
GameRoundVariables variables = game.getGameRoundVariables();
List<JetonSymbol> jetonSymbols = planet.findJetonsOnCard(placeCard).stream().map(Jeton::getType).collect(Collectors.toList());
......@@ -142,7 +142,7 @@ public class PowerApplicator {
//Jeton Artemia
if(canApplyArtemiaOnThisPlace && ! variables.getPlayersWhoDodgeJetonArtemia().contains(idPlayer)) {
applyJetonArtemia(idPlayer, game);
applyJetonArtemia(game, idPlayer);
blockPlace = true;
}
......@@ -152,14 +152,14 @@ public class PowerApplicator {
game.getBoard().moveForwardTraque();
}
else{
applyJetonCreature(idPlayer, game, placeCard);
applyJetonCreature(game, idPlayer, placeCard);
blockPlace = true;
}
}
//Jeton Cible
if(canApplyCibleOnThisPlace && ! variables.getPlayersWhoDodgeJetonCible().contains(idPlayer)) {
applyJetonCible(idPlayer, game);
applyJetonCible(game, idPlayer);
if(variables.isJetonCibleBlockPlace()) {
blockPlace = true;
}
......@@ -169,78 +169,78 @@ public class PowerApplicator {
/**
* A traque apply the power of one place
* @param idPlayer The id of the traque
* @param cardName The card name
* @param game The game
* @param cardName The card name
* @param idPlayer The id of the traque
*/
public static void applyPlaceCardPower(int idPlayer, CardName cardName, Game game) {
public static void applyPlaceCardPower(Game game, CardName cardName, int idPlayer) {
switch (cardName) {
case ANTRE:
applyPlaceAntre(idPlayer, game);
applyPlaceAntre(game, idPlayer);
break;
case JUNGLE:
applyPlaceJungle(idPlayer, game);
applyPlaceJungle(game, idPlayer);
break;
case RIVIERE:
applyPlaceRiviere(idPlayer, game);
applyPlaceRiviere(game, idPlayer);
break;
case PLAGE:
applyPlacePlage(idPlayer, game);
applyPlacePlage(game, idPlayer);
break;
case ROVER:
applyPlaceRover(idPlayer, game);
applyPlaceRover(game, idPlayer);
break;
case MARAIS:
applyPlaceMarais(idPlayer, game);
applyPlaceMarais(game, idPlayer);
break;
case ABRI:
applyPlaceAbri(idPlayer, game);
applyPlaceAbri(game, idPlayer);
break;
case EPAVE:
applyPlaceEpave(idPlayer, game);
applyPlaceEpave(game, idPlayer);
break;
case SOURCE:
applyPlaceSource(idPlayer, game);
applyPlaceSource(game, idPlayer);
break;
case ARTEFACT:
applyPlaceArtefact(idPlayer, game);
applyPlaceArtefact(game, idPlayer);
break;
case NEXUS:
applyPlaceNexus(idPlayer, game);
applyPlaceNexus(game, idPlayer);
break;
case OASIS:
applyPlaceOasis(idPlayer, game);
applyPlaceOasis(game, idPlayer);
break;
case FJORD:
applyPlaceFjord(idPlayer, game);
applyPlaceFjord(game, idPlayer);
break;
case DOME:
applyPlaceDome(idPlayer, game);
applyPlaceDome(game, idPlayer);
break;
case LABYRINTHE:
applyPlaceLabyrinthe(idPlayer, game);
applyPlaceLabyrinthe(game, idPlayer);
break;
case MANGROVE:
applyPlaceMangrove(idPlayer, game);
applyPlaceMangrove(game, idPlayer);
break;
case ARCHIPEL:
applyPlaceArchipel(idPlayer, game);
applyPlaceArchipel(game, idPlayer);
break;
case POLE:
applyPlacePole(idPlayer, game);
applyPlacePole(game, idPlayer);
break;
case FUNGI:
applyPlaceFungi(idPlayer, game);
applyPlaceFungi(game, idPlayer);
break;
case PORTAIL:
applyPlacePortail(idPlayer, game);
applyPlacePortail(game, idPlayer);
break;
default:
throw new IllegalArgumentException(cardName + " is not a PlaceCard name");
}
}
public static void applyTrackingCardPower(int idPlayer, Game game, CardName cardName) {
public static void applyTrackingCardPower(Game game, CardName cardName, int idPlayer) {
switch (cardName) {
case ACHARNEMENT:
applyTrackingAcharnement(game);
......@@ -249,10 +249,10 @@ public class PowerApplicator {
applyTrackingAngoisse(game);
break;
case ANTICIPATION:
applyTrackingAnticipation(idPlayer, game);
applyTrackingAnticipation(game, idPlayer);
break;
case CATACLYSME:
applyTrackingCataclysme(idPlayer, game);
applyTrackingCataclysme(game, idPlayer);
break;
case CHAMP_DE_FORCE:
applyTrackingChampDeForce(game);
......@@ -261,25 +261,25 @@ public class PowerApplicator {
applyTrackingClone(game);
break;
case DEPLOIEMENT:
applyTrackingDeploiement(idPlayer, game);
applyTrackingDeploiement(game, idPlayer);
break;
case DESESPOIR:
applyTrackingDesespoir(game);
break;
case DETOUR:
applyTrackingDetour(idPlayer, game);
applyTrackingDetour(game, idPlayer);
break;
case DOMINATION:
applyTrackingDomination(idPlayer, game);
applyTrackingDomination(game, idPlayer);
break;
case EFFROI:
applyTrackingEffroi(idPlayer, game);
applyTrackingEffroi(game, idPlayer);
break;
case EMPRISE:
applyTrackingEmprise(idPlayer, game);
applyTrackingEmprise(game, idPlayer);
break;
case EPIDEMIE:
applyTrackingEpidemie(idPlayer, game);
applyTrackingEpidemie(game, idPlayer);
break;
case FAILLE_TEMPORELLE:
applyTrackingFailleTemporelle(game);
......@@ -303,7 +303,7 @@ public class PowerApplicator {
applyTrackingInterference(game);
break;
case INTUITION:
applyTrackingIntuition(idPlayer, game);
applyTrackingIntuition(game, idPlayer);
break;
case MAGNETISME:
applyTrackingMagnetisme(game);
......@@ -315,13 +315,13 @@ public class PowerApplicator {
applyTrackingMutation(game);
break;
case PSYCHOSE:
applyTrackingPsychose(idPlayer, game);
applyTrackingPsychose(game, idPlayer);
break;
case REMINISCENCE:
applyTrackingReminiscence(idPlayer, game);
applyTrackingReminiscence(game, idPlayer);
break;
case REPERAGE:
applyTrackingReperage(idPlayer, game);
applyTrackingReperage(game, idPlayer);
break;
case SABLES_MOUVANTS:
applyTrackingSablesMouvants(game);
......@@ -333,16 +333,16 @@ public class PowerApplicator {
applyTrackingStase(game);
break;
case TELEPATHIE:
applyTrackingTelepathie(idPlayer, game);
applyTrackingTelepathie(game, idPlayer);
break;
case TORNADE:
applyTrackingTornade(idPlayer, game);
applyTrackingTornade(game, idPlayer);
break;
case TOXINE:
applyTrackingToxine(game);
break;
case UBIQUITE:
applyTrackingUbiquite(idPlayer, game);
applyTrackingUbiquite(game, idPlayer);
break;
case VIRUS:
applyTrackingVirus(game);
......@@ -355,13 +355,13 @@ public class PowerApplicator {
}
}
public static void applySurvivalCardPower(int idPlayer, Game game, CardName cardName) {
public static void applySurvivalCardPower(Game game, int idPlayer, CardName cardName) {
switch (cardName) {
case ADRENALINE:
applySurvivalAdrenaline(idPlayer, game);
applySurvivalAdrenaline(game, idPlayer);
break;
case ALERTE:
applySurvivalAlerte(idPlayer, game);
applySurvivalAlerte(game, idPlayer);
break;
case AMPLIFICATEUR:
applySurvivalAmplificateur(game);
......@@ -370,85 +370,85 @@ public class PowerApplicator {
applySurvivalBrouillage(game);
break;
case CAVALE:
applySurvivalCavale(idPlayer, game);
applySurvivalCavale(game, idPlayer);
break;
case DETECTEUR:
applySurvivalDetecteur(idPlayer, game);
applySurvivalDetecteur(game, idPlayer);
break;
case DRONE:
applySurvivalDrone(idPlayer, game);
applySurvivalDrone(game, idPlayer);
break;
case ENTRAVE:
applySurvivalEntrave(game);
break;
case EQUIPEMENT:
applySurvivalEquipement(idPlayer, game);
applySurvivalEquipement(game, idPlayer);
break;
case ESQUIVE:
applySurvivalEsquive(idPlayer, game);
applySurvivalEsquive(game, idPlayer);
break;
case FAUSSE_PISTE:
applySurvivalFaussePiste(idPlayer, game);
applySurvivalFaussePiste(game, idPlayer);
break;
case HOLOGRAMME:
applySurvivalHologramme(idPlayer, game);
applySurvivalHologramme(game, idPlayer);
break;
case LEURRE:
applySurvivalLeurre(idPlayer, game);
applySurvivalLeurre(game, idPlayer);
break;
case MIMETISME:
applySurvivalMimetisme(idPlayer, game);
applySurvivalMimetisme(game, idPlayer);
break;
case NAVETTE:
applySurvivalNavette(game);
break;
case PLANQUES:
applySurvivalPlanques(idPlayer, game);
applySurvivalPlanques(game, idPlayer);
break;
case PORTAIL_SURVIVAL:
applySurvivalPortail(idPlayer, game);
applySurvivalPortail(game, idPlayer);
break;
case RALLIEMENT:
applySurvivalRalliement(game);
break;
case REFUGE:
applySurvivalRefuge(idPlayer, game);
applySurvivalRefuge(game, idPlayer);
break;
case REGENERATION:
applySurvivalRegeneration(idPlayer, game);
applySurvivalRegeneration(game, idPlayer);
break;
case RESISTANCE:
applySurvivalResistance(idPlayer, game);
applySurvivalResistance(game, idPlayer);
break;
case RETRAITE:
applySurvivalRetraite(idPlayer, game);
applySurvivalRetraite(game, idPlayer);
break;
case RIPOSTE:
applySurvivalRiposte(game);
break;
case SACRIFICE:
applySurvivalSacrifice(idPlayer, game);
applySurvivalSacrifice(game, idPlayer);
break;
case SECOND_SOUFFLE:
applySurvivalSecondSouffle(idPlayer, game);
applySurvivalSecondSouffle(game, idPlayer);
break;
case SIXIEME_SENS:
applySurvivalSixiemeSens(idPlayer, game);
applySurvivalSixiemeSens(game, idPlayer);
break;
case SYSTEME_D:
applySurvivalSystemeD(game);
break;
case TENACITE:
applySurvivalTenacite(idPlayer, game);
applySurvivalTenacite(game, idPlayer);
break;
case VACCIN:
applySurvivalVaccin(game);
break;
case VOLTE_FACE:
applySurvivalVolteFace(idPlayer, game);
applySurvivalVolteFace(game, idPlayer);
break;
case VORTEX:
applySurvivalVortex(idPlayer, game);
applySurvivalVortex(game, idPlayer);
break;
default:
throw new IllegalArgumentException(cardName + " is not a SurvivalCard name");
......@@ -457,30 +457,25 @@ public class PowerApplicator {
/**
* Apply the power of Jeton Artemia on the player
* @param idPlayer The id of the player
* @param game The game
* @param idPlayer The id of the player
*/
public static void applyJetonArtemia(int idPlayer, Game game) {
if(! game.isJetonArtemiaIsActive()) {
return;
}
throwAwayPlaceCards(idPlayer, game, 1);
public static void applyJetonArtemia(Game game, int idPlayer) {
throwAwayPlaceCards(game, idPlayer, 1);
if(game.getGameRoundVariables().jetonArtemiaMadeLoseOneWillingness()) {
subWillingness(idPlayer, game, 1);
subWillingness(game, idPlayer, 1);
}
}
/**
* Apply the power of Jeton Creature on the player
* @param idPlayer The id of the player
* @param game The game
* @param idPlayer The id of the player
* @param placeCard The placeCard where the traque was caught
*/
public static void applyJetonCreature(int idPlayer, Game game, PlaceCard placeCard) {
public static void applyJetonCreature(Game game, int idPlayer, PlaceCard placeCard) {
GameRoundVariables variables = game.getGameRoundVariables();
variables.addPlayersWhoHasCaughtByCreature(idPlayer);
int numberWillingnessDecrement = game.getNumberWillingnessDecrementByJetonCreature();
if(placeCard.getCardName().equals(ANTRE)) {
......@@ -500,18 +495,17 @@ public class PowerApplicator {
if(game.getIdPlayerTargetByTrackingCardAnticipation() == idPlayer) {
game.getBoard().moveForwardCreature();
}
Player player = game.getPlayer(idPlayer);
checkPlayerIsNotCreature(player);
Traque traque = (Traque) player;
subWillingness(traque, game, numberWillingnessDecrement);
checkPlayerIsNotCreature(game, idPlayer);
Traque traque = (Traque) game.getPlayer(idPlayer);
subWillingness(game, traque, numberWillingnessDecrement);
}
/**
* Apply the power of Jeton Cible on the player
* @param idPlayer The id of the player
* @param game The game
* @param idPlayer The id of the player
*/
public static void applyJetonCible(int idPlayer, Game game) {
public static void applyJetonCible(Game game, int idPlayer) {
//Apply the jeton cible's power
game.getGameRoundVariables().getActionJetonCible().accept(idPlayer, game);
}
......@@ -520,26 +514,26 @@ public class PowerApplicator {
* Apply places
***********************************/
private static void applyPlaceAntre(int idPlayer, Game game) {
private static void applyPlaceAntre(Game game, int idPlayer) {
GameRoundVariables variables = game.getGameRoundVariables();
boolean isLimited = variables.numberMaxPlaceCardsGetByPlacePowerIsLimited();
List<String> powersDescription = database.findPowersDescription(CardName.ANTRE);
int idPower = game.choosePower(idPlayer, powersDescription);
if(!isLimited && idPower == 0) {
takeBackAllCardsFromDefausse(idPlayer, game);
takeBackAllCardsFromDefausse(game, idPlayer);
}
//Copy Power is always the second power
else if (idPower == 1) {
copyPowerWhereJetonCreatureIs(idPlayer, game);
copyPowerWhereJetonCreatureIs(game, idPlayer);
}
//Third power when no isLimited or first power when isLimited
else {
takeBackCardsFromDefausse(idPlayer, game, 1);
takeBackCardsFromDefausse(game, idPlayer, 1);
}
}
private static void applyPlaceJungle(int idPlayer,