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

Add tests for the 10 PlaceCards's powers ; Correction of some bugs

parent 2595c98b
......@@ -29,14 +29,19 @@ public class DatabaseStub implements NotAloneDatabase {
placeCardMap.put("ANTRE", new PlaceCard(CardName.ANTRE, "Antre", "Lorem ipsum",1, "/image.png", "#4466bb"));
placeCardMap.put("NEXUS", new PlaceCard(CardName.NEXUS, "Nexus", "Lorem ipsum", 1, "/image.png", "#4466bb"));
placeCardMap.put("JUNGLE", new PlaceCard(CardName.JUNGLE, "Jungle", "Lorem ipsum", 2, "/image.png", "#4466bb"));
placeCardMap.put("OASIS", new PlaceCard(CardName.OASIS, "Oasis", "Lorem ipsum", 2, "/image.png", "#4466bb"));
placeCardMap.put("RIVIERE", new PlaceCard(CardName.RIVIERE, "Rivière", "Lorem ipsum", 3, "/image.png", "#4466bb"));
placeCardMap.put("FJORD", new PlaceCard(CardName.FJORD, "Fjord", "Lorem ipsum", 3, "/image.png", "#4466bb"));
placeCardMap.put("DOME", new PlaceCard(CardName.DOME,"Dôme", "Lorem ipsum", 4, "/image.png", "#4466bb"));
placeCardMap.put("PLAGE", new PlaceCard(CardName.PLAGE,"Plage", "Lorem ipsum", 4, "/image.png", "#4466bb"));
placeCardMap.put("ROVER", new PlaceCard(CardName.ROVER,"Rover", "Lorem ipsum", 5, "/image.png", "#4466bb"));
placeCardMap.put("LABYRINTHE", new PlaceCard(CardName.LABYRINTHE,"Labyrinthe", "Lorem ipsum", 5, "/image.png", "#4466bb"));
placeCardMap.put("MANGROVE", new PlaceCard(CardName.MANGROVE, "Mangrove", "Lorem ipsum", 6, "/image.png", "#4466bb"));
placeCardMap.put("MARAIS", new PlaceCard(CardName.MARAIS, "Marais", "Lorem ipsum", 6, "/image.png", "#4466bb"));
placeCardMap.put("ABRI", new PlaceCard(CardName.ABRI, "Abri", "Lorem ipsum", 7, "/image.png", "#4466bb"));
placeCardMap.put("ARCHIPEL", new PlaceCard(CardName.ARCHIPEL, "Archipel", "Lorem ipsum", 7, "/image.png", "#4466bb"));
placeCardMap.put("EPAVE", new PlaceCard(CardName.EPAVE, "Epave", "Lorem ipsum", 8, "/image.png", "#4466bb"));
placeCardMap.put("POLE", new PlaceCard(CardName.POLE, "Pole", "Lorem ipsum", 8, "/image.png", "#4466bb"));
placeCardMap.put("FUNGI", new PlaceCard(CardName.FUNGI, "Fungi", "Lorem ipsum", 9, "/image.png", "#4466bb"));
placeCardMap.put("SOURCE", new PlaceCard(CardName.SOURCE, "Source", "Lorem ipsum", 9, "/image.png", "#4466bb"));
placeCardMap.put("PORTAIL", new PlaceCard(CardName.PORTAIL, "Portail", "Lorem ipsum", 10, "/image.png", "#4466bb"));
......
......@@ -1050,7 +1050,8 @@ public class Game implements GameInterface {
chosenPlaceCards = choosePlaceCardsAction(traque.getInGameId(), traque.getMaxPlacesCardPlayable(), placeCardsPlayed);
for(PlaceCard placeCard : placeCardsPlayed) {
if(! chosenPlaceCards.contains(placeCard)) {
if(gameRoundVariables.getPlayersWhoHavePlayCavale().contains(traque.getInGameId())) {
if(gameRoundVariables.getPlayersWhoHavePlayCavale().contains(traque.getInGameId())
|| gameRoundVariables.getplayersWhoUseFjordInPreviousRound().contains(traque.getInGameId())) {
traque.throwAwayPlaceCard(placeCard);
}
else {
......@@ -1096,6 +1097,7 @@ public class Game implements GameInterface {
}
else{
gameRoundVariables.reset();
planet.reset();
for(Traque t : traques) {
t.reset();
}
......@@ -1149,6 +1151,8 @@ public class Game implements GameInterface {
traque.setMaxPlacesCardChoosable(tmp);
traque.setPlaceCardsVisible(((int)power.getModifiedValue()));
break;
case USE_FJORD_IN_PREVIOUS_ROUND:
gameRoundVariables.addplayersWhoUseFjordInPreviousRound(traque.getInGameId());
default:
}
}
......
......@@ -43,6 +43,7 @@ public class GameRoundVariables {
private List<Integer> playersWhoHavePlayRegeneration;
private List<Integer> playersWhoIsTargetRetraite;
private List<Integer> playersWhoHavePlayVolteFace;
private List<Integer> playersWhoUseFjordInPreviousRound;
//Conditions
private boolean traqueCanResist;
......@@ -103,6 +104,7 @@ public class GameRoundVariables {
this.playersWhoDodgeJetonCible = new ArrayList<>();
this.playersWhoIsTargetRetraite = new ArrayList<>();
this.playersWhoHavePlayVolteFace = new ArrayList<>();
this.playersWhoUseFjordInPreviousRound = new ArrayList<>();
//Conditions
this.traqueCanResist = true;
......@@ -358,6 +360,14 @@ public class GameRoundVariables {
this.playersWhoHavePlayVolteFace.add(idPlayer);
}
public List<Integer> getplayersWhoUseFjordInPreviousRound() {
return playersWhoUseFjordInPreviousRound;
}
public void addplayersWhoUseFjordInPreviousRound(int idPlayer) {
this.playersWhoUseFjordInPreviousRound.add(idPlayer);
}
public boolean ralliementIsActive() {
return ralliementIsActive;
}
......
......@@ -754,8 +754,9 @@ public class PowerApplicator {
Traque traque = (Traque) player;
traque.takeBackPlaceCard(database.findPlaceCard(OASIS.toString()));
int willingnessMissing = traque.getMaxWillingness() - traque.getNumberWillingness();
if(! game.getGameRoundVariables().numberMaxPlaceCardsGetByPlacePowerIsLimited()
|| game.getGameRoundVariables().getNumberMaxPlaceCardsGetByPlacePower() >= 2){
boolean maxPlaceCardsLowerThanWillingnessMissing = ! game.getGameRoundVariables().numberMaxPlaceCardsGetByPlacePowerIsLimited()
|| game.getGameRoundVariables().getNumberMaxPlaceCardsGetByPlacePower() >= willingnessMissing;
if(willingnessMissing > 0 && maxPlaceCardsLowerThanWillingnessMissing){
takeBackCardsFromDefausse(idPlayer, game, willingnessMissing);
}
}
......@@ -770,6 +771,8 @@ public class PowerApplicator {
if (idPower == 0) {
Power power = new PowerModificator(idPlayer, PowerModificatorType.CHOOSABLE_VISIBLE_ADDITIONAL_PLACE_CARD, 1);
game.addPowerForNextRound(power);
power = new PowerModificator(idPlayer, PowerModificatorType.USE_FJORD_IN_PREVIOUS_ROUND, null);
game.addPowerForNextRound(power);
}
else {
takeBackCardsFromDefausse(idPlayer, game, 1);
......@@ -801,11 +804,11 @@ public class PowerApplicator {
//there is hidden cards and revealed card (between 6-10)
if(planet.isHiddenCards() && planet.getHiddenCards().size() < 5) {
applyPlaceLabyrintheRevealedAndHidden(idPlayer, game);
applyPlaceLabyrintheNotAllRevealed(idPlayer, game);
}
//place 6-10 are all hidden
else if(planet.isHiddenCards()) {
applyPlaceLabyrintheAllHidden(idPlayer, game);
applyPlaceLabyrintheNotAllRevealed(idPlayer, game);
}
//all places are revealed
else{
......@@ -813,24 +816,7 @@ public class PowerApplicator {
}
}
private static void applyPlaceLabyrintheRevealedAndHidden(int idPlayer, Game game) {
List<String> powersDescription = Arrays.asList("Révéler un Lieu : retourner, face visible, une des 5 cartes Lieu 6 à 10 de la planète Artemia et activer son pouvoir", "Prendre une carte Lieu de la réserve", "Récupérez 1 carte de votre défausse");
int idPower = game.choosePower(idPlayer, powersDescription);
//revealed a place
if (idPower == 0) {
revealAHiddenPlaceAndApplyItsPower(idPlayer, game);
}
//take a non-revealed or a revealed place
else if(idPower == 1){
chooseCardFromReserve(idPlayer, game);
}
else {
takeBackCardsFromDefausse(idPlayer, game, 1);
}
}
private static void applyPlaceLabyrintheAllHidden(int idPlayer, Game game) {
private static void applyPlaceLabyrintheNotAllRevealed(int idPlayer, Game game) {
List<String> powersDescription = Arrays.asList("Révéler un Lieu : retourner, face visible, une des 5 cartes Lieu 6 à 10 de la planète Artemia et activer son pouvoir","Prendre une carte Lieu de la réserve", "Récupérez 1 carte de votre défausse");
int idPower = game.choosePower(idPlayer, powersDescription);
//reveal a place
......@@ -932,7 +918,7 @@ public class PowerApplicator {
Player player = game.getPlayer(idPlayer);
checkPlayerIsNotCreature(player);
Traque traque = (Traque) player;
traque.takeBackPlaceCard(database.findPlaceCard(PORTAIL.toString()));
traque.throwAwayPlaceCard(database.findPlaceCard(PORTAIL.toString()));
playNewPlaceCard(idPlayer, game);
}
else {
......@@ -1242,7 +1228,7 @@ public class PowerApplicator {
}
}
else {
planet.forceMovePlanetPawn();
planet.movePlanetPawn();
if(planet.planetPawnIsActive()) {
applyShieldPawn(game);
}
......@@ -1426,7 +1412,7 @@ public class PowerApplicator {
List<PlaceCard> placeCards = traque.getPlaceCards();
PlaceCard playedCard = game.choosePlaceCardsAction(idPlayer, 1, placeCards).get(0);
traque.playPlaceCard(playedCard);
applyPlaceCardPower(idPlayer, game, playedCard.getCardName());
resolvePlace(idPlayer, playedCard, game);
}
/**
......
......@@ -2,20 +2,25 @@ package fr.univnantes.alma.server.game.item.planet;
public class BeaconPawn extends PlanetPawn{
private boolean state;
private int state;
public BeaconPawn(){
state = false;
state = 0;
}
@Override
public void nextState() {
state = !state;
if(state < 2) {
++state;
}
else{
state = 1;
}
}
@Override
public boolean isActive() {
return state;
return state == 2;
}
@Override
......@@ -24,7 +29,7 @@ public class BeaconPawn extends PlanetPawn{
}
@Override
public int maxMovesInRound() {
public int maxMovesInOneRound() {
return 1;
}
}
......@@ -71,13 +71,14 @@ public class PlaceDistribution {
for(int number = 1 ; number <= 5 ; ++number){
mapPlaceCardToPlace.put(mapCardNumberToPlaceCard.get(number), numberToPlace(number));
}
List<Integer> numbers = Arrays.asList(6,7,8,9,10);
List<Integer> placeCardsOrders = Arrays.asList(6,7,8,9,10);
//if card Labyrinthe is used, we randomize the places
if(useCardLabyrinthe()){
shuffle(numbers);
shuffle(placeCardsOrders);
}
for(int number : numbers){
mapPlaceCardToPlace.put(mapCardNumberToPlaceCard.get(number), numberToPlace(number));
Iterator<Integer> iteratorPlaceCardsNumber = placeCardsOrders.iterator();
for(int i = 6 ; i <= 10 ; ++i){
mapPlaceCardToPlace.put(mapCardNumberToPlaceCard.get(iteratorPlaceCardsNumber.next()), numberToPlace(i));
}
}
......@@ -216,7 +217,7 @@ public class PlaceDistribution {
}
public void revealPlace(Place place) {
placeIsHidden.put(place, true);
placeIsHidden.put(place, false);
}
public void revealPlace(PlaceCard placeCard) {
......
......@@ -20,7 +20,7 @@ public class Planet {
private Map<Place, List<Jeton>> mapPlaceToJetons;
private Map<Place, Boolean> blockedPlaces;
private Map<Place, SurvivalCard> placeSurvivalCardMap;
private int numberMovesInRound;
private int numberMovesAllowInRound;
private PlaceDistribution placeDistribution;
private PlanetPawn planetPawn;
private boolean epaveUsedInTheRound;
......@@ -28,9 +28,9 @@ public class Planet {
public Planet(List<PlaceCard> placeCards){
this.mapPlaceToJetons = new EnumMap<>(Place.class);
this.blockedPlaces = new EnumMap<>(Place.class);
this.numberMovesInRound = 0;
this.placeDistribution = new PlaceDistribution(placeCards);
this.planetPawn = this.placeDistribution.createPawn();
this.numberMovesAllowInRound = planetPawn.maxMovesInOneRound();
this.epaveUsedInTheRound = false;
this.placeSurvivalCardMap = new EnumMap<>(Place.class);
}
......@@ -39,11 +39,12 @@ public class Planet {
return placeDistribution;
}
public void clear(){
public void reset(){
mapPlaceToJetons = new EnumMap<>(Place.class);
blockedPlaces = new HashMap<>();
numberMovesInRound = 0;
epaveUsedInTheRound = false;
resetPawn();
this.numberMovesAllowInRound = planetPawn.maxMovesInOneRound();
}
public boolean placeJeton(PlacedJeton placedJeton) {
......@@ -149,13 +150,13 @@ public class Planet {
}
public boolean canMovePlanetPawn() {
return numberMovesInRound < planetPawn.maxMovesInRound();
return numberMovesAllowInRound > 0;
}
public boolean movePlanetPawn(){
if(canMovePlanetPawn()){
planetPawn.nextState();
++numberMovesInRound;
--numberMovesAllowInRound;
return true;
}
else{
......@@ -170,6 +171,7 @@ public class Planet {
public void moveBackPlanetPawn(){
if(planetPawn.getType().equals(PawnType.SHIELD)) {
planetPawn.previousState();
++numberMovesAllowInRound;
}
}
......
......@@ -12,7 +12,7 @@ public abstract class PlanetPawn {
public abstract boolean isActive();
public abstract int maxMovesInRound();
public abstract int maxMovesInOneRound();
public void reset(){}
}
......@@ -5,15 +5,20 @@ import static fr.univnantes.alma.server.game.item.planet.Planet.DOME_NUMBER;
public class ShieldPawn extends PlanetPawn{
private int location;
private boolean hasReachDome;
public ShieldPawn() {
location = 1;
hasReachDome = false;
}
@Override
public void nextState() {
location = location == DOME_NUMBER ? 1 : location + 1;
++location;
if(location == DOME_NUMBER) {
hasReachDome = true;
location = 1;
}
}
@Override
......@@ -23,7 +28,7 @@ public class ShieldPawn extends PlanetPawn{
@Override
public boolean isActive() {
return location == DOME_NUMBER;
return hasReachDome;
}
@Override
......@@ -32,12 +37,14 @@ public class ShieldPawn extends PlanetPawn{
}
@Override
public int maxMovesInRound() {
return DOME_NUMBER - location;
public int maxMovesInOneRound() {
//DOME_NUMBER - location to reach the DOME
//DOME_NUMBER - 2 to reach the place before the DOME
return DOME_NUMBER - location + DOME_NUMBER -2;
}
@Override
public void reset() {
location = 1;
hasReachDome = false;
}
}
package fr.univnantes.alma.server.game.item.power.modificator;
public enum PowerModificatorType {
CHOOSABLE_PLACE_CARD, PLAYABLE_PLACE_CARD, CHOOSABLE_VISIBLE_ADDITIONAL_PLACE_CARD, PLAYABLE_TRACKING_CARD
CHOOSABLE_PLACE_CARD, PLAYABLE_PLACE_CARD, CHOOSABLE_VISIBLE_ADDITIONAL_PLACE_CARD, PLAYABLE_TRACKING_CARD,
USE_FJORD_IN_PREVIOUS_ROUND
}
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