Class: RubySnake::Client
- Inherits:
-
Object
- Object
- RubySnake::Client
- Defined in:
- lib/ruby_snake/client.rb
Class Attribute Summary collapse
-
.message ⇒ Object
Returns the value of attribute message.
-
.receive ⇒ Object
Returns the value of attribute receive.
Class Method Summary collapse
Class Attribute Details
.message ⇒ Object
Returns the value of attribute message.
6 7 8 |
# File 'lib/ruby_snake/client.rb', line 6 def @message end |
.receive ⇒ Object
Returns the value of attribute receive.
6 7 8 |
# File 'lib/ruby_snake/client.rb', line 6 def receive @receive end |
Class Method Details
.connect(host = '127.0.0.1') ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ruby_snake/client.rb', line 8 def connect(host='127.0.0.1') @message ||= '0' server = TCPSocket.new host, 2000 server.send @message, 0 = server.recv(4096) case when '0' @message = ([Game.snake.food] + Game.snake.body).join(',').to_s if Game.snake when '1' Game.win when '2' Game.lose else @message = ([Game.snake.food] + Game.snake.body).join(',').to_s if Game.snake @receive = .split(',').map(&:to_i).each_slice(2).to_a if end end |