- 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ù)之巔:數(shù)據(jù)的本質(zhì)與未來
- 圖解機(jī)器學(xué)習(xí)算法
- Learn Unity ML-Agents:Fundamentals of Unity Machine Learning
- Oracle 12c云數(shù)據(jù)庫(kù)備份與恢復(fù)技術(shù)
- 數(shù)據(jù)庫(kù)技術(shù)實(shí)用教程
- IPython Interactive Computing and Visualization Cookbook(Second Edition)
- Construct 2 Game Development by Example
- Power BI智能數(shù)據(jù)分析與可視化從入門到精通
- 爬蟲實(shí)戰(zhàn):從數(shù)據(jù)到產(chǎn)品
- 深入理解InfluxDB:時(shí)序數(shù)據(jù)庫(kù)詳解與實(shí)踐
- Unreal Engine Virtual Reality Quick Start Guide
- MySQL DBA修煉之道
- Access 2010數(shù)據(jù)庫(kù)程序設(shè)計(jì)實(shí)踐教程
- 數(shù)據(jù)庫(kù)原理與設(shè)計(jì)實(shí)驗(yàn)教程(MySQL版)
- Mastering Java for Data Science