Commit 1f69f4f
Changed files (5)
spec
unit
lib/console.rb
@@ -1,4 +1,4 @@
-require 'terrain'
+require 'plateau'
require 'rover'
require 'north'
require 'east'
lib/terrain.rb → lib/plateau.rb
@@ -1,4 +1,4 @@
-class Terrain
+class Plateau
def initialize(x,y)
@map = {:x => x, :y => y}
@headings = [North.new, East.new, West.new, South.new]
@@ -25,7 +25,7 @@ class Terrain
end
def deploy_rover_to(heading, x, y)
- Rover.new(heading_for(heading), {:x => x, :y => y})
+ Rover.new(heading_for(heading), {:x => x, :y => y}, self)
end
private
lib/rover.rb
@@ -1,8 +1,9 @@
class Rover
attr_reader :location
- def initialize(heading, coordinates)
+ def initialize(heading, coordinates, plateau = nil)
@heading = heading
@location = coordinates
+ @plateau = plateau
end
def heading
@heading.class.name.downcase.to_sym
@@ -13,8 +14,11 @@ class Rover
def turn_left
@heading = @heading.turn_left
end
- def move_forward(terrain)
- terrain.move_forward(@heading, @location)
+ def forward
+ @plateau.move_forward(@heading, @location)
+ end
+ def move_forward(plateau)
+ plateau.move_forward(@heading, @location)
end
def to_s
"#{@location[:x]} #{@location[:y]} #{@heading}"
spec/unit/terrain_spec.rb → spec/unit/plateau_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
-describe Terrain do
- let(:sut) {Terrain.new(3, 3)}
+describe Plateau do
+ let(:sut) {Plateau.new(3, 3)}
context "when moving forward" do
context "when the next position is to far east" do