So now we have the general display worked out, lets work out some of the rules and goals of this game. First the primary goal is to make it from your starting position at star position 1,1 through the stargate at star position 8,12. This implies movement of your ship. This is done by entering the coordinates that you wish to move to. It would be simple just to jump straight to the stargate (coordinates 8,12) except you must first have the energy reserve to make this move. With that introduction out of the way, here are the rules:
In this image we are moving a vertical distance of 2 and a horizontal distance of 3. The actual distance calculated (using simple geometry) is about 3.6 units. We would multiply that times 1.25 to make a total movement of 4.5 units, requiring 450 gigajoules to make the jump.
So there are the rules. Are you ready to develop the game? Well here we go...
This is the largest project yet, representing a huge a significant step in skill and knowledge. In order to get from our basic set of game rules to a working program we will need to develop a better model of our program. For this we will turn to pseudo coding, a technique discussed in the second installment of this series. We will develop the pseudo code structure in several passes, refining it as we go. This works well for big projects, allowing us to continually break down the problems into smaller, more manageable chucks.
Initial program structure:
Well, that is not a giant list, but some of those steps are fairly complex and will need to be broken down more. Of course there are a few things missing. For instance, how does the game end? What happens if there is an explosion? Also, maybe some instructions would be nice! Lets see if we can't work these things into our model.
>> See if the user wants instructions, and show them if so
>> If we move into stargate - show end game
>> if all lives are used, show end game
Now we need to expand a few of these steps a little to make them more explanatory.
3.a. show users current location
3.b. show lives remaining
3.c. show energy level
4.a. verify the users move
4.b. if they are moving goto 6
4.c. if they are not moving goto 5
5.a. choose a random amount of energy
5.b. add the energy to the users total
5.c. if energy exceeds 485 gJ do cap energy at 485 gJ
5.d. goto 8
6.a. verify the user has selected a valid move
6.b. calculate energy requirements for move
6.c. verify user has enough energy to make the move
6.d. if the user can not make the move go back to 3
6.e. move the ship, deduct the energy.
6.f. if this is the stargate - you win - show winner
7.a. if our destination is occupied by a k bomb goto 9
8.a. choose random location x and y
8.b. if there is a k bomb there already choose again
8.c. if this is the stargate or the origin (1,1) choose again
8.d if the ship is at this location goto 9
8.e place the bomb - goto 11
There is more we could do to further explode the pseudo code out and detail the steps more, but if we add too much detail, then we are really writing the program. The purpose of the pseudo code is to give us a good, clear road map explaining where we are going. It does not need to solve all of our problems for us though.