Creating a Custom Game - TometoTom/MonkyGams GitHub Wiki

bitmoji

Creating a game

  1. You must firstly add the game to the GameType enumeration.
  2. You must then add an if statement in the GameController.startGame() method for that specific game.
  3. You must create a class and extend Game.
  4. You must implement the start() and end() methods, as well as the registerListeners() method.
    • The start() method is executed as soon as the game is started. Having nothing in this method will make the game do absolutely nothing.
    • The end() method must be used for cleaning up and disabling game specific events.
    • The registerListeners() method is likely to be made optional in the future. It is a contained method for registering game-specific listeners.

Registering Game-Specific Listeners

You can the methods:

  • registerEvent(Listener)
  • deregisterEvent(Listener)
  • deregisterAllEvents()

Countdown

You can use the method doCountdown(Runnable) for the pre-game countdown. The runnable is what code should be executed after the countdown.

Scoreboard

By default, every game has a scoreboard pre-created with no contents. You can use getScoreboard() to obtain this scoreboard and add data to it using either:

  • setLine(index, text)
  • addLine() Please keep in mind that doing set line will not work if the index is out of bounds. You can update the scoreboard using doScoreboardUpdating(Runnable). The runnable signifies which code should be executed every update. The scoreboard is non-flickering and updates every 1 tick. You can also use resetStartTime() and getScoreboardFriendlyTime() to record time.

Starting and Ending Games

To start a game, you must use GameController.startNewGame(). To end a game, you must use GameController.endCurrentGame(). The start() and end() methods in game should not be called manually.