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

Defines all the places power ; Some add in server classes ; Upgrade Power

parent e8d06e8c
......@@ -8,10 +8,7 @@ import fr.univnantes.alma.game.item.card.SurvivalCard;
import fr.univnantes.alma.game.item.card.TrackingCard;
import fr.univnantes.alma.game.item.power.PowerType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
public class DatabaseStub implements NotAloneDatabase {
......@@ -133,5 +130,28 @@ public class DatabaseStub implements NotAloneDatabase {
return tracking;
}
@Override
public List<String> findPowersDescription(String cardNameString) {
CardName cardName = null;
try {
cardName = CardName.valueOf(cardNameString);
}
catch (Exception e) {
throw new IllegalArgumentException("Invalid name of card");
}
return findPowersDescription(cardName);
}
@Override
public List<String> findPowersDescription(CardName cardName) {
List<String> powersDescription = new ArrayList<>();
switch (cardName) {
case ANTRE:
powersDescription = Arrays.asList("Reprenez en main les cartes Lieu de votre défausse (mais pas celui-ci)", "Copiez le pouvoir d’un Lieu où le jeton Créature se trouve", "Reprenez en main une carte Lieu de votre défausse");
break;
default:
}
return powersDescription;
}
}
package fr.univnantes.alma.data;
import fr.univnantes.alma.data.item.User;
import fr.univnantes.alma.game.item.card.Card;
import fr.univnantes.alma.game.item.card.PlaceCard;
import fr.univnantes.alma.game.item.card.SurvivalCard;
import fr.univnantes.alma.game.item.card.TrackingCard;
import fr.univnantes.alma.game.item.card.*;
import java.util.List;
......@@ -31,4 +28,8 @@ public interface NotAloneDatabase {
public List<TrackingCard> findAllTrackingCard();
public List<String> findPowersDescription(String cardNameString);
public List<String> findPowersDescription(CardName cardName);
}
......@@ -16,9 +16,11 @@ import fr.univnantes.alma.game.item.player.Creature;
import fr.univnantes.alma.game.item.player.Player;
import fr.univnantes.alma.game.item.player.Traque;
import fr.univnantes.alma.game.item.power.Power;
import fr.univnantes.alma.game.item.power.PowerType;
import fr.univnantes.alma.game.item.power.modificator.PowerModificator;
import fr.univnantes.alma.game.item.power.modificator.PowerModificatorType;
import fr.univnantes.alma.game.utilitary.Pair;
import fr.univnantes.alma.thrift.Response;
import fr.univnantes.alma.thrift.TAction;
import fr.univnantes.alma.thrift.TAskAction;
import fr.univnantes.alma.thrift.TPair;
......@@ -26,7 +28,7 @@ import java.util.*;
import java.util.stream.Collectors;
import static fr.univnantes.alma.game.PowerApplicator.applyPlayerCard;
import static fr.univnantes.alma.game.PowerApplicator.revealPlace;
import static fr.univnantes.alma.game.PowerApplicator.resolvePlace;
import static fr.univnantes.alma.game.item.action.ActionType.*;
import static fr.univnantes.alma.game.item.jeton.JetonSymbol.ARTEMIA;
import static fr.univnantes.alma.game.item.jeton.JetonSymbol.CIBLE;
......@@ -213,6 +215,8 @@ public class Game implements GameInterface {
return playersMap;
}
public Player getPlayer(int idPlayer) {return playersMap.get(idPlayer);}
public Phase getState() {
return state;
}
......@@ -221,6 +225,26 @@ public class Game implements GameInterface {
return room;
}
public boolean isJetonArtemiaIsActive() {
return gameRoundVariables.isJetonArtemiaIsActive();
}
public void disableJetonArtemia() {
gameRoundVariables.disableJetonArtemia();
}
public void enableJetonArtemia() {
gameRoundVariables.enableJetonArtemia();
}
/***************************
* Setters and modifiers
**************************/
public void addPowerForNextRound(Power power) {
this.nextRoundPowers.add(power);
}
/*************************************
* Game Interface Methods
***********************************/
......@@ -637,7 +661,7 @@ public class Game implements GameInterface {
*/
public Response traquePlayPlaceCard(Traque traque, PlaceCard placeCard) {
if(traque.placeCardPlayedSize() < traque.getMaxPlacesCardChoosable() &&
traque.playPlaceCard(placeCard)) {
traque.playPlaceCard(placeCard) && planet.isRevealedPlace(placeCard)) {
return new Response(true, "");
}
else{
......@@ -776,7 +800,7 @@ public class Game implements GameInterface {
}
//reveal all cards played
for(PlaceCard placeCard : placeCards) {
revealPlace(traque.getInGameId(), placeCard, this);
resolvePlace(traque.getInGameId(), placeCard, this);
}
sendDescription();
}
......@@ -784,7 +808,7 @@ public class Game implements GameInterface {
public void managePhase4() {
for(Traque traque : traques) {
traque.throwAwayPlaceCard(traque.getPlaceCardsPlayed());
traque.throwAwayPlaceCard();
}
creature.initializationJeton();
int numberTrackingCardToDraw = creature.getMaxTrackingCards() - creature.trackingCardHandSize();
......@@ -800,9 +824,48 @@ public class Game implements GameInterface {
else{
gameRoundVariables.reset();
for(Traque t : traques) {
t.getRights().reset();
t.reset();
}
creature.getRights().reset();
applyNextRoundPowers();
}
}
/**
* Apply the next round powers and clear them
*/
private void applyNextRoundPowers() {
for(Power power : nextRoundPowers) {
if(power.getType().equals(PowerType.MODIFICATOR)) {
applyModificatorPower((PowerModificator) power);
}
}
nextRoundPowers = new ArrayList<>();
}
/**
* Apply a power modificator
*/
private void applyModificatorPower(PowerModificator power) {
PowerModificatorType type = power.getModificatorType();
Player player = getPlayer(power.getInGameIdPlayer());
if(player.getTeam().equals(CREATURE)) {
return;
}
Traque traque = (Traque) player;
switch (type) {
case PLAYABLE_PLACE_CARD:
traque.setMaxPlacesCardPlayable((int)power.getModifiedValue());
break;
case CHOOSABLE_PLACE_CARD:
traque.setMaxPlacesCardChoosable((int)power.getModifiedValue());
break;
case CHOOSABLE_VISIBLE_ADDITIONAL_PLACE_CARD:
int tmp = traque.getMaxPlacesCardChoosable() + ((int)power.getModifiedValue());
traque.setMaxPlacesCardChoosable(tmp);
traque.setPlaceCardsVisible(((int)power.getModifiedValue()));
break;
default:
}
}
......@@ -829,6 +892,25 @@ public class Game implements GameInterface {
return cards;
}
public List<SurvivalCard> chooseSurvivalCardsAction(int idPlayer, int max, List<SurvivalCard> survivalCards) {
List<Card> cardList = new ArrayList<>(survivalCards);
List<SurvivalCard> cards = null;
boolean validChoice = false;
do {
try {
cards = chooseCardsAction(idPlayer, max, cardList).stream()
.map(c -> (SurvivalCard) c)
.collect(Collectors.toList());
validChoice = true;
}
catch (Exception e){
//Bad Card type
}
}
while (!validChoice);
return cards;
}
public List<Card> chooseCardsAction(int idPlayer, int max, List<Card> cardsToChoose) {
TAskAction askAction = createTActionForChooseCardsAction(max, cardsToChoose);
List<Card> cards = new ArrayList<>();
......@@ -895,7 +977,7 @@ public class Game implements GameInterface {
if(action.getActionType().equals(TARGET_PLAYER)) {
idTargetPlayer = ((ActionMovePlayer) action).getIdPlayer();
}
} while(! playersIdList.contains(idTargetPlayer) && creature.getInGameId() != idTargetPlayer);
} while(! playersIdList.contains(idTargetPlayer) && creature.getInGameId() == idTargetPlayer);
return idTargetPlayer;
}
......@@ -922,19 +1004,76 @@ public class Game implements GameInterface {
return places;
}
public Pair<Player, Place> movePlayer(int idPlayer) {
//TODO
return null;
public Pair<Integer, Place> movePlayer(int idPlayer) {
String message = "Move one traque";
TAskAction askAction = new TAskAction(MOVE_PLAYER.toString(), message, new ArrayList<>());
int idTargetPlayer = -1;
Place place = null;
Action action;
ActionMovePlayer actionMovePlayer;
Set<Integer> playersIdList = playersMap.keySet();
do{
action = askAction(idPlayer, askAction);
if(action.getActionType().equals(MOVE_PLAYER)) {
actionMovePlayer = (ActionMovePlayer) action;
idTargetPlayer = actionMovePlayer.getIdPlayer();
place = actionMovePlayer.getPlace();
}
} while(! playersIdList.contains(idTargetPlayer) && creature.getInGameId() == idTargetPlayer);
return new Pair<>(idPlayer, place);
}
public Pair<JetonSymbol, JetonSymbol> swapJetons(int idPlayer) {
//TODO
return null;
String message = "Move one traque";
TAskAction askAction = new TAskAction(MOVE_PLAYER.toString(), message, new ArrayList<>());
JetonSymbol symbol1 = null;
JetonSymbol symbol2 = null;
Action action;
ActionSwapJeton actionSwapJeton;
do{
action = askAction(idPlayer, askAction);
if(action.getActionType().equals(SWAP_JETONS)) {
actionSwapJeton = (ActionSwapJeton) action;
symbol1 = actionSwapJeton.getJeton1();
symbol2 = actionSwapJeton.getJeton2();
}
} while(symbol1 == null || symbol2 == null || symbol1 == symbol2);
return new Pair<>(symbol1, symbol2);
}
public Map<CardName, Place> associateCardNamesToPlaces(int idPlayer, List<Card> cards) {
//TODO
return null;
public Map<Card, Place> associateCardNamesToPlaces(int idPlayer, List<Card> cardsToAssociate) {
TAskAction askAction = createTActionForAssociateCardNamesToPlaces(cardsToAssociate);
Map<Card, Place> cardNamePlaceMap = new HashMap<>();
Map<CardName, Place> auxiliaryMap;
Action action;
do{
action = askAction(idPlayer, askAction);
if(action.getActionType().equals(ActionType.ASSOCIATE_CARDNAMES_TO_PLACES)) {
auxiliaryMap = ((ActionAssociateCardNamesToPlaces) action).getCardNamePlaceMap();
cardNamePlaceMap = computeMapCardToPlaceFromMapCardNamesToPlace(auxiliaryMap, cardsToAssociate);
}
} while (cardNamePlaceMap.size() != cardsToAssociate.size());
return cardNamePlaceMap;
}
private TAskAction createTActionForAssociateCardNamesToPlaces(List<Card> cardsToAssociate){
List<TPair> params = new ArrayList<>();
for(int i = 0 ; i < cardsToAssociate.size() ; ++i) {
params.add(new TPair("" + (i+1), cardsToAssociate.get(i).getCardName().toString()));
}
String message = "Place the cards";
return new TAskAction(ASSOCIATE_CARDNAMES_TO_PLACES.toString(), message, params);
}
private Map<Card, Place> computeMapCardToPlaceFromMapCardNamesToPlace(Map<CardName, Place> cardNamePlaceMap, List<Card> cards) {
Map<Card, Place> map = new HashMap<>();
for(Card card : cards){
if(cardNamePlaceMap.containsKey(card.getCardName())){
map.put(card, cardNamePlaceMap.get(card.getCardName()));
}
}
return map;
}
}
......@@ -2,13 +2,16 @@ package fr.univnantes.alma.game;
public class GameRoundVariables {
private int incrementScoreTraque;
private boolean jetonArtemiaIsActive;
public GameRoundVariables() {
this.incrementScoreTraque = 1;
jetonArtemiaIsActive = true;
}
public void reset(){
this.incrementScoreTraque = 1;
jetonArtemiaIsActive = true;
}
public int getIncrementScoreTraque() {
......@@ -18,4 +21,16 @@ public class GameRoundVariables {
public void setIncrementScoreTraque(int incrementScoreTraque) {
this.incrementScoreTraque = incrementScoreTraque;
}
public boolean isJetonArtemiaIsActive() {
return jetonArtemiaIsActive;
}
public void disableJetonArtemia() {
jetonArtemiaIsActive = false;
}
public void enableJetonArtemia() {
jetonArtemiaIsActive = true;
}
}
......@@ -5,9 +5,7 @@ import fr.univnantes.alma.game.item.card.PlaceCard;
import fr.univnantes.alma.game.utilitary.Pair;
import javassist.NotFoundException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
public class Reserve {
private Map<Integer, Pair<PlaceCard, Integer>> placeCards;
......@@ -31,6 +29,23 @@ public class Reserve {
}
}
/**
* A List containing the list of PlaceCard with copies number greater than 0
* @return
*/
public List<PlaceCard> getNotEmptyPlaceCard() {
Iterator<Integer> iterator = placeCards.keySet().iterator();
List<PlaceCard> list = new ArrayList<>();
Pair<PlaceCard, Integer> pair;
while(iterator.hasNext()) {
pair = placeCards.get(iterator.next());
if(pair.getValue() > 0) {
list.add(pair.getKey());
}
}
return list;
}
private int copiesNumber(int numberPlayer){
if(numberPlayer >= 5){
return 3;
......@@ -43,6 +58,21 @@ public class Reserve {
}
}
/**
* Test if Reserve contains place cards
* @return true if there is PlaceCard (cardNumber), false otherwise
*/
public boolean isNotEmpty(){
Iterator<Integer> iterator = placeCards.keySet().iterator();
boolean response = false;
int copiesNumber;
while(!response && iterator.hasNext()) {
copiesNumber = placeCards.get(iterator.next()).getValue();
response = response || copiesNumber > 0;
}
return response;
}
/**
* Test if Reserve contains copies of the PlaceCard
* @param cardNumber The card number
......@@ -75,4 +105,13 @@ public class Reserve {
return placeCard;
}
}
public void add(PlaceCard placeCard) {
int cardNumber = placeCard.getNumber();
if(cardNumber<= 5 && cardNumber > 10) {
throw new IllegalArgumentException("PlaceCard in reserve are place cards 6 to 10");
}
int number = placeCards.get(cardNumber).getValue() + 1;
placeCards.put(cardNumber, new Pair<>(placeCard, number));
}
}
......@@ -96,6 +96,10 @@ public class Board {
return score.actualBestTeam();
}
public PlayerTeam winner(){
return score.winner();
}
/**
* Move forward the score of Traque of delta square
*/
......
......@@ -10,21 +10,25 @@ public class Score {
private int scoreTraque;
private int scoreCreature;
private PlayerTeam winner;
public Score(){
this.scoreCreature = 0;
this.scoreTraque = 0;
this.winner = null;
}
public Score(int playerNumber){
playerNumber -= 2; //delta score
this.scoreCreature = BASE_CREATURE + playerNumber;
this.scoreTraque = BASE_TRAQUE + playerNumber;
this.winner = null;
}
public Score(int scoreCreature, int scoreTraque){
this.scoreCreature = scoreCreature;
this.scoreTraque = scoreTraque;
this.winner = null;
}
public int getScoreTraque() {
......@@ -55,6 +59,13 @@ public class Score {
}
}
/**
* @return the team closest to victory
*/
public PlayerTeam winner(){
return winner;
}
/**
* @return true if the score of creature is greater than the base
*/
......@@ -79,6 +90,9 @@ public class Score {
if(!isFinish()) {
scoreTraque -= delta;
}
if(scoreTraque <= 0){
winner = PlayerTeam.TRAQUE;
}
}
/**
......@@ -97,6 +111,9 @@ public class Score {
if(!isFinish()) {
scoreCreature -= delta;
}
if(scoreCreature <= 0){
winner = PlayerTeam.CREATURE;
}
}
/**
......
......@@ -7,8 +7,6 @@ public class BeaconPawn extends PlanetPawn{
private boolean state;
public BeaconPawn(){
//TODO Define balise powers
super(PowerType.PION_BALISE);
state = false;
}
......@@ -21,4 +19,14 @@ public class BeaconPawn extends PlanetPawn{
public boolean isActive() {
return state;
}
@Override
public PawnType getType() {
return PawnType.BEACON;
}
@Override
public int maxMovesInRound() {
return 1;
}
}
package fr.univnantes.alma.game.item.planet;
public enum PawnType {
SHIELD, BEACON
}
......@@ -7,7 +7,6 @@ import java.util.*;
import java.util.List;
import java.util.stream.Collectors;
import static fr.univnantes.alma.game.item.planet.Place.*;
import static fr.univnantes.alma.game.item.planet.Planet.*;
import static java.util.Collections.shuffle;
......@@ -116,20 +115,20 @@ public class PlaceDistribution {
return mapPlaceCardToPlace.get(card);
}
/**
* Convert the place to a place card
* @param place The place
* @return A place
*/
public PlaceCard placeToCardPlace(Place place){
public PlaceCard placeToPlaceCard(Place place){
Iterator<PlaceCard> iterator = mapPlaceCardToPlace.keySet().iterator();
PlaceCard placeCard = null;
for(Map.Entry<PlaceCard, Place> entry : mapPlaceCardToPlace.entrySet()) {
if(entry.getValue().equals(place)) {
placeCard = entry.getKey();
}
boolean find = false;
while(! find && iterator.hasNext()) {
placeCard = iterator.next();
find = mapPlaceCardToPlace.get(placeCard).equals(place);
}
return placeCard;
return find ? placeCard : null;
}
/**
......@@ -180,4 +179,57 @@ public class PlaceDistribution {
return getPlaceCardsInInterval(1, 10);
}
/**
* Test if there is PlaceCard hidden
* @return
*/
public boolean isHiddenCards() {
return placeIsHidden.containsValue(true);
}
/**
* Return the list oh hidden PlaceCard
* @return
*/
public List<PlaceCard> getHiddenCards() {
List<PlaceCard> placeCards = new ArrayList<>();
for(Place place : placeIsHidden.keySet()){
if(placeIsHidden.get(place)){
placeCards.add(placeToPlaceCard(place));
}
}