daje
This commit is contained in:
@@ -11,28 +11,69 @@ import it.polimi.ingsw.gc14.Model.Slot;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Board manages all the elements during the game as decks, upper and lower rows, totems, tiles...
|
||||||
|
*/
|
||||||
public class Board {
|
public class Board {
|
||||||
|
/**
|
||||||
|
* slotList contains the ordered list of slots (tiles). These changes based on the number of players.
|
||||||
|
* Each slot (tile) has special action as drawing from the upper/lower row or taking food.
|
||||||
|
*/
|
||||||
private List<Slot> slotList;
|
private List<Slot> slotList;
|
||||||
|
|
||||||
|
/** tribeDeck is the deck from where you draw tribe cards as characters and events. */
|
||||||
private Queue<TribeCard> tribeDeck;
|
private Queue<TribeCard> tribeDeck;
|
||||||
|
|
||||||
|
/** The upper row of tribe cards. There must be (num. of players + 4) character cards + Event cards */
|
||||||
public List<TribeCard> upperListTribe;
|
public List<TribeCard> upperListTribe;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The lower row of the tribe card. During the first round there will be (num. of players + 1) character cards.
|
||||||
|
* During the following rounds, lower row will be emptied and populated with upper row's cards.
|
||||||
|
* When an Event card get in the lower row, the event effect will be activated at the wnd of the round.
|
||||||
|
*/
|
||||||
public List<TribeCard> lowerListTribe;
|
public List<TribeCard> lowerListTribe;
|
||||||
|
|
||||||
|
/** Contains all the building cards of the upper list. When a new era starts, all its building cards are placed here */
|
||||||
public List<BuildingCard> upperListBuilding;
|
public List<BuildingCard> upperListBuilding;
|
||||||
|
|
||||||
|
/** Contains all the building cards of the upper list. When a new era starts, the old era's buildings are moved from the upper to the lower list */
|
||||||
public List<BuildingCard> lowerListBuilding;
|
public List<BuildingCard> lowerListBuilding;
|
||||||
|
|
||||||
|
/** Number of players */
|
||||||
private int nTotem;
|
private int nTotem;
|
||||||
|
|
||||||
|
/** Current era of the game */
|
||||||
private int era;
|
private int era;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates and return a new list containing the slots (tiles) of the game
|
||||||
|
*
|
||||||
|
* @return a copy of the slot list
|
||||||
|
*/
|
||||||
public List<Slot> getSlotList(){
|
public List<Slot> getSlotList(){
|
||||||
return slotList.stream().map(x->new Slot(x.getSlotId())).collect(Collectors.toList());
|
return slotList.stream().map(x->new Slot(x.getSlotId())).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
public Queue<TribeCard> getTribeDeck() {return new LinkedList<>(tribeDeck);}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates and initialize a new board:
|
||||||
|
* - Generate the slotList using a method of DecksCreator
|
||||||
|
* - Generate the tribeDeck
|
||||||
|
* - Populate the lower list (if there is an event card, it's added to the upper list)
|
||||||
|
* - Populate the upper list
|
||||||
|
* - Generate the buildingDeck using a method of DecksCreator
|
||||||
|
*
|
||||||
|
* @param nTotem the number of players
|
||||||
|
*/
|
||||||
public Board(int nTotem) {
|
public Board(int nTotem) {
|
||||||
this.nTotem = nTotem;
|
this.nTotem = nTotem;
|
||||||
this.slotList = DecksCreator.loadSlotDeck().stream().filter(x->x.getNMinPlayer()<=nTotem).sorted(Comparator.comparingInt(Slot::getSlotId)).toList();
|
this.slotList = DecksCreator.loadSlotDeck().stream().filter(x->x.getNMinPlayer()<=nTotem).sorted(Comparator.comparingInt(Slot::getSlotId)).toList();
|
||||||
upperListTribe=new ArrayList<>();
|
upperListTribe=new ArrayList<>();
|
||||||
lowerListTribe=new ArrayList<>();
|
lowerListTribe=new ArrayList<>();
|
||||||
lowerListBuilding=new ArrayList<>();
|
lowerListBuilding=new ArrayList<>();
|
||||||
tribeDeck=generateTribeDeck(nTotem);
|
tribeDeck=getTribeDeck(nTotem);
|
||||||
era=1;
|
era=1;
|
||||||
|
|
||||||
for(int i=0;i<nTotem+1;i++)
|
for(int i=0;i<nTotem+1;i++)
|
||||||
{
|
{
|
||||||
TribeCard tempCard = tribeDeck.remove();
|
TribeCard tempCard = tribeDeck.remove();
|
||||||
@@ -46,7 +87,8 @@ public class Board {
|
|||||||
lowerListTribe.add(tempCard);
|
lowerListTribe.add(tempCard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(int i=upperListTribe.size();i<nTotem+5;i++)
|
|
||||||
|
for(int i=upperListTribe.size();i<nTotem+4;i++)
|
||||||
{
|
{
|
||||||
TribeCard tempCard = tribeDeck.remove();
|
TribeCard tempCard = tribeDeck.remove();
|
||||||
upperListTribe.add(tempCard);
|
upperListTribe.add(tempCard);
|
||||||
@@ -60,7 +102,18 @@ public class Board {
|
|||||||
upperListBuilding= buildingDeck.subList(0,2);
|
upperListBuilding= buildingDeck.subList(0,2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Queue<TribeCard> generateTribeDeck(int nPlayers) {
|
/**
|
||||||
|
* Creates the tribeDeck. Loads the cards from each era, shuffle them, and then join them in the final deck.
|
||||||
|
* In the end, two special events (Sustenance and ShamanicRitual) are added.
|
||||||
|
*
|
||||||
|
* @param nPlayers the number of players
|
||||||
|
* @return a queue containing the cards in this order:
|
||||||
|
* - Era 1
|
||||||
|
* - Era 2
|
||||||
|
* - Era 3
|
||||||
|
* - Special events
|
||||||
|
*/
|
||||||
|
private Queue<TribeCard> getTribeDeck(int nPlayers) {
|
||||||
ArrayList<TribeCard> era1= DecksCreator.loadTribeDeckByEra(1).stream().filter(x->x.getNMin()<=nPlayers).collect(Collectors.toCollection(ArrayList::new));
|
ArrayList<TribeCard> era1= DecksCreator.loadTribeDeckByEra(1).stream().filter(x->x.getNMin()<=nPlayers).collect(Collectors.toCollection(ArrayList::new));
|
||||||
ArrayList<TribeCard> era2= DecksCreator.loadTribeDeckByEra(2).stream().filter(x->x.getNMin()<=nPlayers).collect(Collectors.toCollection(ArrayList::new));
|
ArrayList<TribeCard> era2= DecksCreator.loadTribeDeckByEra(2).stream().filter(x->x.getNMin()<=nPlayers).collect(Collectors.toCollection(ArrayList::new));
|
||||||
ArrayList<TribeCard> era3= DecksCreator.loadTribeDeckByEra(3).stream().filter(x->x.getNMin()<=nPlayers).collect(Collectors.toCollection(ArrayList::new));
|
ArrayList<TribeCard> era3= DecksCreator.loadTribeDeckByEra(3).stream().filter(x->x.getNMin()<=nPlayers).collect(Collectors.toCollection(ArrayList::new));
|
||||||
@@ -77,22 +130,58 @@ public class Board {
|
|||||||
return tribeDeck_temp;
|
return tribeDeck_temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return the queue of events from the lower list that need to be activated */
|
||||||
public Queue<EventCard> getPendingEvents(){
|
public Queue<EventCard> getPendingEvents(){
|
||||||
return lowerListTribe.stream().filter(TribeCard::IsEventCard).map(x->(EventCard)x).collect(Collectors.toCollection(LinkedList::new));
|
return lowerListTribe.stream().filter(TribeCard::IsEventCard).map(x->(EventCard)x).collect(Collectors.toCollection(LinkedList::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Take the selected card from the upper tribe list of the board
|
||||||
|
*
|
||||||
|
* @param tribeCard is the card to remove
|
||||||
|
* @return true if succeed in removing the card
|
||||||
|
*/
|
||||||
public boolean removeUpperTribeCard(TribeCard tribeCard) {
|
public boolean removeUpperTribeCard(TribeCard tribeCard) {
|
||||||
return upperListTribe.remove(tribeCard);
|
return upperListTribe.remove(tribeCard);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Take the selected card from the lower tribe list of the board
|
||||||
|
*
|
||||||
|
* @param tribeCard is the card to remove
|
||||||
|
* @return true if succeed in removing the card
|
||||||
|
*/
|
||||||
public boolean removeLowerTribeCard(TribeCard tribeCard) {
|
public boolean removeLowerTribeCard(TribeCard tribeCard) {
|
||||||
return upperListTribe.remove(tribeCard);
|
return lowerListTribe.remove(tribeCard);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Take the selected card from the upper building list of the board
|
||||||
|
*
|
||||||
|
* @param buildingCard is the card to remove
|
||||||
|
* @return true if succeed in removing the card
|
||||||
|
*/
|
||||||
public boolean removeUpperBuildingCard(BuildingCard buildingCard) {
|
public boolean removeUpperBuildingCard(BuildingCard buildingCard) {
|
||||||
return upperListTribe.remove(buildingCard);
|
return upperListBuilding.remove(buildingCard);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Take the selected card from the lower building list of the board
|
||||||
|
*
|
||||||
|
* @param buildingCard is the card to remove
|
||||||
|
* @return true if succeed in removing the card
|
||||||
|
*/
|
||||||
public boolean removeLowerBuildingCard(BuildingCard buildingCard) {
|
public boolean removeLowerBuildingCard(BuildingCard buildingCard) {
|
||||||
return upperListTribe.remove(buildingCard);
|
return lowerListBuilding.remove(buildingCard);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Goes to the next round.
|
||||||
|
* - Clear the lower tribe row
|
||||||
|
* - Moves the upper tribe row to the lower one
|
||||||
|
* - Populate the upper tribe row
|
||||||
|
*
|
||||||
|
*/
|
||||||
public int nextRound() {
|
public int nextRound() {
|
||||||
lowerListTribe.clear();
|
lowerListTribe.clear();
|
||||||
lowerListTribe.addAll(upperListTribe);
|
lowerListTribe.addAll(upperListTribe);
|
||||||
@@ -106,22 +195,23 @@ public class Board {
|
|||||||
}
|
}
|
||||||
upperListTribe.add(tempCard);
|
upperListTribe.add(tempCard);
|
||||||
}
|
}
|
||||||
for(int i=upperListTribe.size();i<nTotem+5;i++)
|
|
||||||
{
|
|
||||||
TribeCard tempCard = tribeDeck.remove();
|
|
||||||
upperListTribe.add(tempCard);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return era;
|
return era;
|
||||||
}
|
}
|
||||||
public void nextEra() {
|
|
||||||
|
/**
|
||||||
|
* Change the era of the game:
|
||||||
|
* - Increase the era attribute
|
||||||
|
* - Clear the lower building list and replace it with the upper building list
|
||||||
|
* - Repopulate the upper building list
|
||||||
|
*/
|
||||||
|
private void nextEra() {
|
||||||
era=era+1;
|
era=era+1;
|
||||||
lowerListBuilding.clear();
|
lowerListBuilding.clear();
|
||||||
lowerListBuilding.addAll(upperListBuilding);
|
lowerListBuilding.addAll(upperListBuilding);
|
||||||
upperListBuilding.clear();
|
upperListBuilding.clear();
|
||||||
|
|
||||||
List<BuildingCard> buildingCards=DecksCreator.loadBuildingDeckByEra(era);
|
ArrayList<BuildingCard> buildingCards= new ArrayList<>(DecksCreator.loadBuildingDeckByEra(era));
|
||||||
Collections.shuffle(buildingCards);
|
Collections.shuffle(buildingCards);
|
||||||
if(era==2)
|
if(era==2)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user