Interface GameServer<T extends QuizGame>

  • Type Parameters:
    T - the type of QuizGame the server works with

    public interface GameServer<T extends QuizGame>
    Core object of library. Represents a server with no game logic that listens to game events.

    All quiz implementations should at least have a QuizGame object with a server that receives updates from the game via a ServerGate. A server's purpose should usually be to display information when received, in its own custom way. For the purpose of flexibility, the server is generic thus determines what type of quiz game it works with. Servers should usually never store game instances themselves, since the latter are provided in the event methods that should require them. Ideally, a single server instance should be able to work with as many games of the right type at the same time as needed. All additional game logic should be implemented in the quiz game rather than in the server, since all servers do is perform actions when events occur, such as displaying a question, showing the results of a round, notify players when the game ends, and so on.

    • Method Summary

      Modifier and Type Method Description
      default ServerGate<T> createGate()
      Generates a ServerGate from the server instance, with no game object set.
      void onGameOver​(java.util.List<? extends Player<?>> playerStandings, T game)
      Perform appropriate actions when a game object notifies the server that the game is over (usually when all rounds are terminated).
      void onNonEligiblePlayerGuessed​(Player<?> player)
      Perform appropriate actions when a game object notifies the server that a non eligible player tried to send a guess.
      void onPlayerGaveUp​(Player<?> player)
      Perform appropriate actions when a game object notifies the server that a player gave up on the current round.
      void onPlayerGuessed​(PlayerGuessContext context)
      Perform appropriate actions when a game object notifies the server that an eligible player sent a guess.
      void onPlayerScoreUpdated​(Player<?> player)
      Perform appropriate actions when a game object notifies the server that a player's score has been updated.
      void onQuestionReleased​(Question question)
      Perform appropriate actions when a game object notifies the server that a question was released.
      void onRoundEnded​(GameRoundReport report, T game)
      Perform appropriate actions when a game object notifies the server that a game round was terminated.
    • Method Detail

      • onRoundEnded

        void onRoundEnded​(GameRoundReport report,
                          T game)
        Perform appropriate actions when a game object notifies the server that a game round was terminated.

        Is provided a GameRoundReport instance that contains useful information about the round, such as which player won, the standings, and so on.

        Parameters:
        report - the report containing useful information about the round
        game - the game object that notified the server
      • onGameOver

        void onGameOver​(java.util.List<? extends Player<?>> playerStandings,
                        T game)
        Perform appropriate actions when a game object notifies the server that the game is over (usually when all rounds are terminated).

        Note that in such a case, onRoundEnded(GameRoundReport, QuizGame) should by convention be called before this method, since it's only after the last round ends that the game itself ends.

        Is also provided a list of players ordered by final score, from last to first that can be used as display information.

        Parameters:
        playerStandings - the list of players ordered by score
        game - the game object that notified the server
      • onPlayerGuessed

        void onPlayerGuessed​(PlayerGuessContext context)
        Perform appropriate actions when a game object notifies the server that an eligible player sent a guess.

        Is provided a PlayerGuessContext object that contains useful information about who the player is, the accuracy of their answer (from 0.0 to 1.0) and whether after sending this guess they will be eligible for future guesses in this round. Typically, if the accuracy is 100%, the eligible should, in most cases, be false since there is usually no point in accepting further answers from a player that already guessed the correct one.

        Parameters:
        context - the context containing useful information about the guess
      • onNonEligiblePlayerGuessed

        void onNonEligiblePlayerGuessed​(Player<?> player)
        Perform appropriate actions when a game object notifies the server that a non eligible player tried to send a guess.

        This event might be let empty if the server just ignores non eligible guesses. It can be used to let the player know that their guess was not taken into account.

        Parameters:
        player - the non eligible player that sent a guess
      • onPlayerGaveUp

        void onPlayerGaveUp​(Player<?> player)
        Perform appropriate actions when a game object notifies the server that a player gave up on the current round.

        Players who give up become non eligible players for the rest of the round.

        Parameters:
        player - the player who gave up on the round
      • onPlayerScoreUpdated

        void onPlayerScoreUpdated​(Player<?> player)
        Perform appropriate actions when a game object notifies the server that a player's score has been updated.

        Usually, scores are never updated before the end of the round. Conventionally, since score updates are part of a round, score updates should be called before onRoundEnded(GameRoundReport, QuizGame).

        Parameters:
        player - the player whose score was updated
      • onQuestionReleased

        void onQuestionReleased​(Question question)
        Perform appropriate actions when a game object notifies the server that a question was released.

        Usually, this method will be used to display the given question so that the players can read it.

        Parameters:
        question - the question that is to be revealed to the players