Commit c42f113
Changed files (3)
lib/console.rb
@@ -9,14 +9,13 @@ class Console
def initialize(input, output)
@input = input
@output = output
- @headings = [North.new, East.new, West.new, South.new]
end
def run
edge = ask('enter size of terrain:', ' ')
terrain = Terrain.new({:x => edge[0].to_i, :y => edge[1].to_i})
landing = ask('enter landing coordinate:', ' ')
- rover = Rover.new(heading_for(landing[2]), {:x => landing[0].to_i, :y => landing[1].to_i})
+ rover = terrain.deploy_rover_to(landing[2], {:x => landing[0].to_i, :y => landing[1].to_i})
ask('enter instructions:', //).each do |instruction|
case(instruction)
@@ -37,8 +36,4 @@ class Console
@output.print '> '
@input.gets.split(split)
end
-
- def heading_for(pneumonic)
- @headings.find { |heading| heading.to_s == pneumonic }
- end
end
lib/rover.rb
@@ -3,7 +3,6 @@ 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,6 +1,7 @@
class Terrain
def initialize(edge_of_map)
@map = edge_of_map
+ @headings = [North.new, East.new, West.new, South.new]
end
def move_forward( heading, location)
@@ -11,8 +12,15 @@ class Terrain
end
end
+ def deploy_rover_to(heading, coordinates)
+ Rover.new(heading_for(heading), coordinates)
+ end
+
private
def is_on_terrain(new_location, symbol)
new_location[symbol] < @map[symbol] && new_location[symbol] > 0
end
+ def heading_for(pneumonic)
+ @headings.find { |heading| heading.to_s == pneumonic }
+ end
end