mirror of
https://github.com/gwenhael-le-moine/c-urs_-toil-s.git
synced 2024-12-27 09:58:44 +01:00
introduce move_1_step and pass
This commit is contained in:
parent
a9eba6657c
commit
9642939f99
1 changed files with 9 additions and 0 deletions
9
star.rb
9
star.rb
|
@ -289,7 +289,16 @@ 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
|
||||
end
|
||||
|
||||
def move( direction, objectToMove )
|
||||
|
|
Loading…
Reference in a new issue