- XNA 4.0 Game Development by Example Beginner's Guide(Visual Basic Edition)
- Kurt Jaegers
- 198字
- 2021-08-20 15:50:39
Time for action – filling in the gaps
- Add the
FillFromAbove()
method to theGameBoard
class.Public Sub FillFromAbove(x As Integer, y As Integer) Dim rowLookup As Integer = y - 1 Do While (rowLookup >= 0) If GetSquare(x, rowLookup) <> "Empty" Then SetSquare(x, y, GetSquare(x, rowLookup)) SetSquare(x, rowLookup, "Empty") rowLookup = -1 End If rowLookup -= 1 Loop End Sub
What just happened?
Given a square to fill, FillFromAbove()
looks at the piece directly above to see if it is marked as Empty
. If it is, the method will subtract one from rowLookup
and start over until it reaches the top of the board. If no non-empty pieces are found when the top of the board is reached, the method does nothing and exits.
When a non-empty piece is found, it is copied to the destination square, and the copied piece is changed to an empty piece. The rowLookup
variable is set to -1
to ensure that the loop does not continue to run.
Generating new pieces
We can create a single method that will fill any empty spaces on the game board, use it when the game begins, and when pieces are removed from the board after scoring.
推薦閱讀
- 大數(shù)據(jù):規(guī)劃、實施、運維
- 數(shù)據(jù)庫應(yīng)用基礎(chǔ)教程(Visual FoxPro 9.0)
- Ceph源碼分析
- 網(wǎng)站數(shù)據(jù)庫技術(shù)
- 深入淺出Greenplum分布式數(shù)據(jù)庫:原理、架構(gòu)和代碼分析
- Apache Kylin權(quán)威指南
- 辦公應(yīng)用與計算思維案例教程
- 區(qū)塊鏈技術(shù)應(yīng)用與實踐案例
- SQL Server 2012實施與管理實戰(zhàn)指南
- 菜鳥學(xué)SPSS數(shù)據(jù)分析
- Hands-On System Programming with C++
- 商業(yè)智能工具應(yīng)用與數(shù)據(jù)可視化
- 數(shù)據(jù)指標體系:構(gòu)建方法與應(yīng)用實踐
- 企業(yè)級大數(shù)據(jù)項目實戰(zhàn):用戶搜索行為分析系統(tǒng)從0到1
- Visual Studio 2012 and .NET 4.5 Expert Development Cookbook