Updated: Game.java nextPlayer changed

This commit is contained in:
rubenpirreram
2026-03-27 16:49:44 +01:00
parent ce1ec5b1cd
commit e4a0e49182
2 changed files with 80 additions and 47 deletions
@@ -5,8 +5,6 @@ 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.EventCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventType;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events.ShamanicRitual;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events.Sustenance;
import it.polimi.ingsw.gc14.Model.GamePackage.Board;
import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState;
import it.polimi.ingsw.gc14.Model.Orders.Order2;
@@ -14,7 +12,6 @@ import it.polimi.ingsw.gc14.Model.Orders.Order3;
import it.polimi.ingsw.gc14.Model.Orders.Order4;
import it.polimi.ingsw.gc14.Model.Orders.Order5;
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
import javafx.event.Event;
import java.util.*;
import java.util.stream.Collectors;
@@ -25,8 +22,10 @@ public class Game {
private CurrentState currentState;
private HashMap<Slot,Player> slotMap;
private int nPlayers;
private Queue<Player> OptionalCardQueue;
private OrderLogicCard orderLogicCard;
private Board board;
public Game(int nPlayers) {
this.nPlayers = nPlayers;
board=new Board(nPlayers);
@@ -37,6 +36,20 @@ public class Game {
}
currentState= new CurrentState();
playersList = new ArrayList<>();
OptionalCardQueue = new LinkedList<>();
}
public boolean addPlayer(Player player) {
if(currentState.getGameStage()!= GameStages.WAITING)
return false;
playersList.add(player);
if(playersList.size()>=nPlayers)
{
init();
return true;
}
return false;
}
public void init() {
@@ -58,37 +71,29 @@ public class Game {
currentState.GameStageUpdate(GameStages.SLOT_CHOICE);
}
//region Cotroller Methods
public boolean SlotChoice(Player player, Slot slot) {
if(currentState.getGameStage()!= GameStages.SLOT_CHOICE)
{
return false;
}
if(player.equals(currentState.getCurrentPlayer()))
if(!player.equals(currentState.getCurrentPlayer()))
{
if(slotMap.get(slot)!=null)
{
return false;
}
if(!board.getSlotList().contains(slot))
{
return false;
}
slotMap.put(slot,player);
currentState.PlayerUpdate(orderLogicCard.pull(),null);
if(currentState.getCurrentPlayer()==null)
{
currentState.GameStageUpdate(GameStages.RESOLVING_ACTIONS);
for(Slot s : board.getSlotList())
{
if(slotMap.get(s)!=null)
{
currentState.PlayerUpdate(slotMap.get(s),s);
}
}
}
return true;
return false;
}
return false;
if(slotMap.get(slot)!=null)
{
return false;
}
if(!board.getSlotList().contains(slot))
{
return false;
}
slotMap.put(slot,player);
nextPlayerSetup();
return true;
}
//region Drawing Methods
@@ -201,7 +206,28 @@ public class Game {
//endregion
//region Optional Card Methods
public boolean PickOptionalTribeCard(Player player,TribeCard tribeCard) {
return true;
}
public boolean PickOptionalBuildingCard(Player player, BuildingCard buildingCard) {
return true;
}
public boolean NoOptionalCard(Player player) {
return true;
}
//endregion
//endregion
private void nextPlayerSetup() {
if(GameStages.SLOT_CHOICE==currentState.getGameStage()) {
currentState.PlayerUpdate(orderLogicCard.pull(), null);
if(currentState.getCurrentPlayer()==null)
{
currentState.GameStageUpdate(GameStages.RESOLVING_ACTIONS);
}
}
if(GameStages.RESOLVING_ACTIONS==currentState.getGameStage()) {
orderLogicCard.push(currentState.getCurrentPlayer());
slotMap.put(currentState.getSlot(), null);
@@ -212,15 +238,36 @@ public class Game {
}
if(slotMap.values().stream().allMatch(v -> v == null))
{
currentState.GameStageUpdate(GameStages.BUILDING_EFFECT_12);
BuildingEffect12( playersList.stream().filter(x->x.buildingCards.stream().anyMatch(y->y.getEffectId()==12)).toList());
//currentState.PlayerUpdate(orderLogicCard.pull(),null);
currentState.GameStageUpdate(GameStages.OPTIONAL_CARD_EFFECT);
OptionalCardQueue=(playersList.stream().filter(x->x.buildingCards.stream().anyMatch(y->y.getEffectId()==12)).collect(Collectors.toCollection(LinkedList::new)));
currentState.PlayerUpdate(OptionalCardQueue.remove(), null);
if(currentState.getCurrentPlayer()==null)
{
currentState.GameStageUpdate(GameStages.RESOLVING_EVENT);
if(currentState.getRound()<10)
{
nextRound();
}
else
{
EventResolution();
currentState.GameStageUpdate(GameStages.ENDING);
endGame();
}
return;
}
}
}
if(GameStages.OPTIONAL_CARD_EFFECT==currentState.getGameStage()) {
currentState.PlayerUpdate(OptionalCardQueue.remove(), null);
if(currentState.getCurrentPlayer()==null)
{
currentState.GameStageUpdate(GameStages.RESOLVING_EVENT);
}
}
}
private void BuildingEffect12(List<Player> playerList){
}
private void EventResolution() {
@@ -242,7 +289,6 @@ public class Game {
e.activateEvent(playersList);
}
}
private void nextRound() {
@@ -265,19 +311,6 @@ public class Game {
public boolean addPlayer(Player player) {
if(currentState.getGameStage()!= GameStages.WAITING)
return false;
playersList.add(player);
if(playersList.size()>=nPlayers)
{
init();
return true;
}
return false;
}
@@ -1,5 +1,5 @@
package it.polimi.ingsw.gc14.Model.GamePackage;
public enum GameStages {
WAITING,SLOT_CHOICE, RESOLVING_ACTIONS,BUILDING_EFFECT_12, RESOLVING_EVENT,ENDING,ENDED
WAITING,SLOT_CHOICE, RESOLVING_ACTIONS, OPTIONAL_CARD_EFFECT, RESOLVING_EVENT,ENDING,ENDED
}