Let's look at the steps we took to create our memory game.
1. Generate a number
2. Show number
3. Hide number
4. Prompt for user's guess
5. Check to see if user is correct
Now all we need to do it follow the same steps we took for our game logic and apply it to our programming logic. We will take each game step and add the appropriate pseudo-code to go along with it. These code examples are not language specific. So do not worry if you are using Perl, ruby, C++ etc.
1. Generate a number - Our first task was to generate a random number that we would need to try to memorize. This would be done by using your programming languages random functions and assigning it to a variable.
>NUMBER = (random number between 1 and 100000)
2. Show number - Now that we have a generated number we need to let the player see it. We do this by simply printing the variable out to STD-OUT which by default is the screen.
> print ("NUMBER")
3. Hide number - In our third task we are going to combine three steps, because they flow logically together. Now that we have our number on the screen we are going to wait 5 seconds by using your languages pause or wait command. After this 5 second pause, the program with then clear the screen so the number is no longer showing. After another 5 seconds the player will be prompted to see if he or she remembers the number that was just shown. This time can be adjusted if a higher or lower difficultly is desired.
> wait (5 seconds)
> system "clear screen"
> wait (5 seconds)
4. Prompt for user's guess - We now get the players guess by pulling their answer from standard in. Don't forget to chop or chomp the newline off if you start getting unexpected behaviors. IE you know you got the number right even though it tells you it was the wrong answer.
> get answer from STD-IN
5. Check to see if user is correct - Our last step is to take the players answer and compare it to the actual number. In our example below we respond back to the screen whether we were right or wrong.
> if ANSWER == NUMBER { print ("you got it!")}
> else { print ("better luck next time")}
This example may seem really simple, and it is. Even though it is short and sweet, all it would take to run is to plug in the syntax of your particular programming language. As mentioned before I have made available a version of this simple game in a working Perl script. If I find people find this helpful or interesting I will write a part three that will develop this game even further, by adding a saved score feature and perhaps a scaling difficulty.
Published by Douglas Hutsell
Young, opinionated and technical with way too much time on his hands. View profile
A Different Approach to Home Schooling/TeachingHome schooling or teaching can be a challenge. This article involves teaching multi-aged children. I encourage you to try this alternative and progressive teaching approach. - Bilingual Education and the InternetInformation About Bilingual Education, and the Internet
- Bilingual Education and the InternetThis article provides information about bilingual education and the Internet.
- A Penny Wise Lesson for Young Learners: A Teachable Moment in the Common Pennyif you want your child to succeed, or thrive, in school, and on into life, you, the parent, must play a vital early role in the child's life. you must play the role of exciter.
How to Make a Preschool Shape Memory GameLooking for a great way to teach your preschooler their shapes? Try this fun and simple homemade memory game.
- BlurtIt.com's "Questions and Answers" Page Offers Free Answers to User Questions o...
- An Introduction to Programming in Perl
- Annotated Bibliography: The Impact of Nonverbal Communication on Bilingual Education
- The Use of Music and Song in ESL Instruction
- THE POSITIVE ROLE of VIDEO GAMES in the CLASSROOM
- Learning to Dance in Arizona
- Fun Foam Memory Game You Make for Kids

