Our game is close to being complete -- or at least complete
enough that it can be fun to play. All that remains is removing full
rows (since filling rows is the object of Tetris) and keeping score.
Writing removeFullRows:
This function will clear any full rows (rows that do not contain the empty color)
from the board, move the rows above them down, and fill the top with empty rows.
To do this, we'll create a new board and will only copy into it rows from the old board
that are not full (in the correct order, of course). We'll also keep track of
the number of full rows that are removed in a variable, fullRows. Once all the non-full
rows are copied over, we'll add empty-color rows to the top of the new board until
it's the right size. We then call removeFullRows in placeFallingPiece, so that full rows are cleared at the first possible opportunity.
Now that we are removing rows, we should keep score.
To do that, we will introduce a data value "score" (which is set to
zero in the init function). In our removeFullRows function, we will
increment the score by the square of total number of full rows
removed in order to reward removing
multiple lines at once. And now that we are keeping score, we should
also display the score, which involves adding a function drawScore which is
called by our draw function.
David Kosbie |