Commit 63a1beb

mo k <mo@mokhan.ca>
2012-11-05 04:58:15
move increment and decrement calc to Location.
1 parent 71ef614
Changed files (2)
lib/location.rb
@@ -24,6 +24,24 @@ class Location
     @location[axis] = coordinate
   end
 
+  def increment(axis, map)
+    next_position = current(axis) + 1
+    if(next_position > map[axis])
+      move_to(axis, 0)
+    else
+      move_to(axis, next_position)
+    end
+  end
+
+  def decrement(axis, map)
+    next_position = current(axis) - 1
+    if (next_position < 0)
+      move_to(axis, map[axis])
+    else
+      move_to(axis, next_position)
+    end
+  end
+
   def to_s
     "#{@location[:x]} #{@location[:y]} #{@heading}"
   end
lib/plateau.rb
@@ -19,21 +19,11 @@ class Plateau
   end
 
   def increment(axis, location)
-    next_position = location.current(axis) + 1
-    if(next_position > @map[axis])
-      location.move_to(axis, 0)
-    else
-      location.move_to(axis, next_position)
-    end
+    location.increment(axis, @map)
   end
 
   def decrement(axis, location)
-    next_position = location.current(axis) - 1
-    if (next_position < 0)
-      location.move_to(axis, @map[axis])
-    else
-      location.move_to(axis, next_position)
-    end
+    location.decrement(axis, @map)
   end
 
   private