Game Development Reference
In-Depth Information
Our Square class inherits from Button . The MyBase keyword is how our class
refers to the class from which it inherits. To make sure that our class acts like a
button, we want the initialization code that buttons use to run when our control
initializes—hence the call to MyBase.New() .
After doing something new, it is a good idea to test it. We will need a few more
controls on the form to do that.
1. Switch to the Design view of PlayingField :
2. Drag a Button control from the Toolbox onto the top left of the white panel.
The panel is a container, and we want the control to go inside it. That way,
we can move it by moving the container if we need to resize the underlying
form. If you drop the Button control onto the form, the form will be its
container.
3. Change the Button control's Text property to Expert and the Name property
to ExpertButton.
4. After you change its properties, double-click the Button control to view the
Click event handler. Add the following line of code:
Call NewGame(16, 30, 99)
Adding Squares to the Playing Field
The NewGame code does not exist yet, so you will see the name flagged in the code
and an error in the error list. If you have played a lot of Minesweeper , you know
that an expert level board has 16 rows and 30 columns and conceals 99 mines. We
want to be able to walk through the tiles and find their neighbors easily, so we will
do more than just put the controls on the form; we will hold them in an array as
well. Add the following code to PlayingField.vb:
Public Field(,) As Square
Dim NumRows As Integer
Dim NumCols As Integer
Dim NumMines As Integer
Private Sub NewGame(ByVal nRows As Integer, ByVal nCols As Integer, _
ByVal nMines As Integer)
Dim Sq As Square
'Put up an hourglass
Me.Cursor = Cursors.WaitCursor
 
Search Nedrilad ::




Custom Search