Computer Programming Tips – Write Games To Increase Your Skills

Computer Programming Tips - Write Games To Increase Your Skills

There are many people out there who would love to learn how to program but get stumped after they finish the “hello world’ examples. One of the best ways for beginners to learn their language and have fun while doing it is to write simple games. Writing games is a great way to practice applied logic and design flow. This concept can be useful no matter what programming language you happen to be learning.

When I started learning PERL I decided to make a little text based version of the board game RISK. It was very simplified, as you only competed against one opponent instead of many. There were quite a few challenges that had to be worked out in order for the game to work . I had to determine how the rounds started and ended, how battle was to emulated, and how to randomize the potential events. Once I was able to visualize this, I sat down and developed those concepts into code. The coding part was actually easier because I already knew what I wanted the program to do. Finally once everything was working just has I had hoped I spruced up the out put to make it look much more interesting. Looking back, I think I learned more from writing this game than any other program I have written since.

Just for fun, here are some types of games you might try using for some of your first programs could be:

  1. Rock Paper Scissors
  2. 20 Questions
  3. Memory
  4. Hang Man
  5. Wwheel of Fortune

Or just about anything else you can think of.

Let’s take one of these examples and see how we would break it into logical pieces Let’s choose memory. Now instead of the regular memory card game we are going to make a game that tests your ability to remember numbers. First what are the basic mechanics of the game? Here are most simplistic steps:

  1. Generate a number
  2. Show number
  3. Hide number
  4. Prompt for user’s guess
  5. Check to see if user is correct

We are not going to talk about code at this point, only the steps of our game.

Computer Programming Tips - Write Games To Increase Your Skills

First we will want to generate a number that will be used to guess. Later if we wish to add a bit of functionality we could expand this by allowing the player to set the length of the number. Another idea is to increase the length of our generated number by one each round until the player fails to guess correctly. This all depends on how you would like to play the game.

The second task is getting the number on the screen. A simple print statement can handle this for us. Our third task is simply removing the number from the screen. After all it is not a challenge to remember the number if you can still see it. Next we prompt the user for their guess. Once we have their answer we need to check it against our generated number to see if they are the same. When that round is over we may even want to see if our player wants to try again of call it quits.

This is basic logic and flow 101. The breaking down of the game in to logical steps is the same steps we use in code design. In part two we will take a look at some actual programming to bring our example to life.