Commit fc234bd
Changed files (1)
lib
lib/rover.rb
@@ -1,9 +1,8 @@
class Rover
- attr_reader :location
def initialize(heading, x, y, plateau)
@heading = heading
- @location = {:x => x, :y => y}
@plateau = plateau
+ @location = Location.new(x, y, heading)
end
def heading
@heading.class.name.downcase.to_sym
@@ -12,7 +11,20 @@ class Rover
@heading = @heading.rotate(degrees)
end
def forward
- @plateau.move_forward(@heading, @location)
+ @plateau.move_forward(@heading, @location.location)
+ end
+ def location
+ @location.location
+ end
+ def to_s
+ @location.to_s
+ end
+end
+class Location
+ attr_reader :location
+ def initialize(x, y, heading)
+ @location = {:x => x, :y => y}
+ @heading =heading
end
def to_s
"#{@location[:x]} #{@location[:y]} #{@heading}"