Module: Commands

Included in:
Robotgame::Robot
Defined in:
lib/robotgame/commands.rb

Overview

require “pry”

Instance Method Summary collapse

Instance Method Details

#leftObject

Raises:



25
26
27
28
29
30
# File 'lib/robotgame/commands.rb', line 25

def left
  raise InvalidCommand.new("cannot turn left before placing on table") unless @facing
  @facing = @facing.left
  #binding.pry
  return;
end

#moveObject

Raises:



16
17
18
19
20
21
22
23
# File 'lib/robotgame/commands.rb', line 16

def move
  raise InvalidCommand.new("cannot move before placing on table") unless @facing
  new_x, new_y = @facing.advance(@x, @y)
  validate(new_x, new_y, @facing)
  @x, @y = new_x, new_y
  #binding.pry
  return;
end

#place(x, y, facing) ⇒ Object

include Direction



6
7
8
9
10
11
12
13
14
# File 'lib/robotgame/commands.rb', line 6

def place(x, y, facing)
  validate(x = (x.to_i if /\A\d+\Z/.match(x)),
           y = (y.to_i if /\A\d+\Z/.match(y)),
           facing = Direction[facing.upcase])
  @x, @y, @facing = x, y, facing
  #binding.pry
  return;
  #@output.puts "#{@x},#{@y},#{@face}"
end

#reportObject

Raises:



39
40
41
42
43
44
# File 'lib/robotgame/commands.rb', line 39

def report
  raise InvalidCommand.new("cannot report before placing on table") unless @facing
  #@output.puts "#{@x},#{@y},#{@facing}"
  #binding.pry
  return "#{@x},#{@y},#{@facing}"
end

#rightObject

Raises:



32
33
34
35
36
37
# File 'lib/robotgame/commands.rb', line 32

def right
  raise InvalidCommand.new("cannot turn right before placing on table") unless @facing
  @facing = @facing.right
  #binding.pry
  return;
end