Add: Board Implementation
This commit is contained in:
@@ -6,6 +6,7 @@ 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.EventType;
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events.ShamanicRitual;
|
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.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.GamePackage.CurrentState;
|
||||||
import it.polimi.ingsw.gc14.Model.Orders.Order2;
|
import it.polimi.ingsw.gc14.Model.Orders.Order2;
|
||||||
import it.polimi.ingsw.gc14.Model.Orders.Order3;
|
import it.polimi.ingsw.gc14.Model.Orders.Order3;
|
||||||
@@ -18,44 +19,26 @@ import java.util.*;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Game {
|
public class Game {
|
||||||
private List<Slot> slotList;
|
|
||||||
|
|
||||||
private Queue<TribeCard> tribeDeck;
|
|
||||||
private List<TribeCard> upperListTribe;
|
|
||||||
private List<TribeCard> lowerListTribe;
|
|
||||||
private List<BuildingCard> upperListBuilding;
|
|
||||||
private List<BuildingCard> lowerListBuilding;
|
|
||||||
private ArrayList<Player> playersList;
|
private ArrayList<Player> playersList;
|
||||||
private OrderLogicCard orderLogicCard;
|
|
||||||
|
|
||||||
private CurrentState currentState;
|
private CurrentState currentState;
|
||||||
private HashMap<Slot,Player> slotMap;
|
private HashMap<Slot,Player> slotMap;
|
||||||
private int nPlayers;
|
private int nPlayers;
|
||||||
|
private OrderLogicCard orderLogicCard;
|
||||||
|
private Board board;
|
||||||
public Game(int nPlayers) {
|
public Game(int nPlayers) {
|
||||||
this.nPlayers = nPlayers;
|
this.nPlayers = nPlayers;
|
||||||
this.slotList = DecksCreator.loadSlotDeck().stream().filter(x->x.getNMinPlayer()<=nPlayers).sorted().toList();
|
board=new Board(nPlayers);
|
||||||
slotMap = new LinkedHashMap<>();
|
slotMap = new LinkedHashMap<>();
|
||||||
for(Slot s :DecksCreator.loadSlotDeck().stream().filter(x->x.getNMinPlayer()<=nPlayers).sorted().toList())
|
for(Slot s :board.getSlotList())
|
||||||
{
|
{
|
||||||
slotMap.put(s,null);
|
slotMap.put(s,null);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.tribeDeck= getTribeDeck(nPlayers);
|
|
||||||
ArrayList<BuildingCard> buildingDeck = new ArrayList<>(DecksCreator.loadBuildingDeckByEra(1));
|
|
||||||
Collections.shuffle(buildingDeck);
|
|
||||||
if(nPlayers==2)
|
|
||||||
this.upperListBuilding= buildingDeck.subList(0,1);
|
|
||||||
else
|
|
||||||
this.upperListBuilding= buildingDeck.subList(0,2);
|
|
||||||
currentState= new CurrentState();
|
currentState= new CurrentState();
|
||||||
upperListTribe = new ArrayList<>();
|
|
||||||
lowerListTribe = new ArrayList<>();
|
|
||||||
lowerListBuilding = new ArrayList<>();
|
|
||||||
playersList = new ArrayList<>();
|
playersList = new ArrayList<>();
|
||||||
}
|
}
|
||||||
public void init() {
|
public void init() {
|
||||||
|
|
||||||
switch (nPlayers) {
|
switch (nPlayers) {
|
||||||
case 2:
|
case 2:
|
||||||
orderLogicCard=new Order2(playersList);
|
orderLogicCard=new Order2(playersList);
|
||||||
@@ -70,27 +53,8 @@ public class Game {
|
|||||||
orderLogicCard=new Order5(playersList);
|
orderLogicCard=new Order5(playersList);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i=0;i<nPlayers+1;i++)
|
|
||||||
{
|
|
||||||
TribeCard tempCard = tribeDeck.remove();
|
|
||||||
if(tempCard.IsEventCard())
|
|
||||||
{
|
|
||||||
upperListTribe.add(tempCard);
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lowerListTribe.add(tempCard);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(int i=upperListTribe.size();i<nPlayers+5;i++)
|
|
||||||
{
|
|
||||||
TribeCard tempCard = tribeDeck.remove();
|
|
||||||
upperListTribe.add(tempCard);
|
|
||||||
}
|
|
||||||
currentState.GameStageUpdate(GameStages.SLOT_CHOICE);
|
|
||||||
currentState.PlayerUpdate(orderLogicCard.pull(),null);
|
currentState.PlayerUpdate(orderLogicCard.pull(),null);
|
||||||
|
currentState.GameStageUpdate(GameStages.SLOT_CHOICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean SlotChoice(Player player, Slot slot) {
|
public boolean SlotChoice(Player player, Slot slot) {
|
||||||
@@ -104,7 +68,7 @@ public class Game {
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!slotList.contains(slot))
|
if(!board.getSlotList().contains(slot))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -113,7 +77,7 @@ public class Game {
|
|||||||
if(currentState.getCurrentPlayer()==null)
|
if(currentState.getCurrentPlayer()==null)
|
||||||
{
|
{
|
||||||
currentState.GameStageUpdate(GameStages.RESOLVING_ACTIONS);
|
currentState.GameStageUpdate(GameStages.RESOLVING_ACTIONS);
|
||||||
for(Slot s : slotList)
|
for(Slot s : board.getSlotList())
|
||||||
{
|
{
|
||||||
if(slotMap.get(s)!=null)
|
if(slotMap.get(s)!=null)
|
||||||
{
|
{
|
||||||
@@ -161,12 +125,15 @@ public class Game {
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!upperListBuilding.contains(buildingCard))
|
if(!board.containsUpperBuildingCard(buildingCard))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(buildingCard.buy(player))
|
if(buildingCard.buy(player))
|
||||||
|
{
|
||||||
currentState.UpperDrawn();
|
currentState.UpperDrawn();
|
||||||
|
board.removeUpperBuildingCard(buildingCard);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
if(currentState.getNUpper()==currentState.getSlot().getNUpper()&& currentState.getNLower()==currentState.getSlot().getNLower())
|
if(currentState.getNUpper()==currentState.getSlot().getNUpper()&& currentState.getNLower()==currentState.getSlot().getNLower())
|
||||||
@@ -184,12 +151,15 @@ public class Game {
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!upperListBuilding.contains(buildingCard))
|
if(!board.containsLowerBuildingCard(buildingCard))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(buildingCard.buy(player))
|
if(buildingCard.buy(player))
|
||||||
|
{
|
||||||
currentState.UpperDrawn();
|
currentState.UpperDrawn();
|
||||||
|
board.removeLowerBuildingCard(buildingCard);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
if(currentState.getNUpper()==currentState.getSlot().getNUpper()&& currentState.getNLower()==currentState.getSlot().getNLower())
|
if(currentState.getNUpper()==currentState.getSlot().getNUpper()&& currentState.getNLower()==currentState.getSlot().getNLower())
|
||||||
@@ -206,7 +176,7 @@ public class Game {
|
|||||||
if(GameStages.RESOLVING_ACTIONS==currentState.getGameStage()) {
|
if(GameStages.RESOLVING_ACTIONS==currentState.getGameStage()) {
|
||||||
orderLogicCard.push(currentState.getCurrentPlayer());
|
orderLogicCard.push(currentState.getCurrentPlayer());
|
||||||
slotMap.put(currentState.getSlot(), null);
|
slotMap.put(currentState.getSlot(), null);
|
||||||
for (Slot s : slotList) {
|
for (Slot s : board.getSlotList()) {
|
||||||
if (slotMap.get(s) != null) {
|
if (slotMap.get(s) != null) {
|
||||||
currentState.PlayerUpdate(slotMap.get(s), s);
|
currentState.PlayerUpdate(slotMap.get(s), s);
|
||||||
}
|
}
|
||||||
@@ -230,9 +200,7 @@ public class Game {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Queue<EventCard> events;
|
Queue<EventCard> events;
|
||||||
events=lowerListTribe.stream().filter(TribeCard::IsEventCard).map(x->(EventCard)x).collect(Collectors.toCollection(LinkedList::new));
|
events=board.getPendingEvents();
|
||||||
|
|
||||||
|
|
||||||
ArrayList<EventCard>sustenance=events.stream().filter(x->x.getType().equals(EventType.SUSTENANCE)).collect(Collectors.toCollection(ArrayList::new));
|
ArrayList<EventCard>sustenance=events.stream().filter(x->x.getType().equals(EventType.SUSTENANCE)).collect(Collectors.toCollection(ArrayList::new));
|
||||||
events.removeAll(sustenance);
|
events.removeAll(sustenance);
|
||||||
for(EventCard event:events)
|
for(EventCard event:events)
|
||||||
@@ -250,26 +218,21 @@ public class Game {
|
|||||||
private void nextRound() {
|
private void nextRound() {
|
||||||
|
|
||||||
EventResolution();
|
EventResolution();
|
||||||
|
if(currentState.getRound()==10)
|
||||||
|
{
|
||||||
|
currentState.GameStageUpdate(GameStages.ENDING);
|
||||||
|
endGame();
|
||||||
|
}
|
||||||
|
if(currentState.getEra()!= board.nextRound())
|
||||||
|
currentState.EraUpdate();
|
||||||
|
currentState.RoundUpdate();
|
||||||
|
|
||||||
}
|
}
|
||||||
private void endGame() {
|
private void endGame() {
|
||||||
|
//DO SOMETHING THEN
|
||||||
|
currentState.GameStageUpdate(GameStages.ENDED);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
private Queue<TribeCard> getTribeDeck(int nPlayers) {
|
|
||||||
ArrayList<TribeCard> era1= DecksCreator.loadTribeDeckByEra(1).stream().filter(x->x.getNMin()<=nPlayers).collect(Collectors.toCollection(ArrayList::new));
|
|
||||||
List<TribeCard> era2= DecksCreator.loadTribeDeckByEra(2).stream().filter(x->x.getNMin()<=nPlayers).collect(Collectors.toCollection(ArrayList::new));
|
|
||||||
List<TribeCard> era3= DecksCreator.loadTribeDeckByEra(3).stream().filter(x->x.getNMin()<=nPlayers).collect(Collectors.toCollection(ArrayList::new));
|
|
||||||
Collections.shuffle(era1);
|
|
||||||
Collections.shuffle(era2);
|
|
||||||
Collections.shuffle(era3);
|
|
||||||
Queue<TribeCard> tribeDeck_temp=new LinkedList<>();
|
|
||||||
tribeDeck_temp.addAll(era1);
|
|
||||||
tribeDeck_temp.addAll(era2);
|
|
||||||
tribeDeck_temp.addAll(era3);
|
|
||||||
tribeDeck_temp.add(new Sustenance(3,3));
|
|
||||||
tribeDeck_temp.add(new ShamanicRitual(3,15,7));
|
|
||||||
return tribeDeck_temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,168 @@
|
|||||||
|
package it.polimi.ingsw.gc14.Model.GamePackage;
|
||||||
|
|
||||||
|
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.Events.ShamanicRitual;
|
||||||
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events.Sustenance;
|
||||||
|
import it.polimi.ingsw.gc14.Model.DecksCreator;
|
||||||
|
import it.polimi.ingsw.gc14.Model.OrderLogicCard;
|
||||||
|
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.Slot;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class Board {
|
||||||
|
private List<Slot> slotList;
|
||||||
|
private Queue<TribeCard> tribeDeck;
|
||||||
|
private List<TribeCard> upperListTribe;
|
||||||
|
private List<TribeCard> lowerListTribe;
|
||||||
|
private List<BuildingCard> upperListBuilding;
|
||||||
|
private List<BuildingCard> lowerListBuilding;
|
||||||
|
private int nTotem;
|
||||||
|
private int era;
|
||||||
|
public List<Slot> getSlotList(){//Da chiedere
|
||||||
|
return slotList.stream().map(x->new Slot(x.getSlotId())).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Board(int nTotem) {
|
||||||
|
this.nTotem = nTotem;
|
||||||
|
this.slotList = DecksCreator.loadSlotDeck().stream().filter(x->x.getNMinPlayer()<=nTotem).sorted(Comparator.comparingInt(Slot::getSlotId)).toList();
|
||||||
|
upperListTribe=new ArrayList<>();
|
||||||
|
lowerListTribe=new ArrayList<>();
|
||||||
|
lowerListBuilding=new ArrayList<>();
|
||||||
|
tribeDeck=getTribeDeck(nTotem);
|
||||||
|
era=1;
|
||||||
|
for(int i=0;i<nTotem+1;i++)
|
||||||
|
{
|
||||||
|
TribeCard tempCard = tribeDeck.remove();
|
||||||
|
if(tempCard.IsEventCard())
|
||||||
|
{
|
||||||
|
upperListTribe.add(tempCard);
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lowerListTribe.add(tempCard);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(int i=upperListTribe.size();i<nTotem+5;i++)
|
||||||
|
{
|
||||||
|
TribeCard tempCard = tribeDeck.remove();
|
||||||
|
upperListTribe.add(tempCard);
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<BuildingCard> buildingDeck = new ArrayList<>(DecksCreator.loadBuildingDeckByEra(1));
|
||||||
|
Collections.shuffle(buildingDeck);
|
||||||
|
if(nTotem==2)
|
||||||
|
upperListBuilding= buildingDeck.subList(0,1);
|
||||||
|
else
|
||||||
|
upperListBuilding= buildingDeck.subList(0,2);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private Queue<TribeCard> getTribeDeck(int nPlayers) {
|
||||||
|
ArrayList<TribeCard> era1= DecksCreator.loadTribeDeckByEra(1).stream().filter(x->x.getNMin()<=nPlayers).collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
List<TribeCard> era2= DecksCreator.loadTribeDeckByEra(2).stream().filter(x->x.getNMin()<=nPlayers).collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
List<TribeCard> era3= DecksCreator.loadTribeDeckByEra(3).stream().filter(x->x.getNMin()<=nPlayers).collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
Collections.shuffle(era1);
|
||||||
|
Collections.shuffle(era2);
|
||||||
|
Collections.shuffle(era3);
|
||||||
|
Queue<TribeCard> tribeDeck_temp=new LinkedList<>();
|
||||||
|
tribeDeck_temp.addAll(era1);
|
||||||
|
tribeDeck_temp.addAll(era2);
|
||||||
|
tribeDeck_temp.addAll(era3);
|
||||||
|
tribeDeck_temp.add(new Sustenance(3,3));
|
||||||
|
tribeDeck_temp.add(new ShamanicRitual(3,15,7));
|
||||||
|
return tribeDeck_temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Queue<EventCard> getPendingEvents(){
|
||||||
|
return lowerListTribe.stream().filter(TribeCard::IsEventCard).map(x->(EventCard)x).collect(Collectors.toCollection(LinkedList::new));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean containsUpperTribeCard(TribeCard tribeCard) {
|
||||||
|
return upperListTribe.contains(tribeCard);
|
||||||
|
}
|
||||||
|
public boolean removeUpperTribeCard(TribeCard tribeCard) {
|
||||||
|
return upperListTribe.remove(tribeCard);
|
||||||
|
}
|
||||||
|
public boolean containsLowerTribeCard(TribeCard tribeCard) {
|
||||||
|
return upperListTribe.contains(tribeCard);
|
||||||
|
}
|
||||||
|
public boolean removeLowerTribeCard(TribeCard tribeCard) {
|
||||||
|
return upperListTribe.remove(tribeCard);
|
||||||
|
}
|
||||||
|
public boolean containsUpperBuildingCard(BuildingCard buildingCard) {
|
||||||
|
return upperListTribe.contains(buildingCard);
|
||||||
|
}
|
||||||
|
public boolean removeUpperBuildingCard(BuildingCard buildingCard) {
|
||||||
|
return upperListTribe.remove(buildingCard);
|
||||||
|
}
|
||||||
|
public boolean containsLowerBuildingCard(BuildingCard buildingCard) {
|
||||||
|
return upperListTribe.contains(buildingCard);
|
||||||
|
}
|
||||||
|
public boolean removeLowerBuildingCard(BuildingCard buildingCard) {
|
||||||
|
return upperListTribe.remove(buildingCard);
|
||||||
|
}
|
||||||
|
public int nextRound()
|
||||||
|
{
|
||||||
|
lowerListTribe.clear();
|
||||||
|
lowerListTribe.addAll(upperListTribe);
|
||||||
|
|
||||||
|
for(int i=0;i<nTotem+4;i++)
|
||||||
|
{
|
||||||
|
TribeCard tempCard = tribeDeck.remove();
|
||||||
|
if(tempCard.getEra()!=era)
|
||||||
|
{
|
||||||
|
nextEra();
|
||||||
|
}
|
||||||
|
upperListTribe.add(tempCard);
|
||||||
|
}
|
||||||
|
for(int i=upperListTribe.size();i<nTotem+5;i++)
|
||||||
|
{
|
||||||
|
TribeCard tempCard = tribeDeck.remove();
|
||||||
|
upperListTribe.add(tempCard);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return era;
|
||||||
|
}
|
||||||
|
public void nextEra() {
|
||||||
|
era=era+1;
|
||||||
|
lowerListBuilding.clear();
|
||||||
|
lowerListBuilding.addAll(upperListBuilding);
|
||||||
|
upperListBuilding.clear();
|
||||||
|
|
||||||
|
List<BuildingCard> buildingCards=DecksCreator.loadBuildingDeckByEra(era);
|
||||||
|
Collections.shuffle(buildingCards);
|
||||||
|
if(era==2)
|
||||||
|
{
|
||||||
|
if(nTotem<=3)
|
||||||
|
{
|
||||||
|
upperListBuilding.addAll(buildingCards.subList(0,2));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
upperListBuilding.addAll( buildingCards.subList(0,3));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(era==3)
|
||||||
|
{
|
||||||
|
if(nTotem==2)
|
||||||
|
{
|
||||||
|
upperListBuilding.addAll( buildingCards.subList(0,3));
|
||||||
|
}else if(nTotem==5)
|
||||||
|
{
|
||||||
|
upperListBuilding.addAll( buildingCards.subList(0,5));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
upperListBuilding.addAll(buildingCards.subList(0,4));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,10 @@ package it.polimi.ingsw.gc14.Model;
|
|||||||
|
|
||||||
public class Slot {
|
public class Slot {
|
||||||
// Getters
|
// Getters
|
||||||
|
private char slotId;
|
||||||
|
public char getSlotId() {
|
||||||
|
return slotId;
|
||||||
|
}
|
||||||
private int NUpper;
|
private int NUpper;
|
||||||
public int getNUpper(){
|
public int getNUpper(){
|
||||||
return NUpper;
|
return NUpper;
|
||||||
@@ -21,7 +25,7 @@ public class Slot {
|
|||||||
return Food;
|
return Food;
|
||||||
}
|
}
|
||||||
// End getters
|
// End getters
|
||||||
private char slotId;
|
|
||||||
// Setters
|
// Setters
|
||||||
// End setters
|
// End setters
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|||||||
Reference in New Issue
Block a user