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

Refactoring of several classes ; Add some converting methods ; Defines methods...

Refactoring of several classes ; Add some converting methods ; Defines methods to manage the phases (in game.java) ; Start implementation of PowerApplicator ; Start the implementation of 'ask action' methods (also in game.java)
parent 58b10d4d
......@@ -36,4 +36,14 @@ struct TPlacedJeton{
struct TPhaseId {
1: string name
}
struct TPair {
1: string key,
2: string value
}
struct TAction {
1: string type,
2: list<TPair> params
}
\ No newline at end of file
......@@ -63,6 +63,8 @@ service GameClientService {
void sendStartPhase(common.TPhaseId phaseId, TPlayerTeam team, THand hand, TScore score, TPlanet planet, list<TCardReserve> reserve, list<TTraque> traquesInformation, TCreature creatureInformation)
common.TAction askAction(common.TAction actionAsked)
}
......@@ -16,11 +16,6 @@ struct TRoomId {
1: string token
}
struct TAction {
1: string type,
2: list<string> params
}
struct TBoard {
1: string board
}
......@@ -50,10 +45,11 @@ service GameServerService {
common.Response sendPlaceJetons(TPlayerId playerId, list<common.TPlacedJeton> placedJetons)
common.Response sendResist(TPlayerId playerId)
common.Response sendResist(TPlayerId playerId, i32 number)
common.Response sendGiveUp(TPlayerId playerId)
common.Response sendChooseAction(TPlayerId playerId, TAction action)
//Is usefull ?
common.Response sendChooseAction(TPlayerId playerId, common.TAction action)
}
......@@ -2,6 +2,7 @@ package fr.univnantes.alma.data;
import fr.univnantes.alma.data.item.User;
import fr.univnantes.alma.game.item.Phase;
import fr.univnantes.alma.game.item.card.CardName;
import fr.univnantes.alma.game.item.card.PlaceCard;
import fr.univnantes.alma.game.item.card.SurvivalCard;
import fr.univnantes.alma.game.item.card.TrackingCard;
......@@ -28,27 +29,27 @@ public class DatabaseStub implements NotAloneDatabase {
private void initializePlaceCardMap(){
placeCardMap = new HashMap<>();
placeCardMap.put("ANTRE", new PlaceCard("ANTRE", "Antre", "Lorem ipsum", PowerType.ANTRE, 1, "/image.png", "#4466bb"));
placeCardMap.put("NEXUS", new PlaceCard("NEXUS", "Nexus", "Lorem ipsum", PowerType.NEXUS, 1, "/image.png", "#4466bb"));
placeCardMap.put("JUNGLE", new PlaceCard("JUNGLE", "Jungle", "Lorem ipsum", PowerType.JUNGLE, 2, "/image.png", "#4466bb"));
placeCardMap.put("RIVIERE", new PlaceCard("RIVIERE", "Rivière", "Lorem ipsum", PowerType.RIVIERE, 3, "/image.png", "#4466bb"));
placeCardMap.put("DOME", new PlaceCard("DOME","Dôme", "Lorem ipsum", PowerType.DOME, 4, "/image.png", "#4466bb"));
placeCardMap.put("PLAGE", new PlaceCard("PLAGE","Plage", "Lorem ipsum", PowerType.PLAGE, 5, "/image.png", "#4466bb"));
placeCardMap.put("MANGROVE", new PlaceCard("MANGROVE", "Mangrove", "Lorem ipsum", PowerType.MANGROVE, 6, "/image.png", "#4466bb"));
placeCardMap.put("ABRI", new PlaceCard("ABRI", "Abri", "Lorem ipsum", PowerType.ABRI, 7, "/image.png", "#4466bb"));
placeCardMap.put("EPAVE", new PlaceCard("EPAVE", "Epave", "Lorem ipsum", PowerType.EPAVE, 8, "/image.png", "#4466bb"));
placeCardMap.put("FUNGI", new PlaceCard("FUNGI", "Fungi", "Lorem ipsum", PowerType.FUNGI, 9, "/image.png", "#4466bb"));
placeCardMap.put("PORTAIL", new PlaceCard("PORTAIL", "Portail", "Lorem ipsum", PowerType.PORTAIL, 10, "/image.png", "#4466bb"));
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("RIVIERE", new PlaceCard(CardName.RIVIERE, "Rivière", "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", 5, "/image.png", "#4466bb"));
placeCardMap.put("MANGROVE", new PlaceCard(CardName.MANGROVE, "Mangrove", "Lorem ipsum", 6, "/image.png", "#4466bb"));
placeCardMap.put("ABRI", new PlaceCard(CardName.ABRI, "Abri", "Lorem ipsum", 7, "/image.png", "#4466bb"));
placeCardMap.put("EPAVE", new PlaceCard(CardName.EPAVE, "Epave", "Lorem ipsum", 8, "/image.png", "#4466bb"));
placeCardMap.put("FUNGI", new PlaceCard(CardName.FUNGI, "Fungi", "Lorem ipsum", 9, "/image.png", "#4466bb"));
placeCardMap.put("PORTAIL", new PlaceCard(CardName.PORTAIL, "Portail", "Lorem ipsum", 10, "/image.png", "#4466bb"));
}
private void initializeSurvivalCardMap(){
survivalCardMap = new HashMap<>();
survivalCardMap.put("ADRENALINE", new SurvivalCard("ADRENALINE","Adrénaline", "Lorem ipsum", PowerType.ADRENALINE, Phase.PHASE_1));
survivalCardMap.put("ADRENALINE", new SurvivalCard(CardName.ADRENALINE,"Adrénaline", "Lorem ipsum", Phase.PHASE_1));
}
private void initializeTrackingCardMap(){
trackingCardMap = new HashMap<>();
trackingCardMap.put("ACHARNEMENT", new TrackingCard("ACHARNEMENT", "Acharnement", "Lorem ipsum", PowerType.ACHARNEMENT, Phase.PHASE_1));
trackingCardMap.put("ACHARNEMENT", new TrackingCard(CardName.ACHARNEMENT, "Acharnement", "Lorem ipsum", Phase.PHASE_1));
}
......
......@@ -5,6 +5,8 @@ import fr.univnantes.alma.game.item.action.Action;
import fr.univnantes.alma.game.item.card.Card;
import fr.univnantes.alma.game.item.jeton.PlacedJeton;
import fr.univnantes.alma.game.item.power.Power;
import fr.univnantes.alma.thrift.Response;
import fr.univnantes.alma.thrift.TAction;
import java.util.List;
......@@ -28,13 +30,13 @@ public interface GameInterface {
* @param phase The phase finished by the player
* @throws IllegalArgumentException if the player need to play
*/
public void playerHasFinished(int playerId, Phase phase);
public Response playerHasFinished(int playerId, Phase phase);
/**
* Test if the current phase is finished
* @return true if the current phase is finished, false otherwise
*/
public boolean phaseIsFinish();
public boolean phaseIsFinish(Phase phase);
/**
* Inform the game that the player play a card
......@@ -42,7 +44,7 @@ public interface GameInterface {
* @param card The card played by the player
* @throws IllegalArgumentException if this action is not valid
*/
public void playerPlayCard(int playerId, Card card);
public Response playerPlayCard(int playerId, Card card);
/**
* Inform the game that the player play card
......@@ -50,7 +52,7 @@ public interface GameInterface {
* @param cards The cards played by the player
* @throws IllegalArgumentException if this action is not valid
*/
public void playerPlayCard(int playerId, List<Card> cards);
public Response playerPlayCard(int playerId, List<Card> cards);
/**
* Inform the game that the player place a jeton
......@@ -58,7 +60,7 @@ public interface GameInterface {
* @param jeton The jeton placed by the player
* @throws IllegalArgumentException if this action is not valid
*/
public void playerPlaceJeton(int playerId, PlacedJeton jeton);
public Response playerPlaceJeton(int playerId, PlacedJeton jeton);
/**
* Inform the game that the player place jetons
......@@ -66,21 +68,22 @@ public interface GameInterface {
* @param jetons The jetons placed by the player
* @throws IllegalArgumentException if this action is not valid
*/
public void playerPlaceJeton(int playerId, List<PlacedJeton> jetons);
public Response playerPlaceJeton(int playerId, List<PlacedJeton> jetons);
/**
* Inform the game that the player resist
* @param playerId The game id of the player
* @param number The number of willingnessPawn lost
* @throws IllegalArgumentException if this action is not valid
*/
public void playerResist(int playerId);
public Response playerResist(int playerId, int number);
/**
* Inform the game that the player give up
* @param playerId The game id of the player
* @throws IllegalArgumentException if this action is not valid
*/
public void playerGiveUp(int playerId);
public Response playerGiveUp(int playerId);
/**
* Inform the game that the player choose an action
......@@ -88,7 +91,35 @@ public interface GameInterface {
* @param action The action chosen
* @throws IllegalArgumentException if this action is not valid
*/
public void playerChooseAction(int playerId, Action action);
public Response playerChooseAction(int playerId, Action action);
/**
* Ask an action to a client
* @param inGameIdPlayer The id of player
* @param askedAction The asked action
* @return An Action
*/
public Action askAction(int inGameIdPlayer, TAction askedAction);
/**
* Send that the game start
*/
public void sendFirstRoundStart();
/**
* Send that a new phase has started
*/
public void sendStartPhase();
/**
* Send the game description
*/
public void sendDescription();
/**
* Send that the game is end
*/
public void sendGameIsEnd();
//TODO find a describing game function
......
package fr.univnantes.alma.game;
public class GameRoundVariables {
private int incrementScoreTraque;
public GameRoundVariables() {
this.incrementScoreTraque = 1;
}
public void reset(){
this.incrementScoreTraque = 1;
}
public int getIncrementScoreTraque() {
return incrementScoreTraque;
}
public void setIncrementScoreTraque(int incrementScoreTraque) {
this.incrementScoreTraque = incrementScoreTraque;
}
}
package fr.univnantes.alma.game;
import fr.univnantes.alma.game.item.card.PlaceCard;
import fr.univnantes.alma.game.item.card.PlayerCard;
import fr.univnantes.alma.game.item.planet.Planet;
import fr.univnantes.alma.game.item.player.Traque;
import fr.univnantes.alma.game.item.power.Power;
import java.util.Arrays;
import java.util.List;
public class PowerApplicator {
private PowerApplicator(){}
public static void apply(Power power, Game game) {
}
public static void applyPlayerCard(int idPlayer, PlayerCard playerCard, Game game){
}
public static void revealPlace(int idPlayer, PlaceCard placeCard, Game game) {
Planet planet = game.getPlanet();
if(planet.isJetonOnPlace(placeCard)){
applyJeton(idPlayer, placeCard, game);
return;
}
else if(planet.isBlockedPlace(placeCard)){
//when a place is unusable
return;
}
switch (placeCard.getCardName()) {
case ANTRE:
break;
case JUNGLE:
break;
case RIVIERE:
break;
case PLAGE:
break;
case ROVER:
break;
case MARAIS:
break;
case ABRI:
break;
case EPAVE:
break;
case SOURCE:
break;
case ARTEFACT:
break;
case NEXUS:
break;
case OASIS:
break;
case FJORD:
break;
case DOME:
break;
case LABYRINTHE:
break;
case MANGROVE:
break;
case ARCHIPEL:
break;
case POLE:
break;
case FUNGI:
break;
case PORTAIL:
break;
default:
throw new IllegalArgumentException(placeCard.getCardName() + " is not a PlacePower");
}
}
private static void applyJeton(int inGameIdPlayer, PlaceCard card, Game game) {
//TODO
}
private static void applyPlaceAntre(int inGameIdPlayer, Game game) {
List<String> 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");
int idPower = game.choosePower(inGameIdPlayer, powersDescription);
if(idPower == 0) {
Traque traque = (Traque) game.getPlayersMap().get(inGameIdPlayer);
traque.takeBackAllPlaceCardFromDefausse();
}
else if (idPower == 1) {
List<PlaceCard> placeCards = game.getPlanet().placesWhereJetonCreatureIs();
if(placeCards.size() > 1) {
}
//TODO
}
else {
}
}
}
......@@ -4,6 +4,7 @@ import fr.univnantes.alma.game.item.board.Board;
import fr.univnantes.alma.game.item.planet.Planet;
import fr.univnantes.alma.game.utilitary.request.GameJoinRequest;
import fr.univnantes.alma.game.utilitary.request.GameRequest;
import fr.univnantes.alma.thrift.GameClientService;
import fr.univnantes.alma.thrift.Response;
import org.atlanmod.commons.log.Log;
......@@ -126,7 +127,7 @@ public class Room {
}
else{
isStart = true;
this.game = new Game(players.size(), creatureId, planet, board);
this.game = new Game(players.size(), creatureId, planet, board, this);
response = new Response(true, "");
}
return response;
......
package fr.univnantes.alma.game.item;
import fr.univnantes.alma.game.item.card.CardName;
import fr.univnantes.alma.game.item.card.PlaceCard;
import fr.univnantes.alma.game.item.player.Player;
import fr.univnantes.alma.game.utilitary.Pair;
import fr.univnantes.alma.thrift.Response;
import javassist.NotFoundException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static fr.univnantes.alma.game.item.planet.Planet.POLE_ID;
public class Reserve {
private Map<Integer, Pair<PlaceCard, Integer>> placeCards;
......@@ -25,7 +22,7 @@ public class Reserve {
if((c.getNumber() < 6 && c.getNumber() > 10) || placeCards.containsKey(c.getNumber())){
throw new IllegalArgumentException("Need each number once (6-10)");
}
if (c.getId().equals(POLE_ID)){
if (c.getCardName().equals(CardName.POLE)){
placeCards.put(c.getNumber(), new Pair<>(c, 1));
}
else {
......
package fr.univnantes.alma.game.item.action;
import fr.univnantes.alma.game.utilitary.Pair;
import fr.univnantes.alma.thrift.TAction;
import java.util.List;
/**
* Represents all secondaries actions that a player can do
*/
public abstract class Action {
public abstract ActionType getActionType();
public static TAction createTAction(ActionType type, List<Pair<String, String >> params) {
return null;
}
}
package fr.univnantes.alma.game.item.action;
import fr.univnantes.alma.game.item.card.CardName;
import fr.univnantes.alma.game.item.card.SurvivalCard;
import fr.univnantes.alma.game.item.planet.Place;
import fr.univnantes.alma.thrift.TPair;
import java.util.*;
import static fr.univnantes.alma.game.utilitary.Conversion.*;
public class ActionAssociateCardNamesToPlaces extends Action {
private Map<CardName, Place> cardNamePlaceMap;
public ActionAssociateCardNamesToPlaces(Map<CardName, Place> map){
this.cardNamePlaceMap = map;
}
public ActionAssociateCardNamesToPlaces(List<TPair> params) {
this.cardNamePlaceMap = new HashMap<>();
if(params.size() % 2 != 0){
throw new IllegalArgumentException("Need a number pair of arguments");
}
CardName cardName;
Place place;
try {
for(int i = 0 ; i < params.size() ; i = i+2) {
if(toTPairType(params.get(i).getKey()).equals(TPairType.PLACE)
&& toTPairType(params.get(i+1).getKey()).equals(TPairType.CARD)){
place = toPlace(params.get(i).getValue());
cardName = toCardName(params.get(i+1).getValue());
this.cardNamePlaceMap.put(cardName, place);
}
else if(toTPairType(params.get(i).getKey()).equals(TPairType.CARD)
&& toTPairType(params.get(i+1).getKey()).equals(TPairType.PLACE)){
cardName = toCardName(params.get(i).getValue());
place = toPlace(params.get(i+1).getValue());
this.cardNamePlaceMap.put(cardName, place);
}
else{
throw new IllegalArgumentException("Need only places and cards (alternate)");
}
}
}
catch (Exception e){
throw new IllegalArgumentException("Need only places");
}
}
public Map<CardName, Place> getCardNamePlaceMap() {
return cardNamePlaceMap;
}
@Override
public ActionType getActionType() {
return ActionType.ASSOCIATE_CARDNAMES_TO_PLACES;
}
}
package fr.univnantes.alma.game.item.action;
import fr.univnantes.alma.game.item.card.SurvivalCard;
import java.util.Map;
public class ActionAssociateSurvivalCardsToPlaces extends Action {
private Map<SurvivalCard, Integer> survivalCardIntegerMap;
public ActionAssociateSurvivalCardsToPlaces(Map<SurvivalCard, Integer> map){
this.survivalCardIntegerMap = map;
}
public Map<SurvivalCard, Integer> getSurvivalCardIntegerMap() {
return survivalCardIntegerMap;
}
@Override
public ActionType getActionType() {
return ActionType.ASSOCIATE_SURVIVAL_CARDS_TO_PLACES;
}
}
package fr.univnantes.alma.game.item.action;
import fr.univnantes.alma.game.item.card.Card;
import fr.univnantes.alma.game.item.card.CardName;
import fr.univnantes.alma.thrift.TPair;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import static fr.univnantes.alma.game.utilitary.Conversion.*;
public class ActionChooseCard extends Action {
private List<Card> cards;
private List<CardName> cards;
public ActionChooseCard(List<Card> list){
public ActionChooseCard(List<CardName> list){
this.cards = list;
}
public List<Card> getIdCards() {
public ActionChooseCard(Collection<TPair> params) {
this.cards = new ArrayList<>();
try {
for(TPair pair : params) {
if(!toTPairType(pair.getKey()).equals(TPairType.CARD)){
throw new IllegalArgumentException("Need only cards");
}
this.cards.add(toCardName(pair.getValue()));
}
}
catch (Exception e){
throw new IllegalArgumentException("Need only cards");
}
}
public List<CardName> getCards() {
return cards;
}
......
package fr.univnantes.alma.game.item.action;
import fr.univnantes.alma.game.item.planet.Place;
import fr.univnantes.alma.thrift.TPair;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import static fr.univnantes.alma.game.utilitary.Conversion.*;
public class ActionChoosePlace extends Action {
private List<Place> places;
......@@ -11,6 +16,23 @@ public class ActionChoosePlace extends Action {
this.places = list;
}
public ActionChoosePlace(Collection<TPair> params) {
this.places = new ArrayList<>();
try {
for(TPair pair : params) {
if(!toTPairType(pair.getKey()).equals(TPairType.PLACE)){
throw new IllegalArgumentException("Need only places");
}
this.places.add(toPlace(pair.getValue()));
}
}
catch (Exception e){
throw new IllegalArgumentException("Need only places");
}
}