Tuesday, November 3, 2015

My First "Game"

Well, my C# book tells me I have learned enough for them to guide me through making my first game. I have done it, and it appears to be working! It is a typing game that progressively gets harder as you type the correct letters that appear on your screen. It is a really simple game, and uses some of the knowledge I learned in the first 4 chapters of the Headfirst C# book.

All of the steps are provided to you, so all you have to really do is follow directions. It took me about an hour to create the simple game, but I like to think about each step to help me remember what I did and why I did it. I will be honest, the game did not work flawlessly once I first debugged the game.

Perfect! I was given all the directions and the game doesn't work! After six correct key strokes I would get an out of range error. Either I missed a step or the book gave me incorrect directions (I would hope editors would find this before printing). Turns out I missed a step. Well, it wasn't a step, but a side window with a note telling me to set the difficultyProgressBar maximum to 701 while the default was only 100. I have a method in the game that after each key stroke would increase the difficulty. Well, after so many key strokes it tried to increase the difficulty above 100 and *bam* the game explodes on you.

Luckily, I was able to track down the error and fix the game relatively quick. After I fixed my error I went back to make sure the book told me to take this step. Right there on page 162 at the bottom right corner was the little box stating to remember to do this maximum update along with two other steps. I did the two other steps so I am not sure how I missed the maximum update.

I am glad I missed the update. It helped reinforce some practices that we do at work. That is, we should be testing our own code before shipping or checking in. Sure, the game worked but only for a few key strokes. It built just fine and I would have been able to ship the product. However, it would have come back and blown up in my face. "Look, Robert can code a game, but he doesn't know how to debug and fix errors before shipping."

Other pieces I noticed in the game:

  • The letters shown are all capital letters, but if you type a capital letter back it counts it as and error. I did not debug or fix this one. Maybe I will try that tomorrow morning.
  • I have linked to a zip file that has setup.exe included. Anyone can run the game and see what an awesome job of following directions I did. This will install into your computer and the program can be removed by uninstalling TypeGameChapter4


Next up in the book is a "lab" which gives me a goal, but does not give directions like the previous game. Let's see how it goes!

Get zip file for typing game here!

3 comments:

Edhika said...

Did you try to modify the game so it will start a new game?
I'm trying to modify it but I still can't re-initialized the stats and speed.

Robert Jorgensen said...

Edhika, no I did not. Again, I just did the basic copy from the book. I will look into adding a start over button. That will sure test my knowledge!

K.C. said...

Ooh I got 80 at 100% accuracy. That is my best score so far. X did worse, but only cause she's not on a keyboard every day.