mirror of
https://github.com/gwenhael-le-moine/c-urs_-toil-s.git
synced 2024-12-27 09:58:44 +01:00
move_1_step doesn't affect the real position of objectToMove
This commit is contained in:
parent
51d8e91a62
commit
a02b3fcefd
1 changed files with 7 additions and 5 deletions
10
star.rb
10
star.rb
|
@ -295,7 +295,8 @@ class Star
|
|||
dy = 0 unless dy
|
||||
new_x = @positions[ objectToMove ][ :x ] + dx
|
||||
new_y = @positions[ objectToMove ][ :y ] + dy
|
||||
@positions[ objectToMove ] = { :x => new_x, :y => new_y }
|
||||
{ :x => new_x, :y => new_y }
|
||||
|
||||
end
|
||||
|
||||
def move( direction, objectToMove )
|
||||
|
@ -315,6 +316,7 @@ class Star
|
|||
( @board[ newpos[ :y ] + d[ :v ] ][ newpos[ :x ] + d[ :h ] ] == 'V' ) ||
|
||||
( objectToMove == :ball &&
|
||||
@board[ newpos[ :y ] + d[ :v ] ][ newpos[ :x ] + d[ :h ] ] == 'G' )
|
||||
|
||||
newpos[ :x ] = newpos[ :x ] + d[ :h ]
|
||||
newpos[ :y ] = newpos[ :y ] + d[ :v ]
|
||||
|
||||
|
@ -415,9 +417,9 @@ class TestBla < Test::Unit::TestCase
|
|||
st = Star.new
|
||||
puts st.to_s
|
||||
|
||||
st.move_1_step( :down, :ball )
|
||||
result = st.move_1_step( :down, :ball )
|
||||
|
||||
assert_equal( 1, st.positions[ :ball ][ :x ] )
|
||||
assert_equal( 2, st.positions[ :ball ][ :y ] )
|
||||
assert_equal( 1, result[ :x ] )
|
||||
assert_equal( 2, result[ :y ] )
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue