Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
refactoring - no functional changes
  • Loading branch information
mberends committed Oct 3, 2011
1 parent 5239f11 commit 241a2d8
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions examples/gtk-tetris.pl
Expand Up @@ -91,8 +91,7 @@ ()
{
my $piece = (rand * 7).Int % 7; # TODO: ^7.pick;
$colorindex = $piece + 1;
# TODO: @piece = @tetrominoes[$piece] instead of the following loop:
@piece = (); for ^8 -> $i { @piece[$i] = @tetrominoes[$piece][$i]; }
@piece = @( @tetrominoes[$piece] );
$pieceX = 4;
$pieceY = 0;
}
Expand Down Expand Up @@ -123,30 +122,16 @@ ()
@matrix[$y+$pieceY][$x+$pieceX] = $colorindex;
}
# Look for full rows and remove them. TODO: keep score.
for ^matrixRows -> $row {
my $full = True;
for ^matrixColumns -> $column {
if @matrix[$row][$column] == 0 { $full = False; }
}
if $full {
loop (my $moveRow = $row; $moveRow > 0; --$moveRow) {
for ^matrixColumns -> $column {
@matrix[$moveRow][$column] = @matrix[$moveRow-1][$column];
}
}
for ^matrixColumns -> $column {
@matrix[0][$column] = 0;
}
}
}
@matrix = grep { !all(@$_) }, @matrix;
unshift @matrix, [ 0 xx matrixColumns ] while @matrix < matrixRows;
CreatePiece();
}
}

sub TryRotatePiece()
{
my @p = @piece;
@piece = @p[1], -@p[0], @p[3], -@p[2], @p[5], -@p[4], @p[7], -@p[6];
@piece .= map({ $^b, -$^a });
if ! CanMovePiece(0, 0) {
@piece = @p;
}
Expand Down

0 comments on commit 241a2d8

Please sign in to comment.