Class: StackWars::TextClient

Inherits:
Object
  • Object
show all
Defined in:
lib/stack_wars/text_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(game) ⇒ TextClient

Returns a new instance of TextClient.



3
4
5
# File 'lib/stack_wars/text_client.rb', line 3

def initialize(game)
  @game = game
end

Instance Method Details

#play(string) ⇒ Object

Raises:



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/stack_wars/text_client.rb', line 7

def play(string)
  md = string.match(/^ *(?<pos1>\d+ +\d+) *(?<pos2>\d+ +\d+)? *$/)

  raise Errors::ParseError unless md

  if md[:pos2]
    @game.play(point(md[:pos1]), point(md[:pos2]))
  else
    @game.play(point(md[:pos1]))
  end
end