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

Remove Jeton, JetonCible, JetonCreature and JetonArtemia

parent 5c7c303c
......@@ -7,7 +7,6 @@ import fr.univnantes.alma.server.game.item.card.CardName;
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.card.TrackingCard;
import fr.univnantes.alma.server.game.item.jeton.JetonArtemia;
import fr.univnantes.alma.server.game.item.jeton.JetonSymbol;
import java.util.*;
......
......@@ -494,7 +494,7 @@ public class Game implements GameInterface {
response = new Response(false, "Only the Creature can played jeton");
}
else if(! state.equals(Phase.PHASE_2)) {
if(gameRoundVariables.isJetonCibleBlockPlace() && placedJeton.getJeton().getType().equals(CIBLE)) {
if(gameRoundVariables.isJetonCibleBlockPlace() && placedJeton.getJetonSymbol().equals(CIBLE)) {
response = creaturePlaceAJeton(creature, placedJeton);
}
else {
......@@ -960,10 +960,9 @@ public class Game implements GameInterface {
}
}
JetonSymbol type = placedJeton.getJeton().getType();
JetonSymbol symbol = placedJeton.getJetonSymbol();
if(placedJeton.getPlaces().size() > 1) {
JetonSymbol symbol = placedJeton.getJeton().getType();
if(symbol.equals(JetonSymbol.CIBLE) && !gameRoundVariables.jetonCibleCanBeOnTwoAdjacentPlaces()) {
return new Response(false, "JetonCible can't be place on two adjacent places");
}
......@@ -979,11 +978,11 @@ public class Game implements GameInterface {
placeBetween6To10 = true;
}
}
if( (type.equals(CIBLE) && containsJetonCible)
|| (type.equals(ARTEMIA) && (containsJetonArtemia || board.isArtemiaSquare()))
|| type.equals(JetonSymbol.CREATURE) && (canPlaceOn6To10 || !placeBetween6To10)) {
if( (symbol.equals(CIBLE) && containsJetonCible)
|| (symbol.equals(ARTEMIA) && (containsJetonArtemia || board.isArtemiaSquare()))
|| symbol.equals(JetonSymbol.CREATURE) && (canPlaceOn6To10 || !placeBetween6To10)) {
if(planet.placeJeton(placedJeton)) {
creature.playJeton(placedJeton.getJeton());
creature.playJeton(placedJeton.getJetonSymbol());
return new Response(true, "");
}
else {
......@@ -1406,8 +1405,8 @@ public class Game implements GameInterface {
action = askAction(idPlayer, askAction);
if(action.getActionType().equals(SWAP_JETONS)) {
actionSwapJeton = (ActionSwapJeton) action;
symbol1 = actionSwapJeton.getJeton1();
symbol2 = actionSwapJeton.getJeton2();
symbol1 = actionSwapJeton.getJetonSymbol1();
symbol2 = actionSwapJeton.getJetonSymbol2();
}
} while(symbol1 == null || symbol2 == null || symbol1 == symbol2);
return new Pair<>(symbol1, symbol2);
......
......@@ -132,7 +132,7 @@ public class PowerApplicator {
private static boolean filterJetonBlockPlace(Game game, int idPlayer, PlaceCard placeCard) {
Planet planet = game.getPlanet();
GameRoundVariables variables = game.getGameRoundVariables();
List<JetonSymbol> jetonSymbols = planet.findJetonsOnCard(placeCard).stream().map(Jeton::getType).collect(Collectors.toList());
List<JetonSymbol> jetonSymbols = planet.findJetonsSymbolsOnCard(placeCard);
boolean canApplyArtemiaOnThisPlace = jetonSymbols.contains(JetonSymbol.ARTEMIA) && game.isJetonArtemiaIsActive();
boolean canApplyCreatureOnThisPlace = jetonSymbols.contains(JetonSymbol.CREATURE);
......@@ -1368,7 +1368,7 @@ public class PowerApplicator {
Pair<Place, Place> pair = chooseTwoAdjacentPlace(game, idPlayer);
PlacedJeton jetonCible = new PlacedJeton(JetonSymbol.CIBLE, Arrays.asList(pair.getKey(), pair.getValue()));
game.getPlanet().placeJeton(jetonCible);
game.getCreature().playJeton(new JetonCible());
game.getCreature().playJeton(JetonSymbol.CIBLE);
}
private static void applySurvivalRegeneration(Game game, int idPlayer) {
......
......@@ -9,12 +9,12 @@ import java.util.List;
import static fr.univnantes.alma.server.game.utilitary.Conversion.*;
public class ActionMoveJeton extends Action {
private JetonSymbol jeton;
private JetonSymbol jetonSymbol;
private Place place;
public ActionMoveJeton(JetonSymbol jeton, Place place) {
public ActionMoveJeton(JetonSymbol jetonSymbol, Place place) {
this.place = place;
this.jeton = jeton;
this.jetonSymbol = jetonSymbol;
}
public ActionMoveJeton(List<TPair> params) {
......@@ -27,12 +27,12 @@ public class ActionMoveJeton extends Action {
TPairType type1 = toTPairType(params.get(0).getKey());
TPairType type2 = toTPairType(params.get(1).getKey());
if(type1.equals(TPairType.JETON) && type2.equals(TPairType.PLACE)) {
this.jeton = toJetonType(params.get(0).getValue());
this.jetonSymbol = toJetonSymbol(params.get(0).getValue());
this.place = toPlace(params.get(1).getValue());
}
else if(type1.equals(TPairType.PLACE) && type2.equals(TPairType.JETON)) {
this.place = toPlace(params.get(0).getValue());
this.jeton = toJetonType(params.get(0).getValue());
this.jetonSymbol = toJetonSymbol(params.get(0).getValue());
}
else{
invalid = true;
......@@ -47,8 +47,8 @@ public class ActionMoveJeton extends Action {
}
}
public JetonSymbol getJeton() {
return jeton;
public JetonSymbol getJetonSymbol() {
return jetonSymbol;
}
public Place getPlace() {
......
......@@ -8,12 +8,12 @@ import java.util.List;
import static fr.univnantes.alma.server.game.utilitary.Conversion.*;
public class ActionSwapJeton extends Action {
private JetonSymbol jeton1;
private JetonSymbol jeton2;
private JetonSymbol jetonSymbol1;
private JetonSymbol jetonSymbol2;
public ActionSwapJeton(JetonSymbol j1, JetonSymbol j2){
this.jeton1 = j1;
this.jeton2 = j2;
this.jetonSymbol1 = j1;
this.jetonSymbol2 = j2;
}
public ActionSwapJeton(List<TPair> params) {
......@@ -26,8 +26,8 @@ public class ActionSwapJeton extends Action {
TPairType type1 = toTPairType(params.get(0).getKey());
TPairType type2 = toTPairType(params.get(1).getKey());
if(type1.equals(TPairType.JETON) && type2.equals(TPairType.JETON)) {
this.jeton1 = toJetonType(params.get(0).getValue());
this.jeton2 = toJetonType(params.get(1).getValue());
this.jetonSymbol1 = toJetonSymbol(params.get(0).getValue());
this.jetonSymbol2 = toJetonSymbol(params.get(1).getValue());
}
else{
invalid = true;
......@@ -42,12 +42,12 @@ public class ActionSwapJeton extends Action {
}
}
public JetonSymbol getJeton1() {
return jeton1;
public JetonSymbol getJetonSymbol1() {
return jetonSymbol1;
}
public JetonSymbol getJeton2() {
return jeton2;
public JetonSymbol getJetonSymbol2() {
return jetonSymbol2;
}
@Override
......
package fr.univnantes.alma.server.game.item.card;
import fr.univnantes.alma.server.game.item.Phase;
import fr.univnantes.alma.server.game.item.jeton.Jeton;
import fr.univnantes.alma.server.game.item.jeton.JetonSymbol;
import java.util.ArrayList;
......
package fr.univnantes.alma.server.game.item.jeton;
import fr.univnantes.alma.server.game.item.power.PowerType;
public abstract class Jeton {
//TODO remove
protected PowerType power;
//TODO Constructor
public PowerType getPowers() {
return power;
}
public abstract JetonSymbol getType();
}
package fr.univnantes.alma.server.game.item.jeton;
public class JetonArtemia extends Jeton {
@Override
public JetonSymbol getType() {
return JetonSymbol.ARTEMIA;
}
}
package fr.univnantes.alma.server.game.item.jeton;
public class JetonCible extends Jeton {
@Override
public JetonSymbol getType() {
return JetonSymbol.CIBLE;
}
}
package fr.univnantes.alma.server.game.item.jeton;
public class JetonCreature extends Jeton {
@Override
public JetonSymbol getType() {
return JetonSymbol.CREATURE;
}
}
......@@ -6,53 +6,23 @@ import java.util.ArrayList;
import java.util.List;
public class PlacedJeton {
private Jeton jeton;
private JetonSymbol jetonSymbol;
private List<Place> places;
public PlacedJeton(Jeton jeton, List<Place> places) {
this.jeton = jeton;
this.places = places;
}
public PlacedJeton(Jeton jeton, Place place) {
this.jeton = jeton;
public PlacedJeton(JetonSymbol symbol, Place place) {
this.places = new ArrayList<>();
this.places.add(place);
this.jetonSymbol = symbol;
}
public PlacedJeton(JetonSymbol symbol, List<Place> places) {
this.places = places;
switch (symbol) {
case CIBLE:
this.jeton = new JetonCible();
break;
case ARTEMIA:
this.jeton = new JetonArtemia();
break;
case CREATURE:
this.jeton = new JetonCreature();
break;
}
this.jetonSymbol = symbol;
}
public PlacedJeton(JetonSymbol symbol, Place place) {
this.places = new ArrayList<>();
this.places.add(place);
switch (symbol) {
case CIBLE:
this.jeton = new JetonCible();
break;
case ARTEMIA:
this.jeton = new JetonArtemia();
break;
case CREATURE:
this.jeton = new JetonCreature();
break;
}
}
public Jeton getJeton() {
return jeton;
public JetonSymbol getJetonSymbol() {
return jetonSymbol;
}
public List<Place> getPlaces() {
......
......@@ -18,7 +18,7 @@ public class Planet {
public static final int POLE_NUMBER = 8;
private Map<Place, List<Jeton>> mapPlaceToJetons;
private Map<Place, List<JetonSymbol>> mapPlaceToJetons;
private Map<Place, Boolean> blockedPlaces;
private Map<Place, List<SurvivalCard>> placeSurvivalCardMap;
private int numberMovesAllowInRound;
......@@ -55,7 +55,7 @@ public class Planet {
if(! mapPlaceToJetons.containsKey(place)){
mapPlaceToJetons.put(place, new ArrayList<>());
}
mapPlaceToJetons.get(place).add(placedJeton.getJeton());
mapPlaceToJetons.get(place).add(placedJeton.getJetonSymbol());
}
return true;
}
......@@ -66,11 +66,11 @@ public class Planet {
public List<Place> findPlacesWhereJetonIs(JetonSymbol symbol) {
List<Place> places = new ArrayList<>();
List<Jeton> jetonsAux;
List<JetonSymbol> jetonsAux;
for(Place place : mapPlaceToJetons.keySet()) {
jetonsAux = mapPlaceToJetons.get(place);
for(Jeton j : jetonsAux) {
if(j.getType().equals(symbol)) {
for(JetonSymbol jetonSymbol : jetonsAux) {
if(jetonSymbol.equals(symbol)) {
places.add(place);
}
}
......@@ -79,26 +79,17 @@ public class Planet {
}
public List<PlaceCard> findPlaceCardsWhereJetonIs(JetonSymbol symbol) {
List<PlaceCard> placeCards = new ArrayList<>();
List<Jeton> jetonsAux;
for(Place place : mapPlaceToJetons.keySet()) {
jetonsAux = mapPlaceToJetons.get(place);
for(Jeton j : jetonsAux) {
if(j.getType().equals(symbol)) {
placeCards.add(placeToPlaceCard(place));
}
}
}
return placeCards;
return findPlacesWhereJetonIs(symbol).stream()
.map(this::placeToPlaceCard).collect(Collectors.toList());
}
public void removeJeton(JetonSymbol symbol) {
List<Place> places = new ArrayList<>();
List<Jeton> jetonsAux;
List<JetonSymbol> jetonsAux;
for(Place place : mapPlaceToJetons.keySet()) {
jetonsAux = mapPlaceToJetons.get(place);
for(Jeton j : jetonsAux) {
if(j.getType().equals(symbol)) {
for(JetonSymbol jetonSymbol : jetonsAux) {
if(jetonSymbol.equals(symbol)) {
places.add(place);
}
}
......@@ -142,7 +133,7 @@ public class Planet {
return isJetonOnPlace(placeDistribution.placeCardToPlace(card));
}
public List<Jeton> findJetonsOnCard(PlaceCard card){
public List<JetonSymbol> findJetonsSymbolsOnCard(PlaceCard card){
if(isJetonOnPlace(card)){
return mapPlaceToJetons.get(placeDistribution.placeCardToPlace(card));
}
......@@ -151,10 +142,6 @@ public class Planet {
}
}
public List<JetonSymbol> findJetonsSymbolsOnCard(PlaceCard card){
return findJetonsOnCard(card).stream().map(Jeton::getType).collect(Collectors.toList());
}
public boolean isJetonSymbolOnPlaceCard(JetonSymbol symbol, PlaceCard placeCard) {
return findJetonsSymbolsOnCard(placeCard).contains(symbol);
}
......@@ -195,9 +182,9 @@ public class Planet {
public List<PlaceCard> placesWhereJetonCreatureIs() {
List<PlaceCard> placeCards = new ArrayList<>();
for(Map.Entry<Place, List<Jeton>> entry : mapPlaceToJetons.entrySet()){
for(Jeton j : entry.getValue()) {
if(j.getType().equals(JetonSymbol.CREATURE)) {
for(Map.Entry<Place, List<JetonSymbol>> entry : mapPlaceToJetons.entrySet()){
for(JetonSymbol jetonSymbol : entry.getValue()) {
if(jetonSymbol.equals(JetonSymbol.CREATURE)) {
placeCards.add(placeDistribution.placeToPlaceCard(entry.getKey()));
}
}
......@@ -440,15 +427,15 @@ public class Planet {
}
public void swapJeton(JetonSymbol symbol1, JetonSymbol symbol2) {
Map<Place, List<Jeton>> newMap = new HashMap<>();
Map<Place, List<JetonSymbol>> newMap = new HashMap<>();
for(Place place : mapPlaceToJetons.keySet()) {
for(Jeton jeton : mapPlaceToJetons.get(place)) {
for(JetonSymbol jeton : mapPlaceToJetons.get(place)) {
newMap.putIfAbsent(place, new ArrayList<>());
if(jeton.getType().equals(symbol1)){
newMap.get(place).add(createJeton(symbol2));
if(jeton.equals(symbol1)){
newMap.get(place).add(symbol2);
}
else if(jeton.getType().equals(symbol2)) {
newMap.get(place).add(createJeton(symbol1));
else if(jeton.equals(symbol2)) {
newMap.get(place).add(symbol1);
}
else{
newMap.get(place).add(jeton);
......@@ -457,17 +444,4 @@ public class Planet {
}
mapPlaceToJetons = newMap;
}
public Jeton createJeton(JetonSymbol symbol) {
switch (symbol) {
case CIBLE:
return new JetonCible();
case ARTEMIA:
return new JetonArtemia();
case CREATURE:
return new JetonCreature();
default:
throw new IllegalArgumentException(symbol + " is not a valid symbol");
}
}
}
package fr.univnantes.alma.server.game.item.player;
import fr.univnantes.alma.server.game.item.card.TrackingCard;
import fr.univnantes.alma.server.game.item.jeton.Jeton;
import fr.univnantes.alma.server.game.item.jeton.JetonSymbol;
import fr.univnantes.alma.server.game.item.player.hand.HandCreature;
import fr.univnantes.alma.server.game.item.player.rights.CreatureRight;
......@@ -69,15 +69,15 @@ public class Creature extends Player {
return hand.jetonsIsEmpty();
}
public List<Jeton> getJetons(){
return hand.getJetons();
public List<JetonSymbol> getJetons(){
return hand.getJetonSymbols();
}
public boolean playJeton(Jeton jeton){
public boolean playJeton(JetonSymbol jeton){
return hand.playJeton(jeton);
}
public boolean playJeton(List<Jeton> jetons){
public boolean playJeton(List<JetonSymbol> jetons){
return hand.playJeton(jetons);
}
......
package fr.univnantes.alma.server.game.item.player.hand;
import fr.univnantes.alma.server.game.item.card.TrackingCard;
import fr.univnantes.alma.server.game.item.jeton.Jeton;
import fr.univnantes.alma.server.game.item.jeton.JetonArtemia;
import fr.univnantes.alma.server.game.item.jeton.JetonCible;
import fr.univnantes.alma.server.game.item.jeton.JetonCreature;
import fr.univnantes.alma.server.game.item.jeton.JetonSymbol;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class HandCreature {
private Deck<TrackingCard> trackingCards;
private List<Jeton> jetons;
private List<JetonSymbol> jetonSymbols;
private List<TrackingCard> trackingCardsToApplied;
/**
* The jetons played by the player in the current round
*/
private List<Jeton> jetonsPlayed;
private List<JetonSymbol> jetonSymbolsPlayed;
public HandCreature(){
this.trackingCards = new Deck<>(3);
......@@ -55,25 +53,22 @@ public class HandCreature {
* Jeton methods
*******************************/
public void initializationJeton(){
jetons = new ArrayList<>();
jetons.add(new JetonArtemia());
jetons.add(new JetonCreature());
jetons.add(new JetonCible());
jetonsPlayed = new ArrayList<>();
jetonSymbols = new ArrayList<>(Arrays.asList(JetonSymbol.CIBLE, JetonSymbol.CREATURE, JetonSymbol.ARTEMIA));
jetonSymbolsPlayed = new ArrayList<>();
}
public List<Jeton> getJetonsPlayed() {
return jetonsPlayed;
public List<JetonSymbol> getJetonSymbolsPlayed() {
return jetonSymbolsPlayed;
}
public List<Jeton> getJetons(){
return jetons;
public List<JetonSymbol> getJetonSymbols(){
return jetonSymbols;
}
public boolean playJeton(Jeton jeton){
if(jetons.contains(jeton)){
jetons.remove(jeton);
jetonsPlayed.add(jeton);
public boolean playJeton(JetonSymbol jeton){
if(jetonSymbols.contains(jeton)){
jetonSymbols.remove(jeton);
jetonSymbolsPlayed.add(jeton);
return true;
}
else{
......@@ -81,10 +76,10 @@ public class HandCreature {
}
}
public boolean playJeton(List<Jeton> jetons){
if(this.jetons.containsAll(jetons)){
this.jetons.removeAll(jetons);
jetonsPlayed.addAll(jetons);
public boolean playJeton(List<JetonSymbol> jetons){
if(this.jetonSymbols.containsAll(jetons)){
this.jetonSymbols.removeAll(jetons);
jetonSymbolsPlayed.addAll(jetons);
return true;
}
else{
......@@ -93,19 +88,19 @@ public class HandCreature {
}
public int jetonsSize(){
return jetons.size();
return jetonSymbols.size();
}
public int jetonsPlayedSize(){
return jetonsPlayed.size();
return jetonSymbolsPlayed.size();
}
public boolean jetonsIsEmpty(){
return jetons.isEmpty();
return jetonSymbols.isEmpty();
}
public boolean jetonsPlayedIsEmpty(){
return jetonsPlayed.isEmpty();
return jetonSymbolsPlayed.isEmpty();
}
/********************************
......
......@@ -202,40 +202,12 @@ public class Conversion {
* Jeton
***********************************/
/**
* Convert a TJeton in a Jeton
* @param tJeton
* @return
*/
public static Jeton toJeton(TJeton tJeton){
return toJeton(tJeton.jetonId);
}
/**
* Convert a String in a Jeton