Merge branch 'main' into javadoc-fixes
This commit is contained in:
@@ -4,6 +4,9 @@ import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Builder;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Inventor;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventCard;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventType;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.Board;
|
||||
@@ -17,7 +20,8 @@ import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import it.polimi.ingsw.gc14.Network.Observer;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import it.polimi.ingsw.gc14.View.TUI.AsciiTable;
|
||||
import it.polimi.ingsw.gc14.View.TUI.BorderStyle;
|
||||
|
||||
@@ -28,26 +32,6 @@ import it.polimi.ingsw.gc14.View.TUI.BorderStyle;
|
||||
*/
|
||||
public class Game implements Serializable {
|
||||
|
||||
/**
|
||||
* List of observers registered to receive updates when the game state changes.
|
||||
*
|
||||
* <p>The list is marked as {@code transient} because observers should not be
|
||||
* serialized with the game model.
|
||||
*/
|
||||
private transient List<Observer> observers = new ArrayList<>(); // transient! non serializzare
|
||||
|
||||
|
||||
public void addObserver(Observer observer) {
|
||||
observers.add(observer);
|
||||
}
|
||||
|
||||
|
||||
private void notifyObservers() {
|
||||
for (Observer o : observers) {
|
||||
o.update(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of players participating in the game.
|
||||
*
|
||||
@@ -250,6 +234,16 @@ public class Game implements Serializable {
|
||||
orderLogicCard=new Order5(playersList);
|
||||
break;
|
||||
}
|
||||
for(Player player : playersList)
|
||||
{
|
||||
switch(orderLogicCard.getPosition(player.getUserName()))
|
||||
{
|
||||
case 0: player.addFood(2); break;
|
||||
case 1,2: player.addFood(3); break;
|
||||
case 3,4: player.addFood(4); break;
|
||||
}
|
||||
|
||||
}
|
||||
currentState.PlayerUpdate(orderLogicCard.pull(),null);
|
||||
currentState.GameStageUpdate(GameStages.SLOT_CHOICE);
|
||||
}
|
||||
@@ -282,6 +276,10 @@ public class Game implements Serializable {
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(slotPlayerEntry.getKey().getSlotId()=='A')
|
||||
{
|
||||
player.addFood(3);
|
||||
}
|
||||
slotMap.put(slotPlayerEntry.getKey(),player);
|
||||
nextPlayerSetup();
|
||||
return true;
|
||||
@@ -306,7 +304,7 @@ public class Game implements Serializable {
|
||||
public boolean DrawUpperTribeCardByIndex(Player player,int cardIndex) {
|
||||
if( cardIndex<0 || cardIndex >=board.upperListTribe.size())
|
||||
return false;
|
||||
if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS)
|
||||
if(currentState.getGameStage()!= GameStages.RES_ACTIONS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -342,7 +340,7 @@ public class Game implements Serializable {
|
||||
* @return {@code true} if the skip succeeds, {@code false} otherwise.
|
||||
*/
|
||||
public boolean SkipUpperDrawing(Player player) {
|
||||
if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS)
|
||||
if(currentState.getGameStage()!= GameStages.RES_ACTIONS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -373,7 +371,7 @@ public class Game implements Serializable {
|
||||
* @return {@code true} if the skip succeeds, {@code false} otherwise.
|
||||
*/
|
||||
public boolean SkipLowerDrawing(Player player) {
|
||||
if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS)
|
||||
if(currentState.getGameStage()!= GameStages.RES_ACTIONS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -407,7 +405,7 @@ public class Game implements Serializable {
|
||||
public boolean DrawLowerTribeCardByIndex(Player player, int cardIndex) {
|
||||
if( cardIndex<0 || cardIndex >=board.lowerListTribe.size())
|
||||
return false;
|
||||
if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS)
|
||||
if(currentState.getGameStage()!= GameStages.RES_ACTIONS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -448,7 +446,7 @@ public class Game implements Serializable {
|
||||
public boolean DrawUpperBuildingCardByIndex(Player player,int cardIndex) {
|
||||
if( cardIndex<0 || cardIndex >=board.upperListBuilding.size())
|
||||
return false;
|
||||
if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS)
|
||||
if(currentState.getGameStage()!= GameStages.RES_ACTIONS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -487,7 +485,7 @@ public class Game implements Serializable {
|
||||
public boolean DrawLowerBuildingCardByIndex(Player player,int cardIndex) {
|
||||
if( cardIndex<0 || cardIndex >=board.lowerListBuilding.size())
|
||||
return false;
|
||||
if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS)
|
||||
if(currentState.getGameStage()!= GameStages.RES_ACTIONS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -532,7 +530,7 @@ public class Game implements Serializable {
|
||||
* @return {@code true} if the operation succeeds, {@code false} otherwise.
|
||||
*/
|
||||
public boolean PickOptionalTribeCardByIndex(Player player,int cardIndex) {
|
||||
if(currentState.getGameStage() != GameStages.OPTIONAL_CARD_EFFECT){
|
||||
if(currentState.getGameStage() != GameStages.OPT_CARD_E){
|
||||
return false;
|
||||
}
|
||||
if(!player.equals(currentState.getCurrentPlayer())){
|
||||
@@ -567,7 +565,7 @@ public class Game implements Serializable {
|
||||
* @return {@code true} if the operation succeeds, {@code false} otherwise.
|
||||
*/
|
||||
public boolean PickOptionalBuildingCard(Player player, int cardIndex) {
|
||||
if(currentState.getGameStage() != GameStages.OPTIONAL_CARD_EFFECT){
|
||||
if(currentState.getGameStage() != GameStages.OPT_CARD_E){
|
||||
return false;
|
||||
}
|
||||
if(!player.equals(currentState.getCurrentPlayer())){
|
||||
@@ -599,7 +597,7 @@ public class Game implements Serializable {
|
||||
* @return {@code true} if the operation succeeds, {@code false} otherwise.
|
||||
*/
|
||||
public boolean NoOptionalCard(Player player) {
|
||||
if(currentState.getGameStage() != GameStages.OPTIONAL_CARD_EFFECT){
|
||||
if(currentState.getGameStage() != GameStages.OPT_CARD_E){
|
||||
return false;
|
||||
}
|
||||
if(!player.equals(currentState.getCurrentPlayer())){
|
||||
@@ -638,7 +636,7 @@ public class Game implements Serializable {
|
||||
currentState.PlayerUpdate(tempPlayer, null);
|
||||
return;
|
||||
}
|
||||
currentState.GameStageUpdate(GameStages.RESOLVING_ACTIONS);
|
||||
currentState.GameStageUpdate(GameStages.RES_ACTIONS);
|
||||
for (Slot s : slotMap.keySet()) {
|
||||
if (slotMap.get(s) != null) {
|
||||
currentState.PlayerUpdate(slotMap.get(s), s);
|
||||
@@ -654,7 +652,7 @@ public class Game implements Serializable {
|
||||
return;
|
||||
|
||||
}
|
||||
if(GameStages.RESOLVING_ACTIONS==currentState.getGameStage()) {
|
||||
if(GameStages.RES_ACTIONS ==currentState.getGameStage()) {
|
||||
orderLogicCard.push(currentState.getCurrentPlayer());
|
||||
slotMap.put(currentState.getSlot(), null);
|
||||
for (Slot s : slotMap.keySet()) {
|
||||
@@ -673,9 +671,9 @@ public class Game implements Serializable {
|
||||
}
|
||||
if(slotMap.values().stream().allMatch(v -> v == null))
|
||||
{
|
||||
currentState.GameStageUpdate(GameStages.OPTIONAL_CARD_EFFECT);
|
||||
currentState.GameStageUpdate(GameStages.OPT_CARD_E);
|
||||
HashMap<Player,Integer> optional=new LinkedHashMap<>();
|
||||
for (Player p : playersList) {
|
||||
for (Player p : orderLogicCard.players) {
|
||||
int tempCount=(int)p.buildingCards.stream().filter(x->x.getEffectId()==12).count();
|
||||
if(tempCount>0)
|
||||
{
|
||||
@@ -694,14 +692,13 @@ public class Game implements Serializable {
|
||||
return;
|
||||
}
|
||||
|
||||
currentState.GameStageUpdate(GameStages.RESOLVING_EVENT);
|
||||
currentState.GameStageUpdate(GameStages.RES_EVENT);
|
||||
|
||||
if (currentState.getRound() < 10) {
|
||||
nextRound();
|
||||
currentState.PlayerUpdate(orderLogicCard.pull(), null);
|
||||
currentState.GameStageUpdate(GameStages.SLOT_CHOICE);
|
||||
} else {
|
||||
EventResolution();
|
||||
currentState.GameStageUpdate(GameStages.ENDING);
|
||||
endGame();
|
||||
}
|
||||
@@ -710,7 +707,7 @@ public class Game implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
if (GameStages.OPTIONAL_CARD_EFFECT == currentState.getGameStage()) {
|
||||
if (GameStages.OPT_CARD_E == currentState.getGameStage()) {
|
||||
Player optionalPlayer = OptionalCardQueue.poll();
|
||||
|
||||
if (optionalPlayer != null) {
|
||||
@@ -718,14 +715,13 @@ public class Game implements Serializable {
|
||||
return;
|
||||
}
|
||||
|
||||
currentState.GameStageUpdate(GameStages.RESOLVING_EVENT);
|
||||
currentState.GameStageUpdate(GameStages.RES_EVENT);
|
||||
|
||||
if (currentState.getRound() < 10) {
|
||||
nextRound();
|
||||
currentState.PlayerUpdate(orderLogicCard.pull(), null);
|
||||
currentState.GameStageUpdate(GameStages.SLOT_CHOICE);
|
||||
} else {
|
||||
EventResolution();
|
||||
currentState.GameStageUpdate(GameStages.ENDING);
|
||||
endGame();
|
||||
}
|
||||
@@ -768,7 +764,7 @@ public class Game implements Serializable {
|
||||
*/
|
||||
private void EventResolution() {
|
||||
|
||||
if(currentState.getGameStage()!= GameStages.RESOLVING_EVENT)
|
||||
if(currentState.getGameStage()!= GameStages.RES_EVENT)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -818,6 +814,28 @@ public class Game implements Serializable {
|
||||
* and updating the game stage to {@code ENDED}.
|
||||
*/
|
||||
private void endGame() {
|
||||
Queue<EventCard> events;
|
||||
events=Stream.concat(board.lowerListTribe.stream().filter(TribeCard::IsEventCard),board.upperListTribe.stream().filter(TribeCard::IsEventCard)).map(x->((EventCard)x)).collect(Collectors.toCollection(LinkedList::new));
|
||||
ArrayList<EventCard>sustenance=events.stream().filter(x->x.getType().equals(EventType.SUSTENANCE)).collect(Collectors.toCollection(ArrayList::new));
|
||||
events.removeAll(sustenance);
|
||||
events.forEach(event->event.activateEvent(playersList));
|
||||
sustenance.forEach(event->event.activateEvent(playersList));
|
||||
|
||||
playersList.forEach(p->{
|
||||
int temp= p.builders.stream().mapToInt(Builder::getPrestigeValue).sum();
|
||||
p.addPrestige(temp);
|
||||
});
|
||||
playersList.forEach(p->{
|
||||
int temp=(int) p.inventors.stream().mapToInt(Inventor::Icon).distinct().count();
|
||||
p.addPrestige(temp*p.getNType(CharacterType.INVENTOR));
|
||||
});
|
||||
playersList.forEach(p->{
|
||||
p.addPrestige(10 * (p.getNType(CharacterType.ARTIST)/2));
|
||||
});
|
||||
playersList.forEach(p->{
|
||||
int temp= p.buildingCards.stream().mapToInt(BuildingCard::getPrestigeValue).sum();
|
||||
p.addPrestige(temp);
|
||||
});
|
||||
playersList.forEach(
|
||||
p -> p.buildingCards.stream().filter(x -> x.getEffectType() == EffectType.FINAL).
|
||||
forEach(x -> x.applyEffect(p))
|
||||
|
||||
Reference in New Issue
Block a user