Next: Game Over
Up: The buttons function
Previous: Starting the game
Playing is easy. The Mines datatype needs not to be explained
right now, suffice it to say that it models the state of the playing
field (including the mines, but also keeping track of which fields
have been explored or flagged). To play with a set m of mines
means to execute these steps over and over again:
- If the left mousebutton is released, call open with the
button array, the mines and the position of the field we want to
open (note clever -reduced notation). If open returns
Nothing, we lose; otherwise, we play on with the new
playing field.
- If the right mousebutton is released, call flag with
the button array, the mines and the position. No evil may occur,
just play on.
- If a mouse button is pressed (remember, even the middle button
counts), the smiley should look worried. Normally any of the two
release events above will occur within a short while so the smiley
changes back, but if we press the middle button, the smiley stays
worried. We consider this a feature, and in the best academic
tradition leave it to the reader to come up with a solution.
- On the other, if a start event occurs, restart the game; this
can happen e.g. if the users clicks the smiley in the middle of the
game.
playOn takes care of the smiley when we (de)flagged or
explored a field. It also checks wether we have won with the previous
move; this is the case if there are no untouched fields left (i.e. all
fields are either cleared or flagged). This works because we are only
allowed to drop as many flags as there are mines on the field.
Christoph Lueth
Wed May 29 13:20:38 MEST 2002