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 -
Method Summary
Modifier and TypeMethodDescriptionvoidSets the current player to the next player in order.voideliminateColumn(int i, int i1) voideliminateRow(int i, int i1) int[]endGame()Definitely ends the game.intGetter to look up how many cards are currently on the deck.intGetter to look up how many cards are currently on discard pile.intGetter to look up how many players are involved in the current session.ca.uqam.info.mgl7010.max.skyjo.model.CardReturns buffer card without clearing it from buffer.ca.uqam.info.mgl7010.max.skyjo.model.CardgetCardForPlayerByPosition(int playerIndex, int cardPositionX, int cardPositionY) Getter to obtain card of player at specific position.intgetCurrentDimensionsX(int playerIndex) Getter for current amount of cards horizontally laid out in front of specified player.intgetCurrentDimensionsY(int playerIndex) Getter for current amount of cards vertically laid out in front of specified player.intGetter for the index of the current player.intReturns index of player who triggered game end, if isGameOverInitiated returns true.intReturns the initial amount of cards horizontally laid out in front of each player.intReturns 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.intgetRound()Getter for round counter.booleanisAllPlayerCardsRevealed(int playerIndex) booleanTells whether the model currently has a dedicated buffer card, i.e.booleanbooleanthis.players[i].reduceColumn(); Tells if at least one player has all their cards revealed.booleanisPlayerCardAtPositionRevealed(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.CardReturns Card of topmost discard pile card (without removing card from discard pile).ca.uqam.info.mgl7010.max.skyjo.model.CardRetrieves (and implicitly removes) the buffer card.ca.uqam.info.mgl7010.max.skyjo.model.CardpopDeck()Retrieves the topmost deck card, implicitly removing the card from the deck.ca.uqam.info.mgl7010.max.skyjo.model.CardRetrieves the topmost discard pile card, implicitly removing the card from the discard pile.voidpushDiscardPile(ca.uqam.info.mgl7010.max.skyjo.model.Card card) Required for undoing operations.ca.uqam.info.mgl7010.max.skyjo.model.CardreplacePlayerCard(int playerIndex, int x, int y, ca.uqam.info.mgl7010.max.skyjo.model.Card card) Replaces a player's card by another provided card.voidrevealPlayerCard(int playerIndex, int x, int y) Reveals a concealed card in a player's card arrangement, specified by player and x-y position.voidsetBufferCard(ca.uqam.info.mgl7010.max.skyjo.model.Card card) Sets the provided card as buffer card, i.e.voidMarks the current player as game ender, i.e.
-
Constructor Details
-
SkyjoModelImpl
-
-
Method Details
-
getAmountPlayers
public int getAmountPlayers()Getter to look up how many players are involved in the current session.- Specified by:
getAmountPlayersin interfaceca.uqam.info.mgl7010.max.skyjo.model.SkyjoModelReadOnly- Returns:
- int representing amount of players in session.
-
getPlayerName
Returns the plain string name of a players, specified by index.- Specified by:
getPlayerNamein interfaceca.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:
isPlayerCardAtPositionRevealedin interfaceca.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:
isAllPlayerCardsRevealedin interfaceca.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:
getCardForPlayerByPositionin interfaceca.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:
getCurrentPlayerIndexin interfaceca.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:
peekDiscardPilein interfaceca.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:
getBufferCardin interfaceca.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:
isBufferCardPresentin interfaceca.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:
getPlayerScoresin interfaceca.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:
getInitialDimensionsXin interfaceca.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:
getInitialDimensionsYin interfaceca.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:
getCurrentDimensionsXin interfaceca.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:
getCurrentDimensionsYin interfaceca.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:
isGameOverInitializedin interfaceca.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:
isGameOverin interfaceca.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:
getGameEnderin interfaceca.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:
getAmountDiscardPileCardsin interfaceca.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:
getAmountDeckCardsin interfaceca.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:
getRoundin interfaceca.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:
revealPlayerCardin interfaceca.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:
endGamein interfaceca.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:
replacePlayerCardin interfaceca.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:
eliminateRowin interfaceca.uqam.info.mgl7010.max.skyjo.model.SkyjoModel
-
eliminateColumn
public void eliminateColumn(int i, int i1) - Specified by:
eliminateColumnin interfaceca.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:
popDeckin interfaceca.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:
popDiscardPilein interfaceca.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:
pushDiscardPilein interfaceca.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:
setBufferCardin interfaceca.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:
popBufferCardin interfaceca.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:
advancePlayerin interfaceca.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:
setGameEnderin interfaceca.uqam.info.mgl7010.max.skyjo.model.SkyjoModel
-