Commit f2944ff2 authored by Killian LUCAS's avatar Killian LUCAS
Browse files

conception.adoc + modification planet pour la claireté

parent 350deaad
......@@ -18,9 +18,9 @@ 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, SurvivalCard> placeSurvivalCardMap;
private Map<Place, List<SurvivalCard>> placeSurvivalCardMap;
private int numberMovesAllowInRound;
private PlaceDistribution placeDistribution;
private PlanetPawn planetPawn;
......@@ -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;
}
......@@ -64,13 +64,13 @@ public class Planet {
}
}
public List<Place> getPlacesWhereJetonIs(JetonSymbol symbol) {
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);
}
}
......@@ -78,27 +78,18 @@ public class Planet {
return places;
}
public List<PlaceCard> getPlaceCardsWhereJetonIs(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;
public List<PlaceCard> findPlaceCardsWhereJetonIs(JetonSymbol symbol) {
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);
}
}
......@@ -138,23 +129,19 @@ public class Planet {
return mapPlaceToJetons.containsKey(place);
}
public boolean isJetonOnPlace(PlaceCard card){
return isJetonOnPlace(placeDistribution.placeCardToPlace(card));
public boolean isJetonOnPlace(PlaceCard placeCard){
return isJetonOnPlace(placeDistribution.placeCardToPlace(placeCard));
}
public List<Jeton> findJetonsOnCard(PlaceCard card){
if(isJetonOnPlace(card)){
return mapPlaceToJetons.get(placeDistribution.placeCardToPlace(card));
public List<JetonSymbol> findJetonsSymbolsOnCard(PlaceCard placeCard){
if(isJetonOnPlace(placeCard)){
return mapPlaceToJetons.get(placeDistribution.placeCardToPlace(placeCard));
}
else{
return new ArrayList<>();
}
}
public List<JetonSymbol> findJetonsSymbolsOnCard(PlaceCard placeCard){
return findJetonsOnCard(placeCard).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()));
}
}
......@@ -244,11 +231,18 @@ public class Planet {
}
public SurvivalCard takeSurvivalCardOnPlace(Place place) {
SurvivalCard survivalCard = placeSurvivalCardMap.getOrDefault(place, null);
if(survivalCard != null) {
placeSurvivalCardMap.remove(place);
List<SurvivalCard> survivalCards = placeSurvivalCardMap.getOrDefault(place, null);
SurvivalCard cardCaught = null;
if(survivalCards != null) {
if(!survivalCards.isEmpty()) {
cardCaught = survivalCards.get(0);
survivalCards.remove(cardCaught);
}
if(survivalCards.isEmpty()) {
placeSurvivalCardMap.remove(place);
}
}
return survivalCard;
return cardCaught;
}
public SurvivalCard takeSurvivalCardOnPlace(PlaceCard placeCard) {
......@@ -257,7 +251,8 @@ public class Planet {
public void putSurvivalCardOnPlace(Pair<Place, SurvivalCard> pair) {
placeSurvivalCardMap.putIfAbsent(pair.getKey(), pair.getValue());
placeSurvivalCardMap.putIfAbsent(pair.getKey(), new ArrayList<>());
placeSurvivalCardMap.get(pair.getKey()).add(pair.getValue());
}
public void putSurvivalCardOnPlace(List<Pair<Place, SurvivalCard>> pairs) {
......@@ -432,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);
......@@ -449,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");
}
}
}
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