Package game

Class GameVerticle

java.lang.Object
io.vertx.core.AbstractVerticle
game.GameVerticle
All Implemented Interfaces:
IGameAgent, io.vertx.core.Verticle

public class GameVerticle extends io.vertx.core.AbstractVerticle implements IGameAgent
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
  • Constructor Details

  • Method Details

    • start

      public void start(io.vertx.core.Promise<Void> startPromise)
      It starts the verticle
      Specified by:
      start in interface io.vertx.core.Verticle
      Overrides:
      start in class io.vertx.core.AbstractVerticle
    • addUser

      public boolean addUser(User user)
      Returns:
      true if the user is added
    • setPassword

      public void setPassword(String password)
      Parameters:
      password - of the game
    • checkPasword

      public boolean checkPasword(String pwd)
      Returns:
      true if the password is correct
    • addCard

      public boolean addCard(Card<CardValue,CardSuit> card, String username, Boolean isSuitAdded)
      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

      public void chooseTrump(CardSuit suit)
      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

      public boolean makeCall(Call call, String username)
      Parameters:
      call - the call
      username - the user who makes the call
      Returns:
      true if the call is made correctly
    • getId

      public UUID getId()
    • getGameSchema

      public GameSchema getGameSchema()
    • getStates

      public Map<Integer,Trick> getStates()
    • getCurrentState

      public AtomicInteger getCurrentState()
    • setCurrentState

      public void setCurrentState(int value)
      Parameters:
      value -
    • getCurrentTrick

      public Trick getCurrentTrick()
    • setCurrentTrick

      public void setCurrentTrick(Trick trick)
    • getLatestTrick

      public Trick getLatestTrick()
    • getTricks

      public List<Trick> getTricks()
    • getInitialTurn

      public int getInitialTurn()
    • setInitialTurn

      public void setInitialTurn(int initTurn)
    • getTurn

      public int getTurn()
    • setTurn

      public void setTurn(int turn)
    • getUsers

      public List<User> getUsers()
    • getPositionByUsername

      public int getPositionByUsername(String username)
    • getIsSuitFinished

      public List<Boolean> getIsSuitFinished()
    • clearIsSuitFinished

      public void clearIsSuitFinished()
    • setIsSuitFinished

      public boolean setIsSuitFinished(Boolean value, String username, Boolean isValid)
    • 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 trick
      isTeamA - true if team A won the trick
    • getTrump

      public CardSuit getTrump()
    • getStatus

      public Status getStatus()
    • getUserCards

      public List<Card<CardValue,CardSuit>> getUserCards(String username)
    • isCompleted

      public boolean isCompleted()
      Returns:
      true if the current trick is completed
    • getGameMode

      public GameMode getGameMode()
    • incrementCurrentState

      public void incrementCurrentState(String... from)
      increment the current state
    • changeTeam

      public boolean changeTeam(String username, String team, Integer pos)
      a player change a team
    • isUserIn

      public boolean isUserIn(String user)
      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

      public Optional<String> 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

      public void removeUser(String username)
      Parameters:
      username - to be removed
    • toJson

      public io.vertx.core.json.JsonObject toJson()
      Returns:
      a json with id, status and game mode
    • onCreateGame

      public void onCreateGame(User user)
      Specified by:
      onCreateGame in interface IGameAgent
    • onJoinGame

      public void onJoinGame(User user)
      Specified by:
      onJoinGame in interface IGameAgent
    • onStartGame

      public void onStartGame()
      Specified by:
      onStartGame in interface IGameAgent
    • onCheckMaraffa

      public void onCheckMaraffa(int suit, int value, int trump, String username)
      Specified by:
      onCheckMaraffa in interface IGameAgent
    • onChangeTeam

      public void onChangeTeam()
      Specified by:
      onChangeTeam in interface IGameAgent
    • onPlayCard

      public void onPlayCard()
      Specified by:
      onPlayCard in interface IGameAgent
    • onTrickCompleted

      public CompletableFuture<Void> onTrickCompleted(Trick latestTrick)
      Specified by:
      onTrickCompleted in interface IGameAgent
    • onMessage

      public void onMessage()
      Specified by:
      onMessage in interface IGameAgent
    • onEndRound

      public void onEndRound()
      Specified by:
      onEndRound in interface IGameAgent
    • onEndGame

      public void onEndGame()
      Specified by:
      onEndGame in interface IGameAgent
    • handOutCards

      public void handOutCards(List<Integer> list)
    • onMakeCall

      public void onMakeCall(Call call)
      Specified by:
      onMakeCall in interface IGameAgent
    • onNewRound

      public void onNewRound()
      Specified by:
      onNewRound in interface IGameAgent
    • onNewGame

      public void onNewGame(String newGameID)
      Specified by:
      onNewGame in interface IGameAgent
    • setTurnWithUser

      public void setTurnWithUser(String username)
    • onRemoveUser

      public void onRemoveUser()
      Specified by:
      onRemoveUser in interface IGameAgent
    • messageReceived

      public void messageReceived(String msg, String type, UUID gameID, String author)
    • canPlayCard

      public void canPlayCard(Card<CardValue,CardSuit> card, String username)
    • onExitGame

      public void onExitGame()