Class: Robot::Simulator::Controller
- Inherits:
-
Object
- Object
- Robot::Simulator::Controller
- Defined in:
- lib/robot/simulator/controller.rb
Overview
Controller of the game, initialize the game and receive commands from UI
Instance Attribute Summary collapse
-
#robot ⇒ Object
readonly
Returns the value of attribute robot.
Instance Method Summary collapse
-
#initialize ⇒ Controller
constructor
A new instance of Controller.
- #left ⇒ Object
- #move ⇒ Object
- #place(x, y, facing) ⇒ Object
- #report ⇒ Object
- #right ⇒ Object
Constructor Details
#initialize ⇒ Controller
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
#robot ⇒ Object (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
#left ⇒ Object
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 |
#move ⇒ Object
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 |
#report ⇒ Object
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 |
#right ⇒ Object
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 |