Commit 3ab58f9

mo k <mo@mokhan.ca>
2012-08-10 04:40:08
use switch to parse instructions.
1 parent 448467e
Changed files (2)
bin/app.rb
@@ -21,13 +21,23 @@ end
 
 puts "enter size of terrain:"
 edge = gets.split(' ')
-terrain = Terrain.new({:x => edge[0], :y => edge[1]})
+terrain = Terrain.new({:x => edge[0].to_i, :y => edge[1].to_i})
 
 puts "enter landing coordinates:"
 landing = gets
-rover = Rover.new(get_heading(landing.split(" ")[2]), {:x => landing.split(" ")[0], :y => landing.split(" ")[1]})
+rover = Rover.new(get_heading(landing.split(" ")[2]), {:x => landing.split(" ")[0].to_i, :y => landing.split(" ")[1].to_i})
 
 puts "enter instructions:"
 gets.split(//).each do |instruction|
   puts instruction
+  case(instruction)
+  when 'M'
+    rover.move_forward(terrain)
+  when 'R'
+    rover.turn_right
+  when 'L'
+    rover.turn_left
+  end
 end
+
+puts "final location: #{rover}"
lib/rover.rb
@@ -3,6 +3,7 @@ class Rover
   def initialize(heading, coordinates)
     @heading = heading
     @location = coordinates
+    puts coordinates
   end
   def heading
     @heading.class.name.downcase.to_sym