mirror of
https://github.com/gwenhael-le-moine/c-urs_-toil-s.git
synced 2024-12-27 09:58:44 +01:00
Make pass the move_1_step
This commit is contained in:
parent
9642939f99
commit
51d8e91a62
1 changed files with 7 additions and 10 deletions
17
star.rb
17
star.rb
|
@ -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 )
|
||||||
|
|
Loading…
Reference in a new issue