class Robot::Simulator::Controller

Controller of the game, initialize the game and receive commands from UI

Attributes

robot[R]

Public Class Methods

new() click to toggle source
# File lib/robot/simulator/controller.rb, line 9
def initialize
  @robot = Robot.new Table.new(5, 5)
end

Public Instance Methods

left() click to toggle source
# File lib/robot/simulator/controller.rb, line 21
def left
  raise "Invalid LEFT command: robot is not on the table" unless robot.turn_left
end
move() click to toggle source
# File lib/robot/simulator/controller.rb, line 17
def move
  raise "Invalid MOVE command: robot is not on the table or could fall if move" unless robot.move
end
place(x, y, facing) click to toggle source
# File lib/robot/simulator/controller.rb, line 13
def place(x, y, facing)
  raise "Invalid PLACE command: PLACE #{x},#{y},#{facing}" unless robot.place Coordinate.new(x, y), Direction.from_str(facing)
end
report() click to toggle source
# File lib/robot/simulator/controller.rb, line 29
def report
  [robot.current_track.coordinate.x, robot.current_track.coordinate.y, Direction.to_str(robot.current_track.facing)] if robot.current_track
end
right() click to toggle source
# File lib/robot/simulator/controller.rb, line 25
def right
  raise "Invalid RIGHT command: robot is not on the table" unless robot.turn_right
end