java.lang.Object
polimi.ingsw.am21.codex.model.Game
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a player to the game.drawHand()
Draws a pair of objective cards from the deck.Draws a starter card from the deck.getChat()
Gets the current player.Gets the index of current player.getLobby()
Gets the lobby associated with the game.Gets a player from the nicknameGets the players in the game.getPlayerState
(String nickname) Gets the state of a player.Gets the remaining rounds in the game.Gets the scoreboard of the game.getState()
Gets the state of the game.void
insertObjectiveCard
(ObjectiveCard objectiveCard) void
insertStarterCard
(PlayableCard starterCard) Checks if the game is over.void
runs nextTurnExecute()void
nextTurn
(DrawingCardSource drawingSource, DrawingDeckType deckType, BiConsumer<Integer, Integer> nextTurnEventAfterDraw, Runnable nextTurnWithoutDraw, Consumer<Integer> remainingRoundsChange) Draws the player card and runs nextTurnExecute();void
playerDisconnected
(String player) void
playerReconnected
(String player) void
Sets the game to be over.void
start()
Starts the game.
-
Constructor Details
-
Game
public Game(int players) -
Game
public Game(int players, org.json.JSONArray cards)
-
-
Method Details
-
getLobby
Gets the lobby associated with the game.- Returns:
- The lobby associated with the game.
-
start
Starts the game. -
drawObjectiveCardPair
Draws a pair of objective cards from the deck.- Returns:
- A pair of objective cards drawn from the deck.
- Throws:
EmptyDeckException
- When the deck being drawn from is empty.
-
getState
Gets the state of the game.- Returns:
- The state of the game.
-
getPlayerState
Gets the state of a player.- Parameters:
nickname
- The nickname of the player.- Returns:
- The state of the player.
- Throws:
PlayerNotFoundGameException
- If the player is not found.
-
getScoreBoard
Gets the scoreboard of the game.- Returns:
- The scoreboard of the game.
-
getCurrentPlayer
Gets the current player.- Returns:
- The current player.
-
getPlayer
Gets a player from the nickname- Parameters:
nickname
- The nickname of the player you're looking for- Throws:
PlayerNotFoundGameException
-
getPlayers
Gets the players in the game. -
getCurrentPlayerIndex
Gets the index of current player.- Returns:
- The index of current player.
-
addPlayer
Adds a player to the game.- Parameters:
player
- The player to add.
-
isGameOver
Checks if the game is over.- Returns:
- True if the game is over, otherwise false.
-
setGameOver
public void setGameOver()Sets the game to be over. -
getRemainingRounds
Gets the remaining rounds in the game.- Returns:
- The remaining rounds in the game, if any.
-
isGameHalted
-
nextTurn
public void nextTurn(DrawingCardSource drawingSource, DrawingDeckType deckType, BiConsumer<Integer, Integer> nextTurnEventAfterDraw, Runnable nextTurnWithoutDraw, Consumer<Integer> remainingRoundsChange) throws InvalidActionExceptionDraws the player card and runs nextTurnExecute();- Parameters:
drawingSource
- Where we are drawing the card romdeckType
- The type of deck to draw from.nextTurnEventAfterDraw
- Callback to be called after the cards are drawn: the first parameter is the id of the card drawn by the player, the second is from the one drawn for the card pair (if any, null otherwise).nextTurnWithoutDraw
- Callback to be called if the player cannot draw a card (e.g. because the deck is empty).remainingRoundsChange
- Callback triggered if the number of remaining rounds changes (so when the next (or current) round will be the last one- Throws:
GameOverException
- If the game is over.InvalidActionException
-
nextTurn
public void nextTurn(Runnable nextTurnWithoutDraw, Consumer<Integer> remainingRoundsChange) throws InvalidActionException runs nextTurnExecute()- Parameters:
remainingRoundsChange
- Callback triggered if the number of remaining rounds changes (so when the next (or current) round will be the last one- Throws:
GameOverException
- If the game is over.InvalidActionException
-
playerDisconnected
- Throws:
PlayerNotFoundGameException
-
playerReconnected
- Throws:
PlayerNotFoundGameException
-
drawStarterCard
Draws a starter card from the deck.- Returns:
- The starter card drawn from the deck.
- Throws:
EmptyDeckException
- If the deck being drawn from is empty.
-
insertObjectiveCard
-
insertStarterCard
-
isLastRound
-
drawHand
- Throws:
EmptyDeckException
-
getPlayersCount
- Returns:
- the number of connected players
-
getMaxPlayers
- Returns:
- the number of maximum players
-
getPlayersSpotsLeft
-
getObjectiveCards
-
getResourceCards
-
getGoldCards
-
getChat
-
getGameBoard
-