Tetrish.Tetrish is Tetris ish.
|
🎮 How to play
You score more points if you clear more lines in one go. |
💡 Code Insight: Grid-based tetromino shifting
When the player clears a line, all the blocks have to be shifted down one row. Tetrish (and Tetris) is based on a 2D grid and each square has a reference in memory.
When the player clears a line, all the blocks have to be shifted down one row. Tetrish (and Tetris) is based on a 2D grid and each square has a reference in memory.
Here is a quick synopsis of how Tetrish handles when a line is cleared. It needs to:
CheckForLines() checks to see if any lines are completed by iterating through the rows in the grid. We use a helper function HasLine() to simplify the code structure. HasLine() accepts an integer representing the row index of the grid and checks all the squares on that row to see if they are null. If any are null that means there is no block in that square and we don't have a complete row so we move to the next row by return ing false but if there is a complete row the function returns true and we need to delete the row! DeleteLine() also accepts an integer representing the row index of the grid. It iterates along the squares on that row and destroys all the blocks in those squares. Now we need to move the row above down one square. RowDown() again accepts an int for the row just deleted and iterates along each empty row to move the position on the squares down one row. We need to handle the case where there are more than one row removed at once. |
Build something that makes you think.