Class: Robot::Simulator::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/robot/simulator/controller.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeController

Returns a new instance of Controller.



9
10
11
# File 'lib/robot/simulator/controller.rb', line 9

def initialize
  @robot = Robot.new Table.new(5, 5)
end

Instance Attribute Details

#robotObject (readonly)

Returns the value of attribute robot.



7
8
9
# File 'lib/robot/simulator/controller.rb', line 7

def robot
  @robot
end

Instance Method Details

#leftObject



21
22
23
# 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

#moveObject



17
18
19
# 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) ⇒ Object



13
14
15
# 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

#reportObject



29
30
31
# 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

#rightObject



25
26
27
# 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