Make pass the move_1_step

This commit is contained in:
Gwenhael Le Moine 2011-05-21 16:02:16 +07:00
parent 9642939f99
commit 51d8e91a62

17
star.rb
View file

@ -289,16 +289,13 @@ class Star
end end
def move_1_step( direction, objectToMove) def move_1_step( direction, objectToMove)
d = { :h => 0, :v => 0 } dx = { :left => -1, :right => 1 }[ direction ]
d[ :h ] = -1 if direction == :left dy = { :down => 1, :up => -1 }[ direction ]
d[ :h ] = 1 if direction == :right dx = 0 unless dx
d[ :v ] = -1 if direction == :up dy = 0 unless dy
d[ :v ] = 1 if direction == :down new_x = @positions[ objectToMove ][ :x ] + dx
new_y = @positions[ objectToMove ][ :y ] + dy
new_x = @positions[ objectToMove ][ :x ] + d[ :h ] @positions[ objectToMove ] = { :x => new_x, :y => new_y }
new_y = @positions[ objectToMove ][ :y ] + d[ :v ]
@positions[ objectToMove ][ :x ] = new_x
@positions[ objectToMove ][ :y ] = new_y
end end
def move( direction, objectToMove ) def move( direction, objectToMove )