class Rover
Rover
class that stores rover position state
Attributes
x[RW]
y[RW]
Public Class Methods
new(zone, position_string)
click to toggle source
# File lib/rover.rb, line 7 def initialize(zone, position_string) @zone = zone parsed_position = position_string.split(' ') coordinates = parsed_position[0].split('') @x = coordinates[0].to_i @y = coordinates[1].to_i @direction_key = parsed_position[1] @tracer = tracer end
Public Instance Methods
decrease_x()
click to toggle source
# File lib/rover.rb, line 29 def decrease_x @x -= 1 end
decrease_y()
click to toggle source
# File lib/rover.rb, line 37 def decrease_y @y -= 1 end
direction()
click to toggle source
# File lib/rover.rb, line 17 def direction @tracer.to_s end
increase_x()
click to toggle source
# File lib/rover.rb, line 21 def increase_x @x += 1 end
increase_y()
click to toggle source
# File lib/rover.rb, line 33 def increase_y @y += 1 end
move()
click to toggle source
# File lib/rover.rb, line 25 def move @tracer.move(self) end
to_s()
click to toggle source
# File lib/rover.rb, line 41 def to_s "#{@x} #{@y} #{direction}" end
tracer()
click to toggle source
# File lib/rover.rb, line 53 def tracer case @direction_key when 'N' Tracers::North.new when 'E' Tracers::East.new when 'S' Tracers::South.new when 'W' Tracers::West.new end end
turn_left()
click to toggle source
# File lib/rover.rb, line 45 def turn_left @tracer = @tracer.turn_left end
turn_right()
click to toggle source
# File lib/rover.rb, line 49 def turn_right @tracer = @tracer.turn_right end