Class: RubySnake::Client
- Inherits:
-
Object
- Object
- RubySnake::Client
- Defined in:
- lib/ruby_snake/client.rb
Class Attribute Summary collapse
-
.food ⇒ Object
Returns the value of attribute food.
-
.message ⇒ Object
Returns the value of attribute message.
-
.snake ⇒ Object
Returns the value of attribute snake.
Class Method Summary collapse
Class Attribute Details
.food ⇒ Object
Returns the value of attribute food.
6 7 8 |
# File 'lib/ruby_snake/client.rb', line 6 def food @food end |
.message ⇒ Object
Returns the value of attribute message.
6 7 8 |
# File 'lib/ruby_snake/client.rb', line 6 def end |
.snake ⇒ Object
Returns the value of attribute snake.
6 7 8 |
# File 'lib/ruby_snake/client.rb', line 6 def snake @snake 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ruby_snake/client.rb', line 8 def connect(host='127.0.0.1') = '0' loop do sleep Game.speed begin server = TCPSocket.new host, 2000 rescue => err = '10' break end server.send , 0 = server.recv(4096) case when '0' = '1' when '1' = ([Game.snake.food] + Game.snake.body).join(',').to_s if Game.snake when '2' Game.win break when '3' Game.lose break else = ([Game.snake.food] + Game.snake.body).join(',').to_s if Game.snake array = .split(',').map(&:to_i).each_slice(2).to_a if if array @food = array.shift @snake = array end end end end |