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

Add application methods for SurvivalCards

parent a7b53fcf
......@@ -7,6 +7,7 @@ import fr.univnantes.alma.server.game.item.Reserve;
import fr.univnantes.alma.server.game.item.action.*;
import fr.univnantes.alma.server.game.item.board.Board;
import fr.univnantes.alma.server.game.item.card.*;
import fr.univnantes.alma.server.game.item.jeton.JetonCible;
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;
......@@ -499,6 +500,9 @@ public class Game implements GameInterface {
if(player.teamEqualsTo(TRAQUE) || ! state.equals(Phase.PHASE_2)){
response = new Response(false, "Only the Creature can played jeton and only in the PHASE_2");
}
else if(gameRoundVariables.refugeIsActive() && placedJeton.getJeton().getType().equals(CIBLE)) {
return new Response(false, "Can't play JetonCible when Refuge is active");
}
else{
response = creaturePlaceAJeton(creature, placedJeton);
}
......@@ -702,7 +706,10 @@ public class Game implements GameInterface {
* @return A Response
*/
public Response creaturePlayTrackingCard(Creature creature, TrackingCard trackingCard) {
if(creatureCanPlayThisTrackingCards(creature, trackingCard) &&
if(gameRoundVariables.refugeIsActive() && trackingCard.getJetons().contains(new JetonCible())) {
return new Response(false, "Unable to play this card when Refuge is active");
}
else if(creatureCanPlayThisTrackingCards(creature, trackingCard) &&
creature.playTrackingCard(trackingCard)) {
applyCreaturePlayTrackingCard(creature, trackingCard);
return new Response(true, "");
......@@ -756,6 +763,9 @@ public class Game implements GameInterface {
}
public boolean creatureCanPlayThisTrackingCards(Creature creature, TrackingCard trackingCard) {
if(! gameRoundVariables.canPLayTrackingCard()) {
return false;
}
//if the card doesn't apply himself in the same phase that it's played
if(playerCardsPlayedPhaseAndAppliedPhaseDifferent(trackingCard)) {
//true if the card can to be played or can to be applied
......@@ -769,6 +779,9 @@ public class Game implements GameInterface {
}
public boolean creatureCanPlayThisTrackingCards(Creature creature, List<TrackingCard> trackingCards) {
if(! gameRoundVariables.canPLayTrackingCard()) {
return false;
}
int numberCardPlayed = 0;
//Count the number of played cards
for(TrackingCard trackingCard : trackingCards) {
......@@ -1017,31 +1030,51 @@ public class Game implements GameInterface {
}
public void managePhase3() {
List<PlaceCard> placeCards;
List<PlaceCard> chosenPlaceCards;
for(Traque traque : traques) {
placeCards = new ArrayList<>(traque.getPlaceCardsPlayed());
//if player plays too many cards
if(placeCards.size() > traque.getMaxPlacesCardPlayable()) {
chosenPlaceCards = choosePlaceCardsAction(traque.getInGameId(), traque.getMaxPlacesCardPlayable(), placeCards);
for(PlaceCard placeCard : placeCards) {
//put back non-played cards in the hand
if(! chosenPlaceCards.contains(placeCard)) {
chosenPlaceCards = choosePlaceCardsToReveal(traque);
for(PlaceCard placeCard : chosenPlaceCards) {
resolvePlace(traque.getInGameId(), placeCard, this);
}
sendDescription();
}
}
private List<PlaceCard> choosePlaceCardsToReveal(Traque traque) {
List<PlaceCard> placeCardsPlayed = new ArrayList<>(traque.getPlaceCardsPlayed());
List<PlaceCard> chosenPlaceCards = placeCardsPlayed;
//if player plays too many cards
if(placeCardsPlayed.size() > traque.getMaxPlacesCardPlayable()) {
chosenPlaceCards = choosePlaceCardsAction(traque.getInGameId(), traque.getMaxPlacesCardPlayable(), placeCardsPlayed);
for(PlaceCard placeCard : placeCardsPlayed) {
if(! chosenPlaceCards.contains(placeCard)) {
if(gameRoundVariables.getPlayersWhoHavePlayCavale().contains(traque.getInGameId())) {
traque.throwAwayPlaceCard(placeCard);
}
else {
//put back non-played cards in the hand
traque.takeBackPlaceCard(placeCard);
}
}
}
//reveal all cards played
for(PlaceCard placeCard : placeCards) {
resolvePlace(traque.getInGameId(), placeCard, this);
}
sendDescription();
}
return chosenPlaceCards;
}
public void managePhase4() {
for(Traque traque : traques) {
traque.throwAwayPlaceCard();
if(gameRoundVariables.getPlayersWhoHavePlayCavale().contains(traque.getInGameId())
|| gameRoundVariables.getPlayersWhoHavePlayVolteFace().contains(traque.getInGameId())) {
traque.takeBackPlayedPlaceCards();
}
else if(gameRoundVariables.ralliementIsActive() && gameRoundVariables.getPlayerWhoHasCaughtByCreature().contains(traque.getInGameId())) {
List<PlaceCard> placeCardsWhereIsJetonCreature = planet.getPlaceCardsWhereJetonIs(JetonSymbol.CREATURE);
traque.takeBackPlaceCard(placeCardsWhereIsJetonCreature);
traque.throwAwayPlaceCard();
}
else{
traque.throwAwayPlaceCard();
}
}
creature.initializationJeton();
int numberTrackingCardToDraw = creature.getMaxTrackingCards() - creature.trackingCardHandSize();
......@@ -1052,6 +1085,9 @@ public class Game implements GameInterface {
public void nextRound() {
if(gameRoundVariables.rescuePawnCanMoveForward()){
board.moveForwardTraque(gameRoundVariables.getIncrementScoreTraque());
if(gameRoundVariables.isPawnWillingnessOnBoard()) {
useWillingnessOnBoard();
}
}
if(isFinish()) {
sendGameIsEnd();
......@@ -1114,7 +1150,22 @@ public class Game implements GameInterface {
default:
}
}
}
/**
* Use willingness on board and give one willingness to the traque with the least willingness
*/
private void useWillingnessOnBoard() {
gameRoundVariables.usePawnWillingnessOnBoard();
Traque traqueWithTheLeastOfWillingness = traques.get(0);
int minWillingness = traqueWithTheLeastOfWillingness.getNumberWillingness();
for(Traque traque : traques) {
if(traque.getNumberWillingness() < minWillingness) {
minWillingness = traque.getNumberWillingness();
traqueWithTheLeastOfWillingness = traque;
}
}
traqueWithTheLeastOfWillingness.addWillingness(1);
}
/*************************************
......
package fr.univnantes.alma.server.game;
import fr.univnantes.alma.server.game.item.planet.Place;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiConsumer;
public class GameRoundVariables {
//Numbers
private int numberPawnWillingnessOnBoard;
//Functions
private BiConsumer<Integer, Game> actionJetonCible;
private BiConsumer<Integer, Game> actionAdjacentPlaceJetonCible;
......@@ -19,11 +24,25 @@ public class GameRoundVariables {
private int idPlayerTargetByTrackingCardAnticipation;
private int idPlayerTargetByTrackingCardDomination;
private int idPlayerTargetByTrackingCardEpidemie;
private int idPlayerTargetBySurvivalCardMimetisme;
//Places
private Place targetByAlerte;
//Player ids list
private List<Integer> playerWhoHaveLostAllWillingness;
private List<Integer> playerWhoHaveResist;
private List<Integer> playerCaughtByCreature;
private List<Integer> playersWhoDodgeJetonArtemia;
private List<Integer> playersWhoDodgeJetonCreature;
private List<Integer> playersWhoDodgeJetonCible;
private List<Integer> playersWhoHavePlayCavale;
private List<Integer> playersWhoHavePlayDrone;
private List<Integer> playersWhoHavePlayMimetisme;
private List<Integer> playersWhoHavePlayPortail;
private List<Integer> playersWhoHavePlayRegeneration;
private List<Integer> playersWhoIsTargetRetraite;
private List<Integer> playersWhoHavePlayVolteFace;
//Conditions
private boolean traqueCanResist;
......@@ -43,8 +62,11 @@ public class GameRoundVariables {
private boolean jetonCibleBlockPlace;
private boolean jetonCibleBlockAdjacentPlace;
private boolean jetonCibleAdjacentPlaceMoveTraque;
private boolean ralliementIsActive;
private boolean refugeIsActive;
public GameRoundVariables() {
this.numberPawnWillingnessOnBoard = 0;
reset();
}
......@@ -63,11 +85,24 @@ public class GameRoundVariables {
this.idPlayerTargetByTrackingCardAnticipation = -1;
this.idPlayerTargetByTrackingCardDomination = -1;
this.idPlayerTargetByTrackingCardEpidemie = -1;
this.idPlayerTargetBySurvivalCardMimetisme = -1;
//Places
this.targetByAlerte = null;
//Player ids list
this.playerWhoHaveLostAllWillingness = new ArrayList<>();
this.playerWhoHaveResist = new ArrayList<>();
this.playerCaughtByCreature = new ArrayList<>();
this.playersWhoHavePlayCavale = new ArrayList<>();
this.playersWhoDodgeJetonArtemia = new ArrayList<>();
this.playersWhoHavePlayDrone = new ArrayList<>();
this.playersWhoDodgeJetonCreature = new ArrayList<>();
this.playersWhoHavePlayMimetisme = new ArrayList<>();
this.playersWhoHavePlayPortail = new ArrayList<>();
this.playersWhoHavePlayRegeneration = new ArrayList<>();
this.playersWhoDodgeJetonCible = new ArrayList<>();
this.playersWhoIsTargetRetraite = new ArrayList<>();
this.playersWhoHavePlayVolteFace = new ArrayList<>();
//Conditions
this.traqueCanResist = true;
......@@ -87,6 +122,25 @@ public class GameRoundVariables {
this.jetonCibleBlockPlace = false;
this.jetonCibleBlockAdjacentPlace = false;
this.jetonCibleAdjacentPlaceMoveTraque = false;
this.ralliementIsActive = false;
this.refugeIsActive = false;
}
//Number methods
public void addPawnWillingnessOnBoard(int number) {
numberPawnWillingnessOnBoard += number;
}
public boolean isPawnWillingnessOnBoard() {
return numberPawnWillingnessOnBoard > 0;
}
public void usePawnWillingnessOnBoard() {
if(numberPawnWillingnessOnBoard > 0) {
--numberPawnWillingnessOnBoard;
}
}
//Functions methods
......@@ -169,10 +223,6 @@ public class GameRoundVariables {
return idPlayerTargetByTrackingCardEpidemie != -1;
}
public boolean playerIsTargetBySurvivalCardMimetisme() {
return idPlayerTargetBySurvivalCardMimetisme != -1;
}
public int getIdPlayerTargetByTrackingCardDomination() {
return idPlayerTargetByTrackingCardDomination;
}
......@@ -189,12 +239,17 @@ public class GameRoundVariables {
this.idPlayerTargetByTrackingCardEpidemie = idPlayerTargetByTrackingCardEpidemie;
}
public int getIdPlayerTargetBySurvivalCardMimetisme() {
return idPlayerTargetBySurvivalCardMimetisme;
//Places
public boolean alerteIsActive() {
return targetByAlerte != null;
}
public Place getTargetByAlerte() {
return targetByAlerte;
}
public void setIdPlayerTargetBySurvivalCardMimetisme(int idPlayerTargetBySurvivalCardMimetisme) {
this.idPlayerTargetBySurvivalCardMimetisme = idPlayerTargetBySurvivalCardMimetisme;
public void setTargetByAlerte(Place targetByAlerte) {
this.targetByAlerte = targetByAlerte;
}
//Player ids list
......@@ -215,6 +270,110 @@ public class GameRoundVariables {
playerWhoHaveResist.add(idPlayer);
}
public List<Integer> getPlayerWhoHasCaughtByCreature() {
return playerCaughtByCreature;
}
public void addPlayerWhoHasCaughtByCreature(Integer idPlayer) {
playerCaughtByCreature.add(idPlayer);
}
public List<Integer> getPlayersWhoHavePlayCavale() {
return playersWhoHavePlayCavale;
}
public void addPlayerWhoHavePlayCavale(int idPlayer) {
this.playersWhoHavePlayCavale.add(idPlayer);
}
public List<Integer> getPlayersWhoDodgeJetonArtemia() {
return playersWhoDodgeJetonArtemia;
}
public void addPlayersWhoDodgeJetonArtemia(int idPlayer) {
this.playersWhoDodgeJetonArtemia.add(idPlayer);
}
public List<Integer> getPlayersWhoHavePlayDrone() {
return playersWhoHavePlayDrone;
}
public void addPlayersWhoHavePlayDrone(int idPlayer) {
this.playersWhoHavePlayDrone.add(idPlayer);
}
public List<Integer> getPlayersWhoDodgeJetonCreature() {
return playersWhoDodgeJetonCreature;
}
public void addPlayersWhoDodgeJetonCreature(int idPlayer) {
this.playersWhoDodgeJetonCreature.add(idPlayer);
}
public List<Integer> getPlayersWhoHavePlayMimetisme() {
return playersWhoHavePlayMimetisme;
}
public void addPlayersWhoHavePlayMimetisme(int idPlayer) {
this.playersWhoHavePlayMimetisme.add(idPlayer);
}
public List<Integer> getPlayersWhoHavePlayPortail() {
return playersWhoHavePlayPortail;
}
public void addPlayersWhoHavePlayPortail(int idPlayer) {
this.playersWhoHavePlayPortail.add(idPlayer);
}
public List<Integer> getPlayersWhoHavePlayRegeneration() {
return playersWhoHavePlayRegeneration;
}
public void addPlayersWhoHavePlayRegeneration(int idPlayer) {
this.playersWhoHavePlayRegeneration.add(idPlayer);
}
public List<Integer> getPlayersWhoDodgeJetonCible() {
return playersWhoDodgeJetonCible;
}
public void addPlayersWhoDodgeJetonCible(int idPlayer) {
this.playersWhoDodgeJetonCible.add(idPlayer);
}
public List<Integer> getPlayersWhoIsTargetRetraite() {
return playersWhoIsTargetRetraite;
}
public void addPlayersWhoIsTargetByRetraite(int idPlayer) {
this.playersWhoIsTargetRetraite.add(idPlayer);
}
public List<Integer> getPlayersWhoHavePlayVolteFace() {
return playersWhoHavePlayVolteFace;
}
public void addPlayersWhoHavePlayVolteFace(int idPlayer) {
this.playersWhoHavePlayVolteFace.add(idPlayer);
}
public boolean ralliementIsActive() {
return ralliementIsActive;
}
public void setRalliementIsActive(boolean ralliementIsActive) {
this.ralliementIsActive = ralliementIsActive;
}
public boolean refugeIsActive() {
return refugeIsActive;
}
public void setRefugeIsActive(boolean refugeIsActive) {
this.refugeIsActive = refugeIsActive;
}
//Conditions
public boolean isJetonArtemiaIsActive() {
return jetonArtemiaIsActive;
......
package fr.univnantes.alma.server.game.item.planet;
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.jeton.*;
import fr.univnantes.alma.server.game.utilitary.Pair;
import java.util.*;
......@@ -17,6 +19,7 @@ public class Planet {
private Map<Place, List<Jeton>> mapPlaceToJetons;
private Map<Place, Boolean> blockedPlaces;
private Map<Place, SurvivalCard> placeSurvivalCardMap;
private int numberMovesInRound;
private PlaceDistribution placeDistribution;
private PlanetPawn planetPawn;
......@@ -24,11 +27,12 @@ public class Planet {
public Planet(List<PlaceCard> placeCards){
this.mapPlaceToJetons = new EnumMap<>(Place.class);
this.blockedPlaces = new HashMap<>();
this.blockedPlaces = new EnumMap<>(Place.class);
this.numberMovesInRound = 0;
this.placeDistribution = new PlaceDistribution(placeCards);
this.planetPawn = this.placeDistribution.createPawn();
this.epaveUsedInTheRound = false;
this.placeSurvivalCardMap = new EnumMap<>(Place.class);
}
public PlaceDistribution getPlaceDistribution() {
......@@ -159,6 +163,10 @@ public class Planet {
}
}
public void forceMovePlanetPawn(){
planetPawn.nextState();
}
public void moveBackPlanetPawn(){
if(planetPawn.getType().equals(PawnType.SHIELD)) {
planetPawn.previousState();
......@@ -210,6 +218,38 @@ public class Planet {
return placeDistribution.placeToPlaceCard(place);
}
public boolean isASurvivalCardOnPlace(Place place) {
return placeSurvivalCardMap.containsKey(place);
}
public boolean isASurvivalCardOnPlace(PlaceCard placeCard) {
return isASurvivalCardOnPlace(placeDistribution.placeCardToPlace(placeCard));
}
public SurvivalCard takeSurvivalCardOnPlace(Place place) {
SurvivalCard survivalCard = placeSurvivalCardMap.getOrDefault(place, null);
if(survivalCard != null) {
placeSurvivalCardMap.remove(place);
}
return survivalCard;
}
public SurvivalCard takeSurvivalCardOnPlace(PlaceCard placeCard) {
return takeSurvivalCardOnPlace(placeDistribution.placeCardToPlace(placeCard));
}
public void putSurvivalCardOnPlace(Pair<Place, SurvivalCard> pair) {
placeSurvivalCardMap.putIfAbsent(pair.getKey(), pair.getValue());
}
public void putSurvivalCardOnPlace(List<Pair<Place, SurvivalCard>> pairs) {
for(Pair<Place, SurvivalCard> pair : pairs) {
putSurvivalCardOnPlace(pair);
}
}
/********************************
* Auxiliaries methods
* *****************************/
......
......@@ -216,6 +216,10 @@ public class Traque extends Player {
return hand.takeBackPlaceCard(card);
}
public void takeBackPlayedPlaceCards() {
hand.takeBackPlayedPlaceCards();
}
/**
* Put back the cards in the hand
* @param cards The cards
......
......@@ -137,6 +137,10 @@ public class HandTraque {
return placeCards.takeBack(cards);
}
public void takeBackPlayedPlaceCards() {
placeCards.takeBackPlayedPlaceCards();
}
/**
* Move all the cards from defausse to the hand
*/
......
......@@ -129,6 +129,11 @@ public class PlaceCardDeck {
defausse.clear();
}
public void takeBackPlayedPlaceCards() {
placeCards.addAll(playedCards);
playedCards = new ArrayList<>();
}
public boolean add(PlaceCard card){
if(!placeCards.contains(card) && !defausse.contains(card)){
return placeCards.add(card);
......
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