-
Notifications
You must be signed in to change notification settings - Fork 0
Implementing a Game Engine
Game engines run along with the Laink server, in the same process, and so must be written in Ruby. See domohnoes.rb for an example game.
To add a new game type supported by the server:
-
requirethegametype.rbfile. -
Create a new class that subclasses
Laink::GameType. -
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) -
[optional] Provide an
initializemethod that callssuper(). -
[optional] Provide a
startmethod that callssuper(). -
Provide a
current_playermethod that returns the appropriate item from theplayersarray -
Provide a
statemethod that, given a player from theplayersarray, returns an object that supportsto_jsonand describes everything a player would need to know to make a move. (And nothing they shouldn't know!) -
Provide a
handle_message_from(player)method that usesLaink::GameType#next_messageto 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 thecurrent_player. -
Call
finish_game(winning_player)on the superclass when the game is over.