From 1cdb42b82c58fd2b2512a41d11db4285561a9b9d Mon Sep 17 00:00:00 2001 From: mo k Date: Sun, 12 Feb 2012 14:41:04 -0700 Subject: split out each heading into a separate file. --- lib/east.rb | 11 +++++++++++ lib/north.rb | 11 +++++++++++ lib/rover.rb | 44 -------------------------------------------- lib/south.rb | 11 +++++++++++ lib/west.rb | 11 +++++++++++ spec/rover_specs.rb | 4 ++++ 6 files changed, 48 insertions(+), 44 deletions(-) create mode 100644 lib/east.rb create mode 100644 lib/north.rb create mode 100644 lib/south.rb create mode 100644 lib/west.rb diff --git a/lib/east.rb b/lib/east.rb new file mode 100644 index 0000000..1699ffc --- /dev/null +++ b/lib/east.rb @@ -0,0 +1,11 @@ +class East + def turn_right + South.new + end + def turn_left + North.new + end + def forward(current_location, terrain) + current_location[:x] = current_location[:x]+1 + end +end diff --git a/lib/north.rb b/lib/north.rb new file mode 100644 index 0000000..438d52d --- /dev/null +++ b/lib/north.rb @@ -0,0 +1,11 @@ +class North + def turn_right + East.new + end + def turn_left + West.new + end + def forward(current_location, terrain) + current_location[:y] = current_location[:y]+1 + end +end diff --git a/lib/rover.rb b/lib/rover.rb index 3e85ecf..42fdfda 100644 --- a/lib/rover.rb +++ b/lib/rover.rb @@ -18,47 +18,3 @@ class Rover end end -class North - def turn_right - East.new - end - def turn_left - West.new - end - def forward(current_location, terrain) - current_location[:y] = current_location[:y]+1 - end -end -class East - def turn_right - South.new - end - def turn_left - North.new - end - def forward(current_location, terrain) - current_location[:x] = current_location[:x]+1 - end -end -class West - def turn_right - North.new - end - def turn_left - South.new - end - def forward(current_location, terrain) - current_location[:x] = current_location[:x]-1 - end -end -class South - def turn_right - West.new - end - def turn_left - East.new - end - def forward(current_location, terrain) - current_location[:y] = current_location[:y]-1 - end -end diff --git a/lib/south.rb b/lib/south.rb new file mode 100644 index 0000000..04851c0 --- /dev/null +++ b/lib/south.rb @@ -0,0 +1,11 @@ +class South + def turn_right + West.new + end + def turn_left + East.new + end + def forward(current_location, terrain) + current_location[:y] = current_location[:y]-1 + end +end diff --git a/lib/west.rb b/lib/west.rb new file mode 100644 index 0000000..b77dd3f --- /dev/null +++ b/lib/west.rb @@ -0,0 +1,11 @@ +class West + def turn_right + North.new + end + def turn_left + South.new + end + def forward(current_location, terrain) + current_location[:x] = current_location[:x]-1 + end +end diff --git a/spec/rover_specs.rb b/spec/rover_specs.rb index 9dc73d0..5e99495 100644 --- a/spec/rover_specs.rb +++ b/spec/rover_specs.rb @@ -1,4 +1,8 @@ require 'rover' +require 'north' +require 'east' +require 'west' +require 'south' describe Rover do def create_sut(heading, x = 0, y = 0) -- cgit v1.2.3