From 51d8e91a62c2597280f09d268719cf2c3f719016 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Sat, 21 May 2011 16:02:16 +0700 Subject: [PATCH] Make pass the move_1_step --- star.rb | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/star.rb b/star.rb index 6d1f0fb..3efd8b1 100644 --- a/star.rb +++ b/star.rb @@ -289,16 +289,13 @@ class Star end def move_1_step( direction, objectToMove) - d = { :h => 0, :v => 0 } - d[ :h ] = -1 if direction == :left - d[ :h ] = 1 if direction == :right - d[ :v ] = -1 if direction == :up - d[ :v ] = 1 if direction == :down - - new_x = @positions[ objectToMove ][ :x ] + d[ :h ] - new_y = @positions[ objectToMove ][ :y ] + d[ :v ] - @positions[ objectToMove ][ :x ] = new_x - @positions[ objectToMove ][ :y ] = new_y + dx = { :left => -1, :right => 1 }[ direction ] + dy = { :down => 1, :up => -1 }[ direction ] + dx = 0 unless dx + dy = 0 unless dy + new_x = @positions[ objectToMove ][ :x ] + dx + new_y = @positions[ objectToMove ][ :y ] + dy + @positions[ objectToMove ] = { :x => new_x, :y => new_y } end def move( direction, objectToMove )