Commit f0d5af23 authored by Corentin Guillevic's avatar Corentin Guillevic
Browse files

Add all the tests of TrackingCard power ; Add some correction

parent 2eed842e
......@@ -1201,7 +1201,9 @@ public class PowerApplicator {
BiConsumer<Integer, Game> action = (Integer id, Game g) -> {
Traque traque = (Traque) g.getPlayer(id);
int number = traque.placeCardHandSize() - 2;
throwAwayPlaceCards(id, g, number);
if(number > 0){
throwAwayPlaceCards(id, g, number);
}
};
game.getGameRoundVariables().setActionJetonCible(action);
}
......
......@@ -4,6 +4,7 @@ import fr.univnantes.alma.server.game.item.power.PowerType;
public abstract class Jeton {
//TODO remove
protected PowerType power;
//TODO Constructor
......
......@@ -16,6 +16,7 @@ import fr.univnantes.alma.server.game.item.card.Card;
import fr.univnantes.alma.server.game.item.card.PlaceCard;
import fr.univnantes.alma.server.game.item.card.SurvivalCard;
import fr.univnantes.alma.server.game.item.card.TrackingCard;
import fr.univnantes.alma.server.game.item.jeton.JetonArtemia;
import fr.univnantes.alma.server.game.item.jeton.JetonSymbol;
import fr.univnantes.alma.server.game.item.jeton.PlacedJeton;
import fr.univnantes.alma.server.game.item.pioche.Pioche;
......@@ -2602,4 +2603,361 @@ class PowerApplicatorTest {
assertTrue(creature.getTrackingCardHand().contains(trackingCard.get(0)));
}
@Test
void testApplyPlayerCard_reperage() throws TException {
Game game = new Game(2, 1, planet, board, room, gameClientHandler);
TAction placeOne = new TAction(CHOOSE_PLACE.toString(),
Collections.singletonList(new TPair(TPairType.PLACE.toString(), Place.PLACE_ONE.toString())));
when(gameClientHandler.askAction(any(TAskAction.class)))
.thenReturn(placeOne);
Creature creature = game.getCreature();
PowerApplicator.applyTrackingCardPower(creature.getInGameId(), game, REPERAGE);
creature.getTrackingCardHand().clear();
TrackingCard angoisse = database.findTrackingCard(ANGOISSE.toString());
TrackingCard cataclysme = database.findTrackingCard(CATACLYSME.toString());
creature.addTrackingCard(angoisse);
creature.addTrackingCard(cataclysme);
game.nextRound();
assertTrue(game.playerPlayCard(creature.getInGameId(), angoisse).state);
//Start phase 1
game.startNextPhase();
//Start postphase 1
game.startNextPhase();
//Start prephase 2
game.startNextPhase();
//Start phase 2
game.startNextPhase();
//Start postphase 2
game.startNextPhase();
//Start prephase 3
game.startNextPhase();
assertTrue(game.playerPlayCard(creature.getInGameId(), cataclysme).state);
assertFalse(game.getGameRoundVariables().traqueCanResist());
assertTrue(planet.isBlockedPlace(antre));
}
@Test
void testApplyPlayerCard_sablesMouvants() throws TException {
Game game = new Game(4, 1, planet, board, room, gameClientHandler);
Creature creature= game.getCreature();
creature.playTrackingCard(creature.getTrackingCardHand().get(0));
TAction chooseCard1 = new TAction(CHOOSE_CARD.toString(),
Arrays.asList(new TPair(TPairType.CARD.toString(), ANTRE.toString())
,new TPair(TPairType.CARD.toString(), JUNGLE.toString())
,new TPair(TPairType.CARD.toString(), RIVIERE.toString())));
TAction chooseCard2 = new TAction(CHOOSE_CARD.toString(),
Arrays.asList(new TPair(TPairType.CARD.toString(), ANTRE.toString())
,new TPair(TPairType.CARD.toString(), JUNGLE.toString())));
when(gameClientHandler.askAction(any(TAskAction.class)))
.thenReturn(chooseCard1)
.thenReturn(chooseCard2);
planet.forceMovePlanetPawn();
PowerApplicator.applyTrackingCardPower(creature.getInGameId(), game, SABLES_MOUVANTS);
PlacedJeton placedJeton = new PlacedJeton(JetonSymbol.CIBLE, Place.PLACE_FOUR);
planet.placeJeton(placedJeton);
placedJeton = new PlacedJeton(JetonSymbol.CREATURE, Place.PLACE_FOUR);
planet.placeJeton(placedJeton);
Traque traque1 = (Traque) game.getPlayer(2);
Traque traque2 = (Traque) game.getPlayer(3);
Traque traque3 = (Traque) game.getPlayer(4);
traque2.throwAwayPlaceCard(Collections.singletonList(rover));
traque3.throwAwayPlaceCard(Arrays.asList(riviere, plage, rover));
PowerApplicator.resolvePlace(traque1.getInGameId(), plage, game);
PowerApplicator.resolvePlace(traque2.getInGameId(), plage, game);
PowerApplicator.resolvePlace(traque3.getInGameId(), plage, game);
assertTrue(traque1.getDefausse().containsAll(Arrays.asList(antre, jungle, riviere)));
assertTrue(traque2.getDefausse().containsAll(Arrays.asList(antre, jungle, rover)));
assertTrue(traque3.getDefausse().containsAll(Arrays.asList(riviere, plage, rover)));
}
@Test
void testApplyPlayerCard_soifDeSang() throws TException {
Game game = new Game(4, 1, planet, board, room, gameClientHandler);
Creature creature= game.getCreature();
creature.playTrackingCard(creature.getTrackingCardHand().get(0));
TAction chooseCard = new TAction(CHOOSE_CARD.toString(),
Collections.singletonList(new TPair(TPairType.CARD.toString(), ANTRE.toString())));
when(gameClientHandler.askAction(any(TAskAction.class)))
.thenReturn(chooseSecondPower)
.thenReturn(chooseCard)
.thenReturn(chooseSecondPower)
.thenReturn(chooseCard)
.thenReturn(chooseSecondPower)
.thenReturn(chooseCard);
PowerApplicator.applyTrackingCardPower(creature.getInGameId(), game, SOIF_DE_SANG);
PlacedJeton placedJeton = new PlacedJeton(JetonSymbol.CIBLE, Place.PLACE_FOUR);
planet.placeJeton(placedJeton);
Traque traque1 = (Traque) game.getPlayer(2);
Traque traque2 = (Traque) game.getPlayer(3);
Traque traque3 = (Traque) game.getPlayer(4);
traque1.throwAwayPlaceCard(Collections.singletonList(antre));
traque1.subWillingness(1);
traque2.throwAwayPlaceCard(Collections.singletonList(antre));
traque3.throwAwayPlaceCard(Collections.singletonList(antre));
PowerApplicator.resolvePlace(traque1.getInGameId(), plage, game);
PowerApplicator.resolvePlace(traque2.getInGameId(), riviere, game);
PowerApplicator.resolvePlace(traque3.getInGameId(), rover, game);
assertEquals(3, traque1.getNumberWillingness());
assertEquals(2, traque2.getNumberWillingness());
assertEquals(2, traque3.getNumberWillingness());
}
@Test
void testApplyPlayerCard_stase() {
Game game = new Game(2, 1, planet, board, room, gameClientHandler);
Creature creature = game.getCreature();
Score score = new Score(2);
assertEquals(score, game.getBoard().getScore());
game.nextRound();
score.moveForwardTraque(1);
assertEquals(score, game.getBoard().getScore());
PowerApplicator.applyTrackingCardPower(creature.getInGameId(), game, STASE);
game.nextRound();
assertEquals(score, game.getBoard().getScore());
}
@Test
void testApplyPlayerCard_telepathieCreatureFindTheCard() throws TException {
Game game = new Game(2, 1, planet, board, room, gameClientHandler);
TAction chooseCard = new TAction(CHOOSE_CARD.toString(),
Collections.singletonList(new TPair(TPairType.CARD.toString(), ANTRE.toString())));
TAction targetPlayer = new TAction(TARGET_PLAYER.toString(),
Collections.singletonList(new TPair(TPairType.PLAYER.toString(), "2")));
when(gameClientHandler.askAction(any(TAskAction.class)))
.thenReturn(chooseCard)
.thenReturn(targetPlayer);
Traque traque = (Traque) game.getPlayer(2);
traque.getPlaceCards().clear();
traque.addPlaceCard(Arrays.asList(antre, antre, antre, antre, antre));
Creature creature = game.getCreature();
PowerApplicator.applyTrackingCardPower(creature.getInGameId(), game, TELEPATHIE);
Score score = new Score(2);
score.moveForwardCreature(1);
assertEquals(score, game.getBoard().getScore());
assertEquals(Collections.singletonList(antre), traque.getDefausse());
}
@Test
void testApplyPlayerCard_telepathieCreatureDoesNotFindTheCard() throws TException {
Game game = new Game(2, 1, planet, board, room, gameClientHandler);
TAction chooseCard = new TAction(CHOOSE_CARD.toString(),
Collections.singletonList(new TPair(TPairType.CARD.toString(), JUNGLE.toString())));
TAction targetPlayer = new TAction(TARGET_PLAYER.toString(),
Collections.singletonList(new TPair(TPairType.PLAYER.toString(), "2")));
when(gameClientHandler.askAction(any(TAskAction.class)))
.thenReturn(chooseCard)
.thenReturn(targetPlayer);
Traque traque = (Traque) game.getPlayer(2);
traque.getPlaceCards().clear();
traque.addPlaceCard(Arrays.asList(antre, antre, antre, antre, antre));
Creature creature = game.getCreature();
PowerApplicator.applyTrackingCardPower(creature.getInGameId(), game, TELEPATHIE);
Score score = new Score(2);
assertEquals(score, game.getBoard().getScore());
assertEquals(Collections.singletonList(antre), traque.getDefausse());
}
@Test
void testApplyPlayerCard_tornade() throws TException {
Game game = new Game(2, 1, planet, board, room, gameClientHandler);
TAction choosePlace = new TAction(CHOOSE_PLACE.toString(),
Collections.singletonList(new TPair(TPairType.PLACE.toString(), Place.PLACE_TWO.toString())));
when(gameClientHandler.askAction(any(TAskAction.class)))
.thenReturn(choosePlace);
PlacedJeton placedJeton = new PlacedJeton(JetonSymbol.ARTEMIA, Place.PLACE_ONE);
planet.placeJeton(placedJeton);
Creature creature = game.getCreature();
creature.playJeton(new JetonArtemia());
assertTrue(planet.findJetonsSymbolsOnCard(antre).contains(JetonSymbol.ARTEMIA));
assertFalse(planet.findJetonsSymbolsOnCard(jungle).contains(JetonSymbol.ARTEMIA));
PowerApplicator.applyTrackingCardPower(creature.getInGameId(), game, TORNADE);
assertFalse(planet.findJetonsSymbolsOnCard(antre).contains(JetonSymbol.ARTEMIA));
assertTrue(planet.findJetonsSymbolsOnCard(jungle).contains(JetonSymbol.ARTEMIA));
}
@Test
void testApplyPlayerCard_toxine() throws TException {
Game game = new Game(4, 1, planet, board, room, gameClientHandler);
Pioche<SurvivalCard> survivalCardPioche = game.getSurvivalCardPioche();
SurvivalCard survivalCard = survivalCardPioche.draw();
Traque traque1 = (Traque) game.getPlayer(2);
traque1.getSurvivalCardsHand().clear();
traque1.addSurvivalCard(survivalCard);
Traque traque2 = (Traque) game.getPlayer(3);
traque2.getSurvivalCardsHand().clear();
traque2.addSurvivalCard(survivalCard);
Traque traque3 = (Traque) game.getPlayer(4);
TAction chooseCard = new TAction(CHOOSE_CARD.toString(),
Collections.singletonList(new TPair(TPairType.CARD.toString(), survivalCard.getCardName().toString())));
when(gameClientHandler.askAction(any(TAskAction.class)))
.thenReturn(chooseFirstPower)
.thenReturn(chooseCard)
.thenReturn(chooseCard)
.thenReturn(chooseSecondPower);
Creature creature = game.getCreature();
PowerApplicator.applyTrackingCardPower(creature.getInGameId(), game, TOXINE);
PlacedJeton placedJeton = new PlacedJeton(JetonSymbol.CIBLE, Place.PLACE_FOUR);
planet.placeJeton(placedJeton);
PowerApplicator.resolvePlace(traque1.getInGameId(), plage, game);
PowerApplicator.resolvePlace(traque2.getInGameId(), plage, game);
PowerApplicator.resolvePlace(traque3.getInGameId(), rover, game);
assertTrue(traque1.getSurvivalCardsHand().isEmpty());
assertTrue(traque2.getSurvivalCardsHand().isEmpty());
assertFalse(traque3.getSurvivalCardsHand().isEmpty());
}
@Test
void testApplyPlayerCard_ubiquite() throws TException {
Game game = new Game(2, 1, planet, board, room, gameClientHandler);
TAction swapJeton = new TAction(SWAP_JETONS.toString(),
Arrays.asList(new TPair(TPairType.JETON.toString(), JetonSymbol.ARTEMIA.toString()),
new TPair(TPairType.JETON.toString(), JetonSymbol.CIBLE.toString())));
when(gameClientHandler.askAction(any(TAskAction.class)))
.thenReturn(swapJeton);
PlacedJeton placedJeton = new PlacedJeton(JetonSymbol.ARTEMIA, Place.PLACE_ONE);
planet.placeJeton(placedJeton);
placedJeton = new PlacedJeton(JetonSymbol.CIBLE, Arrays.asList(Place.PLACE_THREE, Place.PLACE_TWO));
planet.placeJeton(placedJeton);
Creature creature = game.getCreature();
assertTrue(planet.findJetonsSymbolsOnCard(antre).contains(JetonSymbol.ARTEMIA));
assertTrue(planet.findJetonsSymbolsOnCard(jungle).contains(JetonSymbol.CIBLE));
assertTrue(planet.findJetonsSymbolsOnCard(riviere).contains(JetonSymbol.CIBLE));
PowerApplicator.applyTrackingCardPower(creature.getInGameId(), game, UBIQUITE);
assertTrue(planet.findJetonsSymbolsOnCard(antre).contains(JetonSymbol.CIBLE));
assertTrue(planet.findJetonsSymbolsOnCard(jungle).contains(JetonSymbol.ARTEMIA));
assertTrue(planet.findJetonsSymbolsOnCard(riviere).contains(JetonSymbol.ARTEMIA));
planet.reset();
placedJeton = new PlacedJeton(JetonSymbol.CIBLE, Place.PLACE_ONE);
planet.placeJeton(placedJeton);
placedJeton = new PlacedJeton(JetonSymbol.ARTEMIA, Arrays.asList(Place.PLACE_THREE, Place.PLACE_TWO));
planet.placeJeton(placedJeton);
assertTrue(planet.findJetonsSymbolsOnCard(antre).contains(JetonSymbol.CIBLE));
assertTrue(planet.findJetonsSymbolsOnCard(jungle).contains(JetonSymbol.ARTEMIA));
assertTrue(planet.findJetonsSymbolsOnCard(riviere).contains(JetonSymbol.ARTEMIA));
PowerApplicator.applyTrackingCardPower(creature.getInGameId(), game, UBIQUITE);
assertTrue(planet.findJetonsSymbolsOnCard(antre).contains(JetonSymbol.ARTEMIA));
assertTrue(planet.findJetonsSymbolsOnCard(jungle).contains(JetonSymbol.CIBLE));
assertTrue(planet.findJetonsSymbolsOnCard(riviere).contains(JetonSymbol.CIBLE));
}
@Test
void testApplyPlayerCard_virus() {
Game game = new Game(2, 1, planet, board, room, gameClientHandler);
Creature creature = game.getCreature();
PowerApplicator.applyTrackingCardPower(creature.getInGameId(), game, VIRUS);
assertTrue(game.getGameRoundVariables().jetonArtemiaCanBeOnTwoAdjacentPlaces());
}
@Test
void testApplyPlayerCard_zoneInterdite() throws TException {
Game game = new Game(4, 1, planet, board, room, gameClientHandler);
Creature creature = game.getCreature();
TAction chooseCard = new TAction(CHOOSE_CARD.toString(),
Collections.singletonList(new TPair(TPairType.CARD.toString(), ANTRE.toString())));
when(gameClientHandler.askAction(any(TAskAction.class)))
.thenReturn(chooseCard);
Traque traque1 = (Traque) game.getPlayer(2);
Traque traque2 = (Traque) game.getPlayer(3);
Traque traque3 = (Traque) game.getPlayer(4);
PowerApplicator.applyTrackingCardPower(creature.getInGameId(), game, ZONE_INTERDITE);
assertTrue(traque1.getDefausse().contains(antre));
assertTrue(traque2.getDefausse().contains(antre));
assertTrue(traque3.getDefausse().contains(antre));
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment