java.lang.Object
polimi.ingsw.am21.codex.model.GameBoard.GameBoard

public class GameBoard extends Object
  • Constructor Details

  • Method Details

    • fromJSON

      public static GameBoard fromJSON(org.json.JSONArray cards)
      static method to create a GameBoard from a JSON array Initializes the decks using a JSONArray
      Parameters:
      cards - the full list
    • peekGoldCardFromDeck

      public PlayableCard peekGoldCardFromDeck()
      Returns the first card of the gold deck, without drawing it
    • drawGoldCardFromDeck

      public PlayableCard drawGoldCardFromDeck() throws EmptyDeckException
      Draws a gold card from the deck
      Returns:
      a gold card drawn from the gold cards deck
      Throws:
      EmptyDeckException - there are no objective cards left in the deck
    • drawCard

      public PlayableCard drawCard(DrawingCardSource drawingSource, DrawingDeckType deckType, Consumer<PlayableCard> replacedCardCallback) throws EmptyDeckException
      Draws a card from a player's deck pair.
      Parameters:
      drawingSource - Where we are drawing the card rom
      deckType - The type of deck to draw from.
      replacedCardCallback - A callback that accepts the card that was put in the card pair to replace the drawn card.
      Returns:
      The drawn card.
      Throws:
      EmptyDeckException - If the deck being drawn from is empty.
    • drawCard

      public PlayableCard drawCard(DrawingCardSource drawingSource, DrawingDeckType deckType) throws EmptyDeckException
      Throws:
      EmptyDeckException
    • getResourceCards

      public CardPair<PlayableCard> getResourceCards()
      Returns:
      the 2 resource cards in the card pair
    • getGoldCards

      public CardPair<PlayableCard> getGoldCards()
      Returns:
      the 2 gold cards in the card pair
    • goldCardsLeft

      public int goldCardsLeft()
      Returns:
      the number of gold cards left in the deck
    • drawStarterCardFromDeck

      public PlayableCard drawStarterCardFromDeck() throws EmptyDeckException
      Draws a starter card from the deck
      Returns:
      the starterDeck
      Throws:
      EmptyDeckException - there are no objective cards left in the deck
    • starterCardsLeft

      public int starterCardsLeft()
      Returns:
      the number of starter cards left in the deck
    • drawObjectiveCardFromDeck

      public ObjectiveCard drawObjectiveCardFromDeck() throws EmptyDeckException
      Draws an objective card from the deck
      Returns:
      the objectiveDeck
      Throws:
      EmptyDeckException - there are no objective cards left in the deck
    • getObjectiveCards

      public CardPair<ObjectiveCard> getObjectiveCards()
      Returns:
      the 2 objective cards
    • insertObjectiveCard

      public void insertObjectiveCard(ObjectiveCard card)
      Inserts an objective card in the bottom of the deck
      Parameters:
      card - the card to insert
    • insertStarterCard

      public void insertStarterCard(PlayableCard card)
      Inserts a starter card in the bottom of the deck
      Parameters:
      card - the card to insert
    • objectiveCardsLeft

      public int objectiveCardsLeft()
      Returns:
      the number of objective cards left in the deck
    • peekResourceCardFromDeck

      public PlayableCard peekResourceCardFromDeck()
      Returns the first card of the resource deck, without drawing it
    • drawResourceCardFromDeck

      public PlayableCard drawResourceCardFromDeck() throws EmptyDeckException
      Draws a resource card from the deck
      Returns:
      a resource card drawn from the resource cards deck
      Throws:
      EmptyDeckException - there are no resource cards left in the deck
    • drawResourceCardFromDeck

      public List<PlayableCard> drawResourceCardFromDeck(int n) throws EmptyDeckException
      Draws a resource card from the deck
      Parameters:
      n - number of cards to extract
      Returns:
      a resource card drawn from the resource cards deck
      Throws:
      EmptyDeckException - there are no resource cards left in the deck
    • drawResourceCardFromPair

      public PlayableCard drawResourceCardFromPair(Boolean first) throws EmptyDeckException
      Draws the first or the second resource card from the game board and replaces it with a new one from the deck
      Parameters:
      first - if true, the first card is drawn, otherwise the second
      Returns:
      the resource card drawn
      Throws:
      EmptyDeckException
    • resourceCardsLeft

      public int resourceCardsLeft()
      Returns:
      the number of resource cards left in the deck
    • drawObjectiveCardPair

      public CardPair<ObjectiveCard> drawObjectiveCardPair() throws EmptyDeckException
      Returns:
      a card pair with objective cards from the deck
      Throws:
      EmptyDeckException - if the objective cards deck is empty