Class SkyjoModelImpl

java.lang.Object
ca.uqam.info.model.SkyjoModelImpl
All Implemented Interfaces:
ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModel, ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModelReadOnly

public class SkyjoModelImpl extends Object implements ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModel
Main implementation of the SkyjoModel interface. This class serves as the central model for the Skyjo game, implementing both the read-write (SkyjoModel) and read-only (SkyjoModelReadOnly) interfaces. It manages the complete game state including players, deck, discard pile, game progression, and enforces game rules. The model follows MVC architecture where this class represents the Model component, providing data and game logic while maintaining separation from View and Controller.
Version:
2.1
Author:
Mohamed Latif Diallo, Hamza Afif, Ussel Sabbat
  • Constructor Summary

    Constructors
    Constructor
    Description
    SkyjoModelImpl(String[] playerName, int defaultSizeX, int defaultSizeY)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Sets the current player to the next player in order.
    void
    eliminateColumn(int i, int i1)
     
    void
    eliminateRow(int i, int i1)
     
    int[]
    Definitely ends the game.
    int
    Getter to look up how many cards are currently on the deck.
    int
    Getter to look up how many cards are currently on discard pile.
    int
    Getter to look up how many players are involved in the current session.
    ca.uqam.info.mgl7010.max.skyjo.model.Card
    Returns buffer card without clearing it from buffer.
    ca.uqam.info.mgl7010.max.skyjo.model.Card
    getCardForPlayerByPosition(int playerIndex, int cardPositionX, int cardPositionY)
    Getter to obtain card of player at specific position.
    int
    getCurrentDimensionsX(int playerIndex)
    Getter for current amount of cards horizontally laid out in front of specified player.
    int
    getCurrentDimensionsY(int playerIndex)
    Getter for current amount of cards vertically laid out in front of specified player.
    int
    Getter for the index of the current player.
    int
    Returns index of player who triggered game end, if isGameOverInitiated returns true.
    int
    Returns the initial amount of cards horizontally laid out in front of each player.
    int
    Returns the initial amount of cards vertically laid out in front of each player.
    getPlayerName(int playerIndex)
    Returns the plain string name of a players, specified by index.
    int[]
    Returns array with sum of all revealed cards, each array position represents one player.
    int
    Getter for round counter.
    boolean
    isAllPlayerCardsRevealed(int playerIndex)
     
    boolean
    Tells whether the model currently has a dedicated buffer card, i.e.
    boolean
     
    boolean
    this.players[i].reduceColumn(); Tells if at least one player has all their cards revealed.
    boolean
    isPlayerCardAtPositionRevealed(int playerIndex, int cardColumn, int cardRow)
    Getter to look up if a card at a given position is already revealed.
    ca.uqam.info.mgl7010.max.skyjo.model.Card
    Returns Card of topmost discard pile card (without removing card from discard pile).
    ca.uqam.info.mgl7010.max.skyjo.model.Card
    Retrieves (and implicitly removes) the buffer card.
    ca.uqam.info.mgl7010.max.skyjo.model.Card
    Retrieves the topmost deck card, implicitly removing the card from the deck.
    ca.uqam.info.mgl7010.max.skyjo.model.Card
    Retrieves the topmost discard pile card, implicitly removing the card from the discard pile.
    void
    pushDiscardPile(ca.uqam.info.mgl7010.max.skyjo.model.Card card)
    Required for undoing operations.
    ca.uqam.info.mgl7010.max.skyjo.model.Card
    replacePlayerCard(int playerIndex, int x, int y, ca.uqam.info.mgl7010.max.skyjo.model.Card card)
    Replaces a player's card by another provided card.
    void
    revealPlayerCard(int playerIndex, int x, int y)
    Reveals a concealed card in a player's card arrangement, specified by player and x-y position.
    void
    setBufferCard(ca.uqam.info.mgl7010.max.skyjo.model.Card card)
    Sets the provided card as buffer card, i.e.
    void
    Marks the current player as game ender, i.e.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SkyjoModelImpl

      public SkyjoModelImpl(String[] playerName, int defaultSizeX, int defaultSizeY)
  • Method Details

    • getAmountPlayers

      public int getAmountPlayers()
      Getter to look up how many players are involved in the current session.
      Specified by:
      getAmountPlayers in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModelReadOnly
      Returns:
      int representing amount of players in session.
    • getPlayerName

      public String getPlayerName(int playerIndex)
      Returns the plain string name of a players, specified by index.
      Specified by:
      getPlayerName in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModelReadOnly
      Returns:
      player name as string.
    • isPlayerCardAtPositionRevealed

      public boolean isPlayerCardAtPositionRevealed(int playerIndex, int cardColumn, int cardRow)
      Getter to look up if a card at a given position is already revealed.
      Specified by:
      isPlayerCardAtPositionRevealed in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModelReadOnly
      Parameters:
      playerIndex - to specify the player owning the card.
      cardColumn - as the card's horizontal position (starting at 0).
      cardRow - as the card's vertical position (starting at 0).
      Returns:
      boolean flag indicating whether the specified card is revealed or not.
    • isAllPlayerCardsRevealed

      public boolean isAllPlayerCardsRevealed(int playerIndex)
      Specified by:
      isAllPlayerCardsRevealed in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModelReadOnly
    • getCardForPlayerByPosition

      public ca.uqam.info.mgl7010.max.skyjo.model.Card getCardForPlayerByPosition(int playerIndex, int cardPositionX, int cardPositionY)
      Getter to obtain card of player at specific position. Throws an exception if the card is currently undisclosed.
      Specified by:
      getCardForPlayerByPosition in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModelReadOnly
      Parameters:
      playerIndex - to specify the player owning the card.
      cardPositionX - as the card's horizontal position (starting at 0).
      cardPositionY - as the card's vertical position (starting at 0).
      Returns:
      card object in case the card is revealed.
    • getCurrentPlayerIndex

      public int getCurrentPlayerIndex()
      Getter for the index of the current player.
      Specified by:
      getCurrentPlayerIndex in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModelReadOnly
      Returns:
      int representing the index of the current player.
    • peekDiscardPile

      public ca.uqam.info.mgl7010.max.skyjo.model.Card peekDiscardPile()
      Returns Card of topmost discard pile card (without removing card from discard pile). Throws a ModelAccessException if the discard pile is empty.
      Specified by:
      peekDiscardPile in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModelReadOnly
      Returns:
      topmost discard pile card.
    • getBufferCard

      public ca.uqam.info.mgl7010.max.skyjo.model.Card getBufferCard()
      Returns buffer card without clearing it from buffer. Throws a ModelAccessException if the buffer is empty.
      Specified by:
      getBufferCard in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModelReadOnly
      Returns:
      the currently buffered card.
    • isBufferCardPresent

      public boolean isBufferCardPresent()
      Tells whether the model currently has a dedicated buffer card, i.e. if the current player has already drawn a card from new card pile or discard card pile and placed it on the buffer.
      Specified by:
      isBufferCardPresent in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModelReadOnly
      Returns:
      boolean indicating if a card is currently buffered.
    • getPlayerScores

      public int[] getPlayerScores()
      Returns array with sum of all revealed cards, each array position represents one player. If all cards of a player are undisclosed, the sum amounts to 0.
      Specified by:
      getPlayerScores in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModelReadOnly
      Returns:
      int array representing combined score of all revealed cards for each player.
    • getInitialDimensionsX

      public int getInitialDimensionsX()
      Returns the initial amount of cards horizontally laid out in front of each player.
      Specified by:
      getInitialDimensionsX in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModelReadOnly
      Returns:
      int representing initial horizontal player cards.
    • getInitialDimensionsY

      public int getInitialDimensionsY()
      Returns the initial amount of cards vertically laid out in front of each player.
      Specified by:
      getInitialDimensionsY in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModelReadOnly
      Returns:
      int representing initial vertical player cards.
    • getCurrentDimensionsX

      public int getCurrentDimensionsX(int playerIndex)
      Getter for current amount of cards horizontally laid out in front of specified player. Players can eliminate rows and columns over time, this method allows retrieving the current amount, which may be different from the default.
      Specified by:
      getCurrentDimensionsX in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModelReadOnly
      Parameters:
      playerIndex - as the identifier of the player to inquery.
      Returns:
      amount of horizontal cards remaining for specified player.
    • getCurrentDimensionsY

      public int getCurrentDimensionsY(int playerIndex)
      Getter for current amount of cards vertically laid out in front of specified player. Players can eliminate rows and columns over time, this method allows retrieving the current amount, which may be different from the default.
      Specified by:
      getCurrentDimensionsY in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModelReadOnly
      Parameters:
      playerIndex - as the identifier of the player to inquery.
      Returns:
      amount of vertical cards remaining for specified player.
    • isGameOverInitialized

      public boolean isGameOverInitialized()
      this.players[i].reduceColumn(); Tells if at least one player has all their cards revealed.
      Specified by:
      isGameOverInitialized in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModelReadOnly
      Returns:
      true if at least one player has all their cards revealed.
    • isGameOver

      public boolean isGameOver()
      Specified by:
      isGameOver in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModelReadOnly
    • getGameEnder

      public int getGameEnder()
      Returns index of player who triggered game end, if isGameOverInitiated returns true. Returns negative value otherwise.
      Specified by:
      getGameEnder in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModelReadOnly
      Returns:
      player index or -1.
    • getAmountDiscardPileCards

      public int getAmountDiscardPileCards()
      Getter to look up how many cards are currently on discard pile.
      Specified by:
      getAmountDiscardPileCards in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModelReadOnly
      Returns:
      amount of cards currently on discard pile.
    • getAmountDeckCards

      public int getAmountDeckCards()
      Getter to look up how many cards are currently on the deck.
      Specified by:
      getAmountDeckCards in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModelReadOnly
      Returns:
      amount of cards currently on the deck.
    • getRound

      public int getRound()
      Getter for round counter.
      Specified by:
      getRound in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModelReadOnly
      Returns:
      int representing the current round count.
    • revealPlayerCard

      public void revealPlayerCard(int playerIndex, int x, int y)
      Reveals a concealed card in a player's card arrangement, specified by player and x-y position.
      Specified by:
      revealPlayerCard in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModel
      Parameters:
      playerIndex - as string matching exactly one player object associated with model.
      x - as horizontal card position, first column is 0.
      y - as vertical card position, first row is 0.
    • endGame

      public int[] endGame()
      Definitely ends the game. Reveals all remaining player cards and returns the resulting scores.
      Specified by:
      endGame in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModel
      Returns:
      final player scores of all cards combined.
    • replacePlayerCard

      public ca.uqam.info.mgl7010.max.skyjo.model.Card replacePlayerCard(int playerIndex, int x, int y, ca.uqam.info.mgl7010.max.skyjo.model.Card card)
      Replaces a player's card by another provided card.
      Specified by:
      replacePlayerCard in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModel
      Parameters:
      playerIndex - to specify which player's card layout is modified.
      x - as horizontal position of the card to be swapped (starting at 0).
      y - as vertical position of the card to be swapped (starting at 0).
      card - as the card to take the specified position.
      Returns:
      the card which has been replaced.
    • eliminateRow

      public void eliminateRow(int i, int i1)
      Specified by:
      eliminateRow in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModel
    • eliminateColumn

      public void eliminateColumn(int i, int i1)
      Specified by:
      eliminateColumn in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModel
    • popDeck

      public ca.uqam.info.mgl7010.max.skyjo.model.Card popDeck()
      Retrieves the topmost deck card, implicitly removing the card from the deck. Throws an ModelAccessException if the deck is empty.
      Specified by:
      popDeck in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModel
      Returns:
      Card retrieved from topmost deck position.
    • popDiscardPile

      public ca.uqam.info.mgl7010.max.skyjo.model.Card popDiscardPile()
      Retrieves the topmost discard pile card, implicitly removing the card from the discard pile. Throws an ModelAccessException if the discard pile is empty.
      Specified by:
      popDiscardPile in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModel
      Returns:
      Card retrieved from topmost discard pile position.
    • pushDiscardPile

      public void pushDiscardPile(ca.uqam.info.mgl7010.max.skyjo.model.Card card)
      Required for undoing operations.
      Specified by:
      pushDiscardPile in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModel
      Parameters:
      card - a card that has been previously removed from the discard pile and is now placed back on top.
    • setBufferCard

      public void setBufferCard(ca.uqam.info.mgl7010.max.skyjo.model.Card card)
      Sets the provided card as buffer card, i.e. selected by player for further action. This is commonly the card they just popped from the deck or discard pile. Throws a ModelAccessException if the buffer space is already taken.
      Specified by:
      setBufferCard in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModel
      Parameters:
      card - as the card to be placed as buffer.
    • popBufferCard

      public ca.uqam.info.mgl7010.max.skyjo.model.Card popBufferCard()
      Retrieves (and implicitly removes) the buffer card. Throws a ModelAccessException if there currently is no card in buffer.
      Specified by:
      popBufferCard in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModel
      Returns:
      the card removed from buffer.
    • advancePlayer

      public void advancePlayer()
      Sets the current player to the next player in order.
      Specified by:
      advancePlayer in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModel
    • setGameEnder

      public void setGameEnder()
      Marks the current player as game ender, i.e. the person who triggered game end by revealing their last undisclosed card. Can only be called when the provided player has all cards revealed and game and has not yet been triggered.
      Specified by:
      setGameEnder in interface ca.uqam.info.mgl7010.max.skyjo.model.SkyjoModel