Commit c58d15f

mo k <mo@mokhan.ca>
2012-08-11 05:39:11
start to refactor bounds check.
1 parent 94e5e26
Changed files (2)
lib/rover.rb
@@ -3,6 +3,7 @@ class Rover
   def initialize(heading, coordinates)
     @heading = heading
     @location = coordinates
+    puts to_s
   end
   def heading
     @heading.class.name.downcase.to_sym
lib/terrain.rb
@@ -1,13 +1,19 @@
 class Terrain
   def initialize(edge_of_map)
     @map = edge_of_map
+    puts @map
   end
 
   def move_forward( heading, location)
     new_location = heading.forward(location.clone)
-    if( new_location[:x] < @map[:x] && new_location[:x] > 0 && new_location[:y] < @map[:y] && new_location[:y] > 0)
+    if(is_on_terrain(new_location, :x) && is_on_terrain(new_location, :y))
       location[:x] = new_location[:x]
       location[:y] = new_location[:y]
     end
   end
+
+  private 
+  def is_on_terrain(new_location, symbol)
+    new_location[symbol] < @map[symbol] && new_location[symbol] > 0
+  end
 end