- XNA 4.0 Game Development by Example Beginner's Guide(Visual Basic Edition)
- Kurt Jaegers
- 276字
- 2021-08-20 15:50:39
Time for action – manipulating the GameBoard
- Add
public
methods to theGameBoard
class to interact withGamePieces
:Public Sub RotatePiece(x As Integer, y As Integer, clockwise As Boolean) boardSquares(x, y).RotatePiece(clockwise) End Sub Public Function GetSourceRect( x As Integer, y As Integer) As Rectangle Return boardSquares(x, y).GetSourceRectangle() End Function Public Function GetSquare(x As Integer, y As Integer) As String Return boardSquares(x, y).PieceType End Function Public Sub SetSquare(x As Integer, y As Integer, pieceType As String) boardSquares(x, y).SetPiece(pieceType) End Sub Public Function HasConnector(x As Integer, y As Integer, direction As String) As Boolean Return boardSquares(x, y).HasConnector(direction) End Function Public Sub RandomPiece(x As Integer, y As Integer) boardSquares(x, y).SetPiece(GamePiece.PieceTypes( rand.Next(0, GamePiece.MaxPlayablePieceIndex + 1))) End Sub
What just happened?
RotatePiece()
, GetSourceRect()
, GetSquare()
, SetSquare()
, and HasConnector()
methods simply locate the appropriate GamePiece
within the boardSquares
array and pass on the function request to the piece.
The RandomPiece()
method uses the rand
object to get a random value from the PieceTypes
array and assigns it to a GamePiece
. It is important to remember that with the Random.Next()
method overload used here, the second parameter is non-inclusive. In order to generate a random number from 0
through 5
, the second parameter needs to be 6
.
Filling in the gaps
Whenever the player completes a scoring chain, the pieces in that chain are removed from the board. Any pieces above them fall down into the vacated spots and new pieces are generated.
推薦閱讀
- 數(shù)據(jù)挖掘原理與實(shí)踐
- 數(shù)據(jù)之巔:數(shù)據(jù)的本質(zhì)與未來
- 輕松學(xué)大數(shù)據(jù)挖掘:算法、場(chǎng)景與數(shù)據(jù)產(chǎn)品
- 大數(shù)據(jù)可視化
- Oracle RAC 11g實(shí)戰(zhàn)指南
- Live Longer with AI
- Lego Mindstorms EV3 Essentials
- MATLAB Graphics and Data Visualization Cookbook
- 深入淺出 Hyperscan:高性能正則表達(dá)式算法原理與設(shè)計(jì)
- SQL Server 2012數(shù)據(jù)庫管理教程
- 編寫有效用例
- 爬蟲實(shí)戰(zhàn):從數(shù)據(jù)到產(chǎn)品
- Mastering ROS for Robotics Programming(Second Edition)
- R Machine Learning Essentials
- ECharts數(shù)據(jù)可視化:入門、實(shí)戰(zhàn)與進(jìn)階