Skip to content

Implementing a Game Engine

Phrogz edited this page Oct 28, 2011 · 3 revisions

Game engines currently run along with the Laink server, in the same process, and so (for now) must be written in Ruby. See domohnoes.rb for an example game.

In the future these should move to a separate process using the same communication framework, turning the server into a lightweight broker for setting up games. This will require games to support n reader threads for n players, instead of the server doing this.

To add a new game type supported by the server:

  1. require the gametype.rb file.

  2. Create a new class that subclasses Laink::GameType.

  3. Add the required method calls:

     sig     "com.danceliquid.domohnoes" # The unique signature identifying this game type
     name    "Domohnoes"                 # A nice name for your game
     players 2..4                        # The number of players supported (may be an integer or range)
    
  4. [optional] Provide an initialize method that calls super().

  5. [optional] Provide a start method that calls super().

  6. Provide a current_player method that returns the appropriate item from the players array

  7. Provide a state method that, given a player from the players array, returns an object that supports to_json and describes everything a player would need to know to make a move. (And nothing they shouldn't know!)

  8. Provide a handle_message_from(player) method that uses Laink::GameType#next_message to determine if there's a message on the queue that the game knows how to handle, and process it. Most important, be able to handle {"command":"move"} messages, ensuring that the player is the current_player.

  9. Call finish_game(winning_player) on the superclass when the game is over.

Clone this wiki locally