- XNA 4.0 Game Development by Example Beginner's Guide(Visual Basic Edition)
- Kurt Jaegers
- 288字
- 2021-08-20 15:50:40
Time for action – generating new pieces
- Add the
GenerateNewPieces()
method to theGameBoard
class:Public Sub GenerateNewPieces(dropSquare As Boolean) Dim x, y As Integer If dropSquare Then For x = 0 To GameBoardWidth For y = GameBoardHeight To 0 Step -1 If GetSquare(x, y) = "Empty" Then FillFromAbove(x, y) End If Next Next End If For y = 0 To GameBoardHeight For x = 0 To GameBoardWidth If GetSquare(x, y) = "Empty" Then RandomPiece(x, y) End If Next Next End Sub
What just happened?
When GenerateNewPieces()
is called with true
passed as dropSquares
, the looping logic processes one column at a time from the bottom up. By using the step 1 in the for
loop for the Y
coordinate, we can make the loop run backwards instead of the default forward direction. When it finds an empty square, it calls FillFromAbove()
to pull a filled square from above into that location.
The reason the processing order is important here is that by filling a lower square from a higher position, that higher position will become empty. It, in turn, will need to be filled from above.
After the holes are filled (or if dropSquares
is set to false
), GenerateNewPieces()
examines each square in boardSquares
and asks it to generate random pieces for each square that contains an empty piece.
Water-filled pipes
Whether or not a pipe is filled with water, it is managed separately from its orientation. Rotating a single pipe could change the water-filled status of any number of other pipes, without changing their rotation.
Instead of filling and emptying individual pipes, it is easier to empty all of the pipes and then re-fill the pipes that need to be marked as having water in them.
- 計算機組成原理與接口技術:基于MIPS架構實驗教程(第2版)
- 同步:秩序如何從混沌中涌現
- 有趣的二進制:軟件安全與逆向分析
- Oracle RAC 11g實戰指南
- 卷積神經網絡的Python實現
- 深入淺出數字孿生
- Python金融數據分析(原書第2版)
- 從0到1:JavaScript 快速上手
- MATLAB Graphics and Data Visualization Cookbook
- 高維數據分析預處理技術
- Google Cloud Platform for Developers
- 新手學會計(2013-2014實戰升級版)
- 大數據技術原理與應用:概念、存儲、處理、分析與應用
- 中文版Access 2007實例與操作
- Mastering ROS for Robotics Programming(Second Edition)