Package game
Class GameVerticle
java.lang.Object
io.vertx.core.AbstractVerticle
game.GameVerticle
- All Implemented Interfaces:
IGameAgent
,io.vertx.core.Verticle
This class models a game using a Verticle from vertx.
id = the id of the verticle
numberOfPlayers = the numbers of players of this game
stateMap = it saves each state with the related trick
users = it keeps track of all the users added to the game
-
Field Summary
Fields inherited from class io.vertx.core.AbstractVerticle
context, vertx
-
Constructor Summary
ConstructorDescriptionGameVerticle
(UUID id, User user, int numberOfPlayers, int expectedScore, GameMode gameMode, String password) GameVerticle
(UUID id, User user, int numberOfPlayers, int expectedScore, GameMode gameMode, AbstractStatisticManager statisticManager, WebSocketVertx webSocket) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds the card if the trick is not completed, otherwise it adds the card to a new trick and updates the current stateboolean
boolean
void
canPlayCard
(Card<CardValue, CardSuit> card, String username) boolean
canStart()
boolean
changeTeam
(String username, String team, Integer pos) a player change a teamboolean
checkPasword
(String pwd) void
chooseTrump
(CardSuit suit) void
void
endRoundByMistake
(boolean firstTeam) Set the team who lose the game because of a mistakeint
getId()
int
int
int
int
getPositionByUsername
(String username) getTrump()
int
getTurn()
getUserCards
(String username) getUsers()
void
handOutCards
(List<Integer> list) void
incrementCurrentState
(String... from) increment the current stateboolean
boolean
boolean
boolean
boolean
boolean
void
messageReceived
(String msg, String type, UUID gameID, String author) void
void
onCheckMaraffa
(int suit, int value, int trump, String username) void
onCreateGame
(User user) void
void
void
void
onJoinGame
(User user) void
onMakeCall
(Call call) void
void
void
void
void
void
onTrickCompleted
(Trick latestTrick) void
removeUser
(String username) void
setCurrentState
(int value) void
setCurrentTrick
(Trick trick) void
setInitialTurn
(int initTurn) boolean
setIsSuitFinished
(Boolean value, String username, Boolean isValid) void
set the flag newGameCreated to truevoid
setPassword
(String password) void
setScore
(int score, boolean isTeamA, boolean increment) update the score of the teamsvoid
setScoreAfterMistake
(int score, boolean isFirstTeam) void
setTurn
(int turn) void
setTurnWithUser
(String username) void
It starts the verticleboolean
void
reset the trumpio.vertx.core.json.JsonObject
toJson()
Methods inherited from class io.vertx.core.AbstractVerticle
config, deploymentID, getVertx, init, processArgs, start, stop, stop
-
Constructor Details
-
GameVerticle
public GameVerticle(UUID id, User user, int numberOfPlayers, int expectedScore, GameMode gameMode, AbstractStatisticManager statisticManager, WebSocketVertx webSocket) -
GameVerticle
-
-
Method Details
-
start
It starts the verticle- Specified by:
start
in interfaceio.vertx.core.Verticle
- Overrides:
start
in classio.vertx.core.AbstractVerticle
-
addUser
- Returns:
- true if the user is added
-
setPassword
- Parameters:
password
- of the game
-
checkPasword
- Returns:
- true if the password is correct
-
addCard
Adds the card if the trick is not completed, otherwise it adds the card to a new trick and updates the current state- Parameters:
card
- to be added to the trick
-
balancedTeams
public boolean balancedTeams()- Returns:
- true if the teams are balanced: have the same number of players
-
canStart
public boolean canStart()- Returns:
- true if all players have joined the game and if the teams are balanced
-
chooseTrump
- Parameters:
suit
- the leading suit of the round
-
startGame
public boolean startGame()- Returns:
- true if all the players are in
-
startNewRound
public void startNewRound()reset the trump -
makeCall
- Parameters:
call
- the callusername
- the user who makes the call- Returns:
- true if the call is made correctly
-
getId
-
getGameSchema
-
getStates
-
getCurrentState
-
setCurrentState
public void setCurrentState(int value) - Parameters:
value
-
-
getCurrentTrick
-
setCurrentTrick
-
getLatestTrick
-
getTricks
-
getInitialTurn
public int getInitialTurn() -
setInitialTurn
public void setInitialTurn(int initTurn) -
getTurn
public int getTurn() -
setTurn
public void setTurn(int turn) -
getUsers
-
getPositionByUsername
-
getIsSuitFinished
-
clearIsSuitFinished
public void clearIsSuitFinished() -
setIsSuitFinished
-
setScoreAfterMistake
public void setScoreAfterMistake(int score, boolean isFirstTeam) -
setScore
public void setScore(int score, boolean isTeamA, boolean increment) update the score of the teams- Parameters:
score
- of the team who won the trickisTeamA
- true if team A won the trick
-
getTrump
-
getStatus
-
getUserCards
-
isCompleted
public boolean isCompleted()- Returns:
- true if the current trick is completed
-
getGameMode
-
incrementCurrentState
increment the current state -
changeTeam
a player change a team -
isUserIn
- Returns:
- true if the user is in the game
-
getNumberOfPlayersIn
public int getNumberOfPlayersIn()- Returns:
- the number of players who have already joined the game
-
getExpectedScore
public int getExpectedScore()- Returns:
- the expected score a team should obtain in order to win the game
-
isNewGameCreated
public boolean isNewGameCreated()- Returns:
- the flag newGameCreated
-
setNewGameCreated
public void setNewGameCreated()set the flag newGameCreated to true -
getMaxNumberOfPlayers
public int getMaxNumberOfPlayers()- Returns:
- the number of players for this game
-
getPassword
- Returns:
- the password of this game,
-
endRoundByMistake
public void endRoundByMistake(boolean firstTeam) Set the team who lose the game because of a mistake -
isRoundEnded
public boolean isRoundEnded()- Returns:
- true if the round is ended
-
isGameEnded
public boolean isGameEnded()- Returns:
- true if the game is ended
-
removeUser
- Parameters:
username
- to be removed
-
toJson
public io.vertx.core.json.JsonObject toJson()- Returns:
- a json with id, status and game mode
-
onCreateGame
- Specified by:
onCreateGame
in interfaceIGameAgent
-
onJoinGame
- Specified by:
onJoinGame
in interfaceIGameAgent
-
onStartGame
public void onStartGame()- Specified by:
onStartGame
in interfaceIGameAgent
-
onCheckMaraffa
- Specified by:
onCheckMaraffa
in interfaceIGameAgent
-
onChangeTeam
public void onChangeTeam()- Specified by:
onChangeTeam
in interfaceIGameAgent
-
onPlayCard
public void onPlayCard()- Specified by:
onPlayCard
in interfaceIGameAgent
-
onTrickCompleted
- Specified by:
onTrickCompleted
in interfaceIGameAgent
-
onMessage
public void onMessage()- Specified by:
onMessage
in interfaceIGameAgent
-
onEndRound
public void onEndRound()- Specified by:
onEndRound
in interfaceIGameAgent
-
onEndGame
public void onEndGame()- Specified by:
onEndGame
in interfaceIGameAgent
-
handOutCards
-
onMakeCall
- Specified by:
onMakeCall
in interfaceIGameAgent
-
onNewRound
public void onNewRound()- Specified by:
onNewRound
in interfaceIGameAgent
-
onNewGame
- Specified by:
onNewGame
in interfaceIGameAgent
-
setTurnWithUser
-
onRemoveUser
public void onRemoveUser()- Specified by:
onRemoveUser
in interfaceIGameAgent
-
messageReceived
-
canPlayCard
-
onExitGame
public void onExitGame()
-