mirror of
https://github.com/gwenhael-le-moine/c-urs_-toil-s.git
synced 2024-12-27 09:58:44 +01:00
use objectToMove in move method
This commit is contained in:
parent
6e40724dd7
commit
dbb937f808
1 changed files with 10 additions and 10 deletions
20
star.rb
20
star.rb
|
@ -293,32 +293,32 @@ class Star
|
||||||
d[ :v ] = 1 if direction == :down
|
d[ :v ] = 1 if direction == :down
|
||||||
|
|
||||||
tmp = { :x => 0, :y => 0 }
|
tmp = { :x => 0, :y => 0 }
|
||||||
tmp[ :x ] = @positions[ @whats_moving ][ :x ]
|
tmp[ :x ] = @positions[ objectToMove ][ :x ]
|
||||||
tmp[ :y ] = @positions[ @whats_moving ][ :y ]
|
tmp[ :y ] = @positions[ objectToMove ][ :y ]
|
||||||
|
|
||||||
while ( 0 <= tmp[ :y ] + d[ :v ] && tmp[ :y ] + d[ :v ] < @level[ :height ] ) &&
|
while ( 0 <= tmp[ :y ] + d[ :v ] && tmp[ :y ] + d[ :v ] < @level[ :height ] ) &&
|
||||||
( 0 <= tmp[ :x ] + d[ :h ] && tmp[ :x ] + d[ :h ] < @level[ :width ] ) &&
|
( 0 <= tmp[ :x ] + d[ :h ] && tmp[ :x ] + d[ :h ] < @level[ :width ] ) &&
|
||||||
( @board[ tmp[ :y ] + d[ :v ] ][ tmp[ :x ] + d[ :h ] ] == 'V' ) ||
|
( @board[ tmp[ :y ] + d[ :v ] ][ tmp[ :x ] + d[ :h ] ] == 'V' ) ||
|
||||||
( @whats_moving == :ball &&
|
( objectToMove == :ball &&
|
||||||
@board[ tmp[ :y ] + d[ :v ] ][ tmp[ :x ] + d[ :h ] ] == 'G' )
|
@board[ tmp[ :y ] + d[ :v ] ][ tmp[ :x ] + d[ :h ] ] == 'G' )
|
||||||
tmp[ :x ] = tmp[ :x ] + d[ :h ]
|
tmp[ :x ] = tmp[ :x ] + d[ :h ]
|
||||||
tmp[ :y ] = tmp[ :y ] + d[ :v ]
|
tmp[ :y ] = tmp[ :y ] + d[ :v ]
|
||||||
|
|
||||||
if @whats_moving == :ball && @board[ tmp[ :y ] ][ tmp[ :x ] ] == 'G'
|
if objectToMove == :ball && @board[ tmp[ :y ] ][ tmp[ :x ] ] == 'G'
|
||||||
then
|
then
|
||||||
@board[ tmp[ :y ] ][ tmp[ :x ] ] = 'V'
|
@board[ tmp[ :y ] ][ tmp[ :x ] ] = 'V'
|
||||||
@counters[ :gifts ] = @counters[ :gifts ] - 1
|
@counters[ :gifts ] = @counters[ :gifts ] - 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if tmp[ :x ] != @positions[ @whats_moving][ :x ] ||
|
if tmp[ :x ] != @positions[ objectToMove][ :x ] ||
|
||||||
tmp[ :y ] != @positions[ @whats_moving][ :y ]
|
tmp[ :y ] != @positions[ objectToMove][ :y ]
|
||||||
then
|
then
|
||||||
@board[ @positions[ @whats_moving][ :y ] ][ @positions[ @whats_moving][ :x ] ] = 'V'
|
@board[ @positions[ objectToMove][ :y ] ][ @positions[ objectToMove][ :x ] ] = 'V'
|
||||||
@positions[ @whats_moving][ :x ] = tmp[ :x ]
|
@positions[ objectToMove][ :x ] = tmp[ :x ]
|
||||||
@positions[ @whats_moving][ :y ] = tmp[ :y ]
|
@positions[ objectToMove][ :y ] = tmp[ :y ]
|
||||||
|
|
||||||
@board[ @positions[ @whats_moving][ :y ] ][ @positions[ @whats_moving][ :x ] ] = @whats_moving == :ball ? 'B' : 'C'
|
@board[ @positions[ objectToMove][ :y ] ][ @positions[ objectToMove][ :x ] ] = objectToMove == :ball ? 'B' : 'C'
|
||||||
@counters[ :moves ] = @counters[ :moves ] + 1
|
@counters[ :moves ] = @counters[ :moves ] + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue