Package it.polimi.ingsw.model
Class PlayerBoard
java.lang.Object
it.polimi.ingsw.model.PlayerBoard
- All Implemented Interfaces:
InterfacePlayerBoard,ActivatedLeaderObservable,LeaderDiscardObservable,MoveForwardObservable
public class PlayerBoard extends java.lang.Object implements InterfacePlayerBoard, MoveForwardObservable, LeaderDiscardObservable, ActivatedLeaderObservable
Represents a player board containing all the element of the game that regards a single player
-
Constructor Summary
Constructors Constructor Description PlayerBoard(java.lang.String username, java.util.List<LeaderCard> leaderCards, Market market, DevelopCardDeck developCardDeck) -
Method Summary
Modifier and Type Method Description voidaddDevelopCard(int row, int column, int cardSlot)Pick a card from the DevelopCardDeck and place it in the CardSlotvoidaddMarbleToWarehouse(int marbleIndex)Add one of the tempMarketMarble resources to warehouse or trackvoidaddToMoveForwardObserverList(MoveForwardObserver observerToAdd)Add an observer to a list of observersvoidaddWhiteToWarehouse(int leaderId)Add a white marble to warehouse using the leaderCard passed as parameterbooleanareMarblesFinished()Check if the all the marbles taken form market are finished and consumed (added to warehouse or track)voidbaseProduction(ResourceType resource1, ResourceType resource2, ResourceType product)Allows the player to throw 2 resources in exchange for 1 resource he wantsvoiddevelopProduce(int slotIndex)Activate production on a develop cardvoiddiscardLeader(int leaderId)Remove 1 of the leader cards from leaderCards array during the game once the card is removed the faith marker on other players is moved forward by 1voiddiscardLeaderAtBegin(int leaderPosition1, int leaderPosition2)Remove 1 of the leader cards from leaderCards array in the beginning of the gamevoidenterFinalTurnPhase()Merge the chest's temporary resources into normal chest, Forget all the production already activated Consume any possible remaining marble that hasn't been addedCardSlotsgetCardSlots()ChestgetChest()DevelopCardDeckgetDevelopCardDeck()java.util.ArrayList<LeaderCard>getLeaderCards()java.util.Set<MoveForwardObserver>getMoveForwardObserverList()java.util.List<MarketMarble>getTempMarketMarble()TrackgetTrack()java.lang.StringgetUsername()WarehousegetWarehouse()voidleaderProduce(int leaderId, ResourceType product)Activate production on a leader cardvoidnotifyActivatedLeader(LeaderUpdate msg)Notify the model observers that a leader card has been activated.voidnotifyForMoveForward()Notify the moveForward observers that they have to move their faith markervoidnotifyLeaderDiscard(LeaderUpdate msg)Notify the model observers that a leader card has been discarded Along with the notification sends the proper update Object as further explained in project documentationintreturnScore()Calculate player's scorevoidsetActiveLeadercard(int leaderCardId)Activate a leader cardvoidsetController(ModelObserver controller)voidsetEndGameObserver(EndGameObserver obs)java.util.List<MarketMarble>shopMarketColumn(int column)Saves the market marbles taken from the market in tempMarketMarblejava.util.List<MarketMarble>shopMarketRow(int row)Saves the market marbles taken from the market in tempMarketMarbleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
PlayerBoard
public PlayerBoard(java.lang.String username, java.util.List<LeaderCard> leaderCards, Market market, DevelopCardDeck developCardDeck) throws java.io.IOException- Throws:
java.io.IOException
-
-
Method Details
-
returnScore
public int returnScore()Calculate player's score- Returns:
- total points the player scored
-
discardLeaderAtBegin
public void discardLeaderAtBegin(int leaderPosition1, int leaderPosition2) throws InvalidLeaderCardExceptionRemove 1 of the leader cards from leaderCards array in the beginning of the game- Parameters:
leaderPosition1- , index of the first leader card to remove (starts at 0)leaderPosition2- , index of the second leader card to remove (starts at 0), considering the first already removed- Throws:
InvalidLeaderCardException- if one or both the leader cards don't exist
-
discardLeader
Remove 1 of the leader cards from leaderCards array during the game once the card is removed the faith marker on other players is moved forward by 1- Parameters:
leaderId- , Id of the leaderCard to remove (starts at 0)- Throws:
InvalidLeaderCardException- if the leaderCard is activated or the index is outOfBoundLeaderIsActiveException
-
addDevelopCard
public void addDevelopCard(int row, int column, int cardSlot) throws InvalidDevelopCardException, NotBuyableException, InvalidCardSlotExceptionPick a card from the DevelopCardDeck and place it in the CardSlot- Parameters:
row- , row of the Deck that identifies the Develop to add (starts at 0)column- , column of the Deck that identifies the Develop to add (starts at 0)cardSlot- , slot of CardSlots where the card is placed (starts at 0)- Throws:
InvalidCardSlotException- if the card can't be placed in the slot passed as parameterNotBuyableException- if the player can't buy this cardInvalidDevelopCardException- if the index of row or column doesn't exists
-
shopMarketColumn
public java.util.List<MarketMarble> shopMarketColumn(int column) throws RowOrColumnNotExistsExceptionSaves the market marbles taken from the market in tempMarketMarble- Parameters:
column- indicates which column get from market (starts at 0)- Throws:
RowOrColumnNotExistsException- if the specified index of the market doesn't exist
-
shopMarketRow
Saves the market marbles taken from the market in tempMarketMarble- Parameters:
row- indicates which row get from market (starts at 0)- Throws:
RowOrColumnNotExistsException- if the specified index of the market doesn't exist
-
getTempMarketMarble
-
addMarbleToWarehouse
public void addMarbleToWarehouse(int marbleIndex) throws MoreWhiteLeaderCardsException, NotEnoughSpaceException, MarbleNotExistExceptionAdd one of the tempMarketMarble resources to warehouse or track- Parameters:
marbleIndex- , the index of the marble to remove from tempMarketMarble (starts at 0)- Throws:
MoreWhiteLeaderCardsException- if the player has more than 1 leaderCard activated that modifies the white marbleNotEnoughSpaceException- if the resource can't be addedMarbleNotExistException- if the specified marble doesn't exist
-
addWhiteToWarehouse
public void addWhiteToWarehouse(int leaderId) throws InvalidLeaderCardException, NotEnoughSpaceException, MarbleNotExistExceptionAdd a white marble to warehouse using the leaderCard passed as parameter- Parameters:
leaderId- , Id of the leader to use to modify the color of the white marble- Throws:
InvalidLeaderCardException- if the index is outOfBoundNotEnoughSpaceException- if, after have modified the white marble into a resource, there isn't place in the warehouse to place itMarbleNotExistException
-
baseProduction
public void baseProduction(ResourceType resource1, ResourceType resource2, ResourceType product) throws AbuseOfFaithException, NotEnoughResourcesException, AlreadyProducedException, NeedAResourceToAddExceptionAllows the player to throw 2 resources in exchange for 1 resource he wants- Parameters:
resource1- first resource the player wants to throwresource2- second resource the player wants to throwproduct- resource that the player wants to gain- Throws:
AbuseOfFaithException- if one of the 3 resources is faith, he can't throw faith and he can't gain faithNotEnoughResourcesException- if the player has not the specified required resourcesAlreadyProducedException- if this production has already been activated during this turnNeedAResourceToAddException- if the specified product parameter is null
-
areMarblesFinished
public boolean areMarblesFinished()Check if the all the marbles taken form market are finished and consumed (added to warehouse or track)- Returns:
- true if the marbles are finished, false otherwise
-
developProduce
public void developProduce(int slotIndex) throws NotActivatableException, AlreadyProducedException, InvalidCardSlotExceptionActivate production on a develop card- Parameters:
slotIndex- index of cards slot where the card is- Throws:
NotActivatableException- if the player can't activate this cardAlreadyProducedException- if this production has already been activated during this turnInvalidCardSlotException- if the card slot doesn't exists
-
leaderProduce
public void leaderProduce(int leaderId, ResourceType product) throws NotEnoughResourcesException, AbuseOfFaithException, NeedAResourceToAddException, AlreadyProducedException, InvalidLeaderCardExceptionActivate production on a leader card- Parameters:
leaderId- index of the leader on which the production must be activatedproduct- resource that the player wants to gain- Throws:
AbuseOfFaithException- if product is equal to faithNotEnoughResourcesException- if the player has not the specified required resourcesAlreadyProducedException- if this production has already been activated during this turnNeedAResourceToAddException- if the specified product parameter is nullInvalidLeaderCardException
-
setActiveLeadercard
public void setActiveLeadercard(int leaderCardId) throws InvalidLeaderCardException, NotEnoughResourcesExceptionActivate a leader card- Parameters:
leaderCardId- , Id of the leader card to activate- Throws:
InvalidLeaderCardException- if the player doesn't own this cardNotEnoughResourcesException- if the player doesn't have the resources (CardFlags or ResourceType) to activate the card
-
enterFinalTurnPhase
public void enterFinalTurnPhase()Merge the chest's temporary resources into normal chest, Forget all the production already activated Consume any possible remaining marble that hasn't been added -
getUsername
public java.lang.String getUsername() -
getMoveForwardObserverList
-
setEndGameObserver
-
getWarehouse
- Specified by:
getWarehousein interfaceInterfacePlayerBoard
-
getChest
- Specified by:
getChestin interfaceInterfacePlayerBoard
-
getTrack
- Specified by:
getTrackin interfaceInterfacePlayerBoard
-
getCardSlots
- Specified by:
getCardSlotsin interfaceInterfacePlayerBoard
-
getLeaderCards
- Specified by:
getLeaderCardsin interfaceInterfacePlayerBoard
-
getDevelopCardDeck
- Specified by:
getDevelopCardDeckin interfaceInterfacePlayerBoard
-
notifyForMoveForward
public void notifyForMoveForward()Description copied from interface:MoveForwardObservableNotify the moveForward observers that they have to move their faith marker- Specified by:
notifyForMoveForwardin interfaceMoveForwardObservable
-
addToMoveForwardObserverList
Description copied from interface:MoveForwardObservableAdd an observer to a list of observers- Specified by:
addToMoveForwardObserverListin interfaceMoveForwardObservable- Parameters:
observerToAdd- the observer to add
-
setController
-
notifyLeaderDiscard
Description copied from interface:LeaderDiscardObservableNotify the model observers that a leader card has been discarded Along with the notification sends the proper update Object as further explained in project documentation- Specified by:
notifyLeaderDiscardin interfaceLeaderDiscardObservable- Parameters:
msg- the update object representing a leader card update
-
notifyActivatedLeader
Description copied from interface:ActivatedLeaderObservableNotify the model observers that a leader card has been activated. Along with the notification sends the proper update Object as further explained in project documentation- Specified by:
notifyActivatedLeaderin interfaceActivatedLeaderObservable- Parameters:
msg- the update object representing a leader card update
-