Update: Partial Implementation Game Class

This commit is contained in:
rubenpirreram
2026-03-22 19:53:59 +01:00
parent 3a75231035
commit 43d90ca86d
7 changed files with 167 additions and 5 deletions
@@ -2,18 +2,24 @@ package it.polimi.ingsw.gc14.Model;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
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.CurrentState;
import it.polimi.ingsw.gc14.Model.Orders.Order2;
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;
public class Game {
private List<Slot> slotList;
private Queue<TribeCard> tribeDeck;
private List<TribeCard> upperListTribe;
private List<TribeCard> lowerListTribe;
@@ -21,12 +27,20 @@ public class Game {
private List<BuildingCard> lowerListBuilding;
private ArrayList<Player> playersList;
private CurrentState currentState;
private HashMap<Slot,Player> slotMap ;
private int nPlayers;
private OrderLogicCard orderLogicCard;
public Game(int nPlayers) {
this.nPlayers = nPlayers;
this.slotList = DecksCreator.loadSlotDeck().stream().filter(x->x.getNMinPlayer()<=nPlayers).sorted().toList();
slotMap = new LinkedHashMap<>();
for(Slot s :DecksCreator.loadSlotDeck().stream().filter(x->x.getNMinPlayer()<=nPlayers).sorted().toList())
{
slotMap.put(s,null);
}
this.tribeDeck= getTribeDeck(nPlayers);
ArrayList<BuildingCard> buildingDeck = new ArrayList<>(DecksCreator.loadBuildingDeckByEra(1));
Collections.shuffle(buildingDeck);
@@ -34,7 +48,7 @@ public class Game {
this.upperListBuilding= buildingDeck.subList(0,1);
else
this.upperListBuilding= buildingDeck.subList(0,2);
currentState= new CurrentState();
upperListTribe = new ArrayList<>();
lowerListTribe = new ArrayList<>();
lowerListBuilding = new ArrayList<>();
@@ -75,8 +89,135 @@ public class Game {
TribeCard tempCard = tribeDeck.remove();
upperListTribe.add(tempCard);
}
currentState.GameStageUpdate(GameStages.SLOT_CHOICE);
currentState.PlayerUpdate(orderLogicCard.pull(),null);
}
public boolean SlotChoice(Player player, Slot slot)
{
if(currentState.getGameStage()!= GameStages.SLOT_CHOICE)
{
return false;
}
if(player.equals(currentState.getCurrentPlayer()))
{
if(slotMap.get(slot)!=null)
{
return false;
}
if(!slotList.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 : slotList)
{
if(slotMap.get(s)!=null)
{
currentState.PlayerUpdate(slotMap.get(s),s);
}
}
}
return true;
}
return false;
}
public boolean DrawTribeCard(Player player,TribeCard tribeCard)
{
if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS)
{
return false;
}
if(player.equals(currentPlayer))
{
}
return false;
}
public boolean DrawUpperBuildingCard(Player player,BuildingCard buildingCard)
{
if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS)
{
return false;
}
if(!player.equals(currentState.getCurrentPlayer()))
{
return false;
}
if(!upperListBuilding.contains(buildingCard))
{
return false;
}
if(buildingCard.buy(player))
currentState.UpperDrawn();
else
return false;
if(currentState.getNUpper()==currentState.getSlot().getNUpper()&& currentState.getNLower()==currentState.getSlot().getNLower())
{
}
return false;
}
private void nextPlayerSetup()
{
if(GameStages.RESOLVING_ACTIONS==currentState.getGameStage()) {
orderLogicCard.push(currentState.getCurrentPlayer());
slotMap.put(currentState.getSlot(), null);
for (Slot s : slotList) {
if (slotMap.get(s) != null) {
currentState.PlayerUpdate(slotMap.get(s), s);
}
}
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);
}
}
}
private void BuildingEffect12(List<Player> playerList)
{
}
private void EventResolution()
{
if(currentState.getGameStage()!= GameStages.RESOLVING_EVENT)
{
return;
}
Queue<EventCard> events;
events=lowerListTribe.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);
for(EventCard event:events)
{
event.activateEvent(playersList);
}
for(EventCard e : sustenance)
{
e.activateEvent(playersList);
}
}
private void nextRound()
{
EventResolution();
}
private Queue<TribeCard> getTribeDeck(int nPlayers)
{
@@ -94,13 +235,19 @@ public class Game {
tribeDeck_temp.add(new ShamanicRitual(3,15,7));
return tribeDeck_temp;
}
public void addPlayer(Player player)
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, RESOLVING_EVENT,ENDING,ENDED
WAITING,SLOT_CHOICE, RESOLVING_ACTIONS,BUILDING_EFFECT_12, RESOLVING_EVENT,ENDING,ENDED
}
@@ -1,5 +1,7 @@
package it.polimi.ingsw.gc14.Model;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import java.util.*;
public abstract class OrderLogicCard {
@@ -20,4 +22,10 @@ public abstract class OrderLogicCard {
return players.peek();
}
protected abstract void effect(Player player, int index) throws IndexOutOfBoundsException;
protected void buildingEffect(Player player)
{
for(BuildingCard b : player.buildingCards.stream().filter(x->x.getEffectId()==3).toList())
player.addFood(1);
}
}
@@ -1,5 +1,6 @@
package it.polimi.ingsw.gc14.Model.Orders;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.OrderLogicCard;
import it.polimi.ingsw.gc14.Model.Player;
import java.util.*;
@@ -18,10 +19,11 @@ public class Order2 extends OrderLogicCard {
if(index==0)
{
player.addFood(1);
buildingEffect(player);
return;
}
if(index==1){
if(player.removeFood(1)){
if(!player.removeFood(1)){
player.removePrestige(2);
return;
}
@@ -19,6 +19,7 @@ public class Order3 extends OrderLogicCard {
if(index==0)
{
player.addFood(2);
buildingEffect(player);
return;
}
if(index==2){
@@ -19,11 +19,13 @@ public class Order4 extends OrderLogicCard {
if(index==0)
{
player.addFood(2);
buildingEffect(player);
return;
}
if(index==1)
{
player.addFood(1);
buildingEffect(player);
return;
}
if(index==3){
@@ -19,11 +19,13 @@ public class Order5 extends OrderLogicCard {
if(index==0)
{
player.addFood(3);
buildingEffect(player);
return;
}
if(index==1)
{
player.addFood(1);
buildingEffect(player);
return;
}
if(index==4){