Class: ClasslessMud::Client
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- ClasslessMud::Client
- Defined in:
- lib/classless_mud/client.rb
Instance Attribute Summary collapse
-
#player ⇒ Object
readonly
Returns the value of attribute player.
Instance Method Summary collapse
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #on(&callback) ⇒ Object
- #puts(message) ⇒ Object
- #receive_data(data) ⇒ Object
- #start(game) ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
16 17 18 |
# File 'lib/classless_mud/client.rb', line 16 def initialize @callbacks = [] end |
Instance Attribute Details
#player ⇒ Object (readonly)
Returns the value of attribute player.
14 15 16 |
# File 'lib/classless_mud/client.rb', line 14 def player @player end |
Instance Method Details
#on(&callback) ⇒ Object
39 40 41 |
# File 'lib/classless_mud/client.rb', line 39 def on &callback @callbacks.push callback end |
#puts(message) ⇒ Object
43 44 45 |
# File 'lib/classless_mud/client.rb', line 43 def puts send_data "#{message}\n" end |
#receive_data(data) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/classless_mud/client.rb', line 28 def receive_data data data = data.chomp if @callbacks.any? callback = @callbacks.pop callback.call(data) else player.(data) end player.display_prompt if player end |
#start(game) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/classless_mud/client.rb', line 20 def start game @game = game send_data MOTD ::ClasslessMud::AccountBuilder.create(self, game) { |player| @player = player } end |