- 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.
- 漫話大數(shù)據(jù)
- SQL入門經(jīng)典(第5版)
- 計(jì)算機(jī)信息技術(shù)基礎(chǔ)實(shí)驗(yàn)與習(xí)題
- Access 2007數(shù)據(jù)庫(kù)應(yīng)用上機(jī)指導(dǎo)與練習(xí)
- 數(shù)據(jù)庫(kù)應(yīng)用基礎(chǔ)教程(Visual FoxPro 9.0)
- 網(wǎng)站數(shù)據(jù)庫(kù)技術(shù)
- Apache Kylin權(quán)威指南
- 大數(shù)據(jù)精準(zhǔn)挖掘
- 淘寶、天貓電商數(shù)據(jù)分析與挖掘?qū)崙?zhàn)(第2版)
- 數(shù)據(jù)庫(kù)應(yīng)用系統(tǒng)開發(fā)實(shí)例
- Oracle數(shù)據(jù)庫(kù)管理、開發(fā)與實(shí)踐
- SQL Server 2012實(shí)施與管理實(shí)戰(zhàn)指南
- 數(shù)據(jù)修復(fù)技術(shù)與典型實(shí)例實(shí)戰(zhàn)詳解(第2版)
- Visual FoxPro數(shù)據(jù)庫(kù)技術(shù)基礎(chǔ)
- 云計(jì)算寶典:技術(shù)與實(shí)踐