The final thing we need to do is to bring the two distinct games into one program (in an indefinite loop) so that the user can choose which game to play (and play it) and also being given the option of exiting the program.
As we have taken a very modular approach to the coding of each aspect of what will be the final program, this is an ideal opportunity to put the separate parts as functions in the final program and then call the functions as needed.
We will also need a menu system to give users the three choices of:
- Play the numbers game
- Play the letters game
- Exit the program
We will also need the whole program to loop so that the program user can play again (make a choice of playing the same game again or the other game or to exit the program!)
The first task I wanted to complete was the menu system and I decided that I would have 4 functions that would be called within the menu (to make the whole program modular and so that some parts could be omitted when testing!).
I decided that I would need the following functions (for the two parts of the program)
numbersgame() - To run the number selection and the selection of a target
numberscountdown() - to do the 30 second countdown and also print the target with the numbers that should be used
lettersgame() - to do the Consonant and Vowel Selection
letterscountdown() - to do the 30 second countdown and also print the letters to be used
I would also need a menu() function which called the main four functions in order and my cls() function which clears the screen and makes text outputted clear to see.
The entire menu() function would be also called by a main() function.
The menu function I coded like this (with the choice of just using letters as well as the full words to make choices (and speed things up)
Firstly I needed to set up some global variables for the numbers game as some variables from the numbersgame() function would be required in the numberscountdown() function.
These variables are necessary as they are used to strip characters from the List that was used to store the numbers that have been selected and I did not want to repeat the same code in the next function (it was easier just to make those variables available everywhere!)
For other coding and teaching ideas click here.