Interface QuizGame

  • All Known Implementing Classes:
    DefaultSimpleGame, SimpleGame

    public interface QuizGame
    Core object of the library. Represents a quiz game containing all the necessary logic.

    Quiz games should contain:

    • Support for pausing and resuming (through pause() and resume()).
    • Support for force stopping (through forceStop()
    • A way for objects depending on the game to request interaction with the server (through sendInputToServer(Consumer). Typically, when a question is released, it will ask the game to transmit the information to the server.
    • Support for input reception (through onInputReceived(Object, String). All the game logic depends on the inputs sent by players. When and how input is sent depends on each implementation.
    • A way to externally request the next round to start, if the current one is finished (through nextRound()). By default, when a round terminates, the game will be paused until it is asked to continue.
    • A system that detects whether the current round terminated and performs actions accordingly (through checkEndOfRound(GameRound).
    • Other minor utility methods that can be useful externally
    See SimpleGame for the main implementation.
    • Method Summary

      Modifier and Type Method Description
      void checkEndOfRound​(GameRound current)
      Require the game to check whether the current round is over.
      boolean containsPlayerId​(java.lang.Object id)
      Retrieve whether the game contains the player with the given ID.
      void forceStop()
      Force-stop the game, shutting down all communications with players.
      boolean isCurrentRoundFinished()
      Determine whether the round currently in action is finished and should thus be skipped.
      boolean nextRound()
      Skip the current round (usually when over) and start the following one.
      void onInputReceived​(java.lang.Object playerId, java.lang.String message)
      Main communication gate between the players and the game logic.
      void pause()
      Pause the game.
      void removePlayer​(java.lang.Object playerId)
      Remove a player of the player list, if present
      void resume()
      Resume the game after it was paused.
      void sendInputToServer​(java.util.function.Consumer<GameServer<?>> action)
      Main communication gate between the game object and a GameServer.
      void start()
      Start the game.
      void update()
      Update the game object, allowing the latter to perform periodic actions such as even triggering, if needed.
    • Method Detail

      • start

        void start()
        Start the game. No interaction with the game object should be allowed unless a unique call to `start` was previously made.
      • pause

        void pause()
        Pause the game. The common behavior of this method should be to ignore all communications from players until resume() is called.
      • resume

        void resume()
        Resume the game after it was paused. If the game wasn't paused, the method has no effect
      • update

        void update()
        Update the game object, allowing the latter to perform periodic actions such as even triggering, if needed. The call frequency of update is up to the game object handler
      • forceStop

        void forceStop()
        Force-stop the game, shutting down all communications with players. Assuming the default game system, quiz games should naturally stop when all rounds are played
      • isCurrentRoundFinished

        boolean isCurrentRoundFinished()
        Determine whether the round currently in action is finished and should thus be skipped.
        Returns:
        whether the current round is over
      • containsPlayerId

        boolean containsPlayerId​(java.lang.Object id)
        Retrieve whether the game contains the player with the given ID.
        Parameters:
        id - an object representing a player ID
        Returns:
        whether the object is present in the player list of the game
      • nextRound

        boolean nextRound()
        Skip the current round (usually when over) and start the following one.
        Returns:
        whether the operation was a success
      • onInputReceived

        void onInputReceived​(java.lang.Object playerId,
                             java.lang.String message)
        Main communication gate between the players and the game logic. The game handler should call this method when a player sends whatever input that must be transmitted to the game. Whether the player was eligible for sending a message should be decided by the game itself, not beforehand.
        Parameters:
        playerId - the ID of the player who sent a message
        message - the message provided
      • checkEndOfRound

        void checkEndOfRound​(GameRound current)
        Require the game to check whether the current round is over. Even though usually called internally, the method can also be called when an exterior factor may make the round terminate. Timers are a good example, since they should usually be handled externally.
        Parameters:
        current - the current round
      • sendInputToServer

        void sendInputToServer​(java.util.function.Consumer<GameServer<?>> action)
        Main communication gate between the game object and a GameServer. This method is often used by the game rounds, who would like to notify the server that a particular event should be triggered. The default implementation of QuizGame uses `ServerGate`s, as an additional layer for game-server communication.
        Parameters:
        action - the action to perform from a `GameServer` object
        See Also:
        ServerGate
      • removePlayer

        void removePlayer​(java.lang.Object playerId)
        Remove a player of the player list, if present
        Parameters:
        playerId - the ID of the player that is to be removed