Commit a60e88b2 authored by Corentin Guillevic's avatar Corentin Guillevic

Small refactoring

parent 7cd1354f
package fr.univnantes.alma.server.game.item.power.recurrent; package fr.univnantes.alma.server.game.item.power.recurrent;
import fr.univnantes.alma.server.game.Game; import fr.univnantes.alma.server.game.Game;
import fr.univnantes.alma.server.game.item.Phase;
import fr.univnantes.alma.server.game.item.power.Power; import fr.univnantes.alma.server.game.item.power.Power;
import fr.univnantes.alma.server.game.item.power.PowerType; import fr.univnantes.alma.server.game.item.power.PowerType;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.BiFunction; import java.util.function.BiPredicate;
public class PowerRecurrent extends Power { public class PowerRecurrent extends Power {
private BiConsumer<Integer, Game> action; private final BiConsumer<Integer, Game> action;
private BiFunction<Integer, Game, Boolean> condition; private final BiPredicate<Integer, Game> condition;
private Phase phase;
public PowerRecurrent(int inGameIdPlayer, BiConsumer<Integer, Game> action, BiFunction<Integer, Game, Boolean> condition) { public PowerRecurrent(int inGameIdPlayer, BiConsumer<Integer, Game> action, BiPredicate<Integer, Game> condition) {
super(inGameIdPlayer); super(inGameIdPlayer);
this.action = action; this.action = action;
this.condition = condition; this.condition = condition;
...@@ -25,7 +23,7 @@ public class PowerRecurrent extends Power { ...@@ -25,7 +23,7 @@ public class PowerRecurrent extends Power {
} }
public boolean conditionIsTrue(Game game) { public boolean conditionIsTrue(Game game) {
return condition.apply(inGameIdPlayer, game); return condition.test(inGameIdPlayer, game);
} }
@Override @Override
......
package fr.univnantes.alma.server; package fr.univnantes.alma.server.game;
import fr.univnantes.alma.common.NotAloneDatabase; import fr.univnantes.alma.common.NotAloneDatabase;
import fr.univnantes.alma.data.DatabaseFactory; import fr.univnantes.alma.data.DatabaseFactory;
...@@ -1404,6 +1404,33 @@ class PowerApplicatorTest { ...@@ -1404,6 +1404,33 @@ class PowerApplicatorTest {
assertEquals(Collections.singletonList(nexus), traque.getPlaceCards()); assertEquals(Collections.singletonList(nexus), traque.getPlaceCards());
} }
@Test
void testResolvePlace_archipelCantPickSurvivalCard() throws TException {
Game game = new Game(2, 1, planetExtension, board, room, gameClientHandler);
game.setTraqueCanPickSurvivalCards(false);
TAction chooseADefausseCard = new TAction(CHOOSE_CARD.toString(),
Collections.singletonList(new TPair(TPairType.CARD.toString(), NEXUS.toString())));
when(gameClientHandler.askAction(any(TAskAction.class)))
.thenReturn(chooseSecondPower)
.thenReturn(chooseADefausseCard);
Traque traque = (Traque) game.getPlayer(2);
List<PlaceCard> throwAwayCards = Arrays.asList(nexus, oasis, fjord, dome, labyrinthe);
traque.throwAwayPlaceCard(throwAwayCards);
traque.addPlaceCard(archipel);
traque.playPlaceCard(archipel);
PowerApplicator.resolvePlace(traque.getInGameId(), archipel, game);
//Verify that traque has only Nexus
assertEquals(Collections.singletonList(nexus), traque.getPlaceCards());
}
@Test @Test
void testResolvePlace_poleFirstPower() throws TException, NotFoundException { void testResolvePlace_poleFirstPower() throws TException, NotFoundException {
Game game = new Game(2, 1, planetExtension, board, room, gameClientHandler); Game game = new Game(2, 1, planetExtension, board, room, gameClientHandler);
...@@ -1533,6 +1560,64 @@ class PowerApplicatorTest { ...@@ -1533,6 +1560,64 @@ class PowerApplicatorTest {
assertEquals(Collections.singletonList(nexus), traque.getPlaceCards()); assertEquals(Collections.singletonList(nexus), traque.getPlaceCards());
} }
@Test
void testResolvePlace_fungiFistPowerCantPickSurvival() throws TException {
Game game = new Game(2, 1, planetExtension, board, room, gameClientHandler);
game.setTraqueCanPickSurvivalCards(false);
when(gameClientHandler.askAction(any(TAskAction.class)))
.thenReturn(chooseFirstPower);
Traque traque = (Traque) game.getPlayer(2);
traque.subWillingness(2);
List<PlaceCard> throwAwayCards = Arrays.asList(nexus, oasis, fjord, dome, labyrinthe);
traque.throwAwayPlaceCard(throwAwayCards);
traque.addPlaceCard(fungi);
traque.playPlaceCard(fungi);
PowerApplicator.resolvePlace(traque.getInGameId(), fungi, game);
assertTrue(game.getGameRoundVariables().isPawnWillingnessOnBoard());
game.nextRound();
assertEquals(2, traque.getNumberWillingness());
assertTrue(game.getGameRoundVariables().isPawnWillingnessOnBoard());
game.nextRound();
assertEquals(3, traque.getNumberWillingness());
assertFalse(game.getGameRoundVariables().isPawnWillingnessOnBoard());
}
@Test
void testResolvePlace_fungiSecondPowerCantPickSurvival() throws TException {
Game game = new Game(2, 1, planetExtension, board, room, gameClientHandler);
game.setTraqueCanPickSurvivalCards(false);
TAction chooseADefausseCard = new TAction(CHOOSE_CARD.toString(),
Collections.singletonList(new TPair(TPairType.CARD.toString(), NEXUS.toString())));
when(gameClientHandler.askAction(any(TAskAction.class)))
.thenReturn(chooseSecondPower)
.thenReturn(chooseADefausseCard);
Traque traque = (Traque) game.getPlayer(2);
List<PlaceCard> throwAwayCards = Arrays.asList(nexus, oasis, fjord, dome, labyrinthe);
traque.throwAwayPlaceCard(throwAwayCards);
traque.addPlaceCard(fungi);
traque.playPlaceCard(fungi);
PowerApplicator.resolvePlace(traque.getInGameId(), fungi, game);
//Verify that traque has only Nexus
assertEquals(Collections.singletonList(nexus), traque.getPlaceCards());
}
@Test @Test
void testResolvePlace_PortailFirstPower() throws TException { void testResolvePlace_PortailFirstPower() throws TException {
Game game = new Game(2, 1, planetExtension, board, room, gameClientHandler); Game game = new Game(2, 1, planetExtension, board, room, gameClientHandler);
...@@ -2163,6 +2248,23 @@ class PowerApplicatorTest { ...@@ -2163,6 +2248,23 @@ class PowerApplicatorTest {
assertTrue(planet.isBlockedPlace(antre)); assertTrue(planet.isBlockedPlace(antre));
} }
@Test
void testApplyPlayerCard_flashbackTrackingTrashEmpty() throws TException {
Game game = new Game(2, 1, planet, board, room, gameClientHandler);
TrackingCard desespoir = database.findTrackingCard(DESESPOIR.toString());
TrackingCard flashback = database.findTrackingCard(FLASHBACK.toString());
TrackingCard cataclysme = database.findTrackingCard(CATACLYSME.toString());
Creature creature= game.getCreature();
creature.getTrackingCardHand().clear();
creature.addTrackingCard(flashback);
assertTrue(game.playerPlayCard(creature.getInGameId(), flashback).state);
}
@Test @Test
void testApplyPlayerCard_gargantua() { void testApplyPlayerCard_gargantua() {
Game game = new Game(3, 1, planet, board, room, gameClientHandler); Game game = new Game(3, 1, planet, board, room, gameClientHandler);
...@@ -3010,16 +3112,18 @@ class PowerApplicatorTest { ...@@ -3010,16 +3112,18 @@ class PowerApplicatorTest {
@Test @Test
void testApplyPlayerCard_amplificateurWithExtension() { void testApplyPlayerCard_amplificateurWithExtension() {
Game game = new Game(4, 1, planetExtension, board, room, gameClientHandler); Game game = new Game(2, 1, planetExtension, board, room, gameClientHandler);
Traque traque = (Traque) game.getPlayer(2); Traque traque = (Traque) game.getPlayer(2);
planet.forceMovePlanetPawn(); planetExtension.forceMovePlanetPawn();
planet.forceMovePlanetPawn(); planetExtension.forceMovePlanetPawn();
PowerApplicator.applySurvivalCardPower(traque.getInGameId(), game, AMPLIFICATEUR); PowerApplicator.applySurvivalCardPower(traque.getInGameId(), game, AMPLIFICATEUR);
assertTrue(planet.planetPawnIsActive()); Score score = new Score(2);
score.moveBackCreature(1);
assertEquals(score, game.getBoard().getScore());
} }
@Test @Test
...@@ -3184,6 +3288,21 @@ class PowerApplicatorTest { ...@@ -3184,6 +3288,21 @@ class PowerApplicatorTest {
assertTrue(traque.getSurvivalCardsHand().contains(survivalCard)); assertTrue(traque.getSurvivalCardsHand().contains(survivalCard));
} }
@Test
void testApplyPlayerCard_equipementCantPickSurvivalCard() throws TException {
Game game = new Game(2, 1, planet, board, room, gameClientHandler);
game.getGameRoundVariables().setTraqueCanPickSurvivalCards(false);
SurvivalCard survivalCard = game.getSurvivalCardPioche().getCards().get(0);
Traque traque = (Traque) game.getPlayer(2);
PowerApplicator.applySurvivalCardPower(traque.getInGameId(), game, EQUIPEMENT);
assertFalse(traque.getSurvivalCardsHand().contains(survivalCard));
}
@Test @Test
void testApplyPlayerCard_equipementFirstPower() throws TException { void testApplyPlayerCard_equipementFirstPower() throws TException {
Game game = new Game(2, 1, planet, board, room, gameClientHandler); Game game = new Game(2, 1, planet, board, room, gameClientHandler);
......
Markdown is supported
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