Commit fc234bd

mo k <mo@mokhan.ca>
2012-11-04 20:51:30
start to extract a location object.
1 parent 4c99a33
Changed files (1)
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}"