Game Development Reference
In-Depth Information
Figure 4.2
A field of blank tiles.
Open the File menu and choose Save All. Then start the project in the debugger
and click the Expert button. After a bit of thinking, the form will paint all the
Button controls. If you click Expert again, the form will remove them and paint
new ones. Remember that you have to stop debugging before you can edit the
code. Your application should resemble Figure 4.2.
Note that locations are in terms of top and left, and the values grow as you
progress down the form and to the right. Programmers not used to the way
Windows does things will need to remember that the Y axis is inverted.
Turning Plain Squares into Mines
At present, these are just clickable buttons, not a minefield. One of the benefits of
object-oriented programming is that objects can conceal their inner data. We will
design the Square class so that the only way to find out if a tile is truly a mine is to
click it. This will ensure that our AI does not cheat. We will, of course, need a way
to tell the tile if it is a mine or a safe square. We also need a way for safe squares to
know howmany mines are adjacent to them. Our code will not let the safe squares
ask their neighbors if they aremines or not, however, so themine squares will need
to tell their neighbors to increment their count of nearby mines anonymously.
Search Nedrilad ::

Custom Search