Class CardFactory

java.lang.Object
it.polimi.ingsw.am13.model.card.CardFactory

public class CardFactory extends Object
This class parses the information of card_json and creates Card objects in accordance to the Factory pattern
  • Field Details

  • Constructor Details

    • CardFactory

      public CardFactory()
  • Method Details

    • createCardsResource

      public LinkedList<CardResource> createCardsResource() throws InvalidCardCreationException
      Deserializes a list of Resource cards from the card_data.json
      Returns:
      LinkedList<> of CardResource
      Throws:
      InvalidCardCreationException - if it fails to create a valid card
    • createCardsGold

      public LinkedList<CardGold> createCardsGold() throws InvalidCardCreationException
      Deserializes a list of Gold cards from the card_data.json
      Returns:
      LinkedList<> of CardGold
      Throws:
      InvalidCardCreationException - if it fails to create a valid card
    • createCardsStarter

      public LinkedList<CardStarter> createCardsStarter() throws InvalidCardCreationException
      Deserializes a list of Starter cards from the card_data.json
      Returns:
      LinkedList<> of CardStarter
      Throws:
      InvalidCardCreationException - if it fails to create a valid card
    • createCardsObjective

      public LinkedList<CardObjective> createCardsObjective() throws InvalidCardCreationException
      Deserializes a list of Objective cards from the card_data.json
      Returns:
      LinkedList<> of CardObjective
      Throws:
      InvalidCardCreationException - if it fails to create a valid card
    • getFrontsNode

      private com.fasterxml.jackson.databind.JsonNode getFrontsNode(String cardType) throws IOException
      Parameters:
      cardType - String used to reference this card type in the card_data.json
      Returns:
      JsonNode of the list of "front sides" of the given cardType
      Throws:
      IOException - If it fails to retrieve the correct JsonNode from the JSON file
      See Also:
      • JsonNode
    • getBacksNode

      private com.fasterxml.jackson.databind.JsonNode getBacksNode(String cardType) throws IOException
      Parameters:
      cardType - String used to reference this card type in the card_data.json
      Returns:
      JsonNode of the list of "front sides" of the given cardType
      Throws:
      IOException - If it fails to retrieve the correct JsonNode from the JSON file
      See Also:
      • JsonNode
    • getCorners

      private List<Corner> getCorners(com.fasterxml.jackson.databind.JsonNode cardSide)
      Parameters:
      cardSide - JsonNode of the card side to which the corners are a part of.
      Returns:
      List<> of Corner objects
    • colorConverter

      private Color colorConverter(String s)
      Parameters:
      s - String whose first letter represents a color for a card
      Returns:
      corresponding Color
    • resourceConverter

      private Resource resourceConverter(char c)
      Parameters:
      c - Character indicating a resource
      Returns:
      corresponding Resource
    • emptyCorners

      private List<Corner> emptyCorners()
      Returns:
      List of empty corners