Baroody's Game Development Site

A Website to help you program computer games

Step 4: Ending the Game

OK, we're almost there!  All we have to do is to figure out when the game is over.  This happens when all the tiles are in position from 1 to 8 when moving left to right and from row 1 to row 3.  The empty space will be in Position 9, right?

Here's what we need to do...at the end of the DisplayArray_Click sub routine, place the code indicated below (it's highlighted):

blnIsGame Function

This code is pretty straight forward.  It checks to see if a Boolean function evaluates to "True."  If it does, then a message box is displayed indicating that the game has been won.

Now, let's look at the Boolean function.  We start by assuming that the game has been won (blnIsGame = True).  Now, we run through the command button array (cmdDisplayArray) captions to see if they are equal to the string representation of the numbers 1 - 8.  If they are, then we do nothing and we exit the function (with the value "True" - in other words, the game has been won).  If we get to any piece that is not in order, then we set the return value of the function to "False" and exit (indicating that the game has not been won).

That's it for the basic version of this game...well done!


If you're interested in some options for this game, click here or select Step 5: Options on the navigation bar.