Showing posts with label typingChallenge. Show all posts
Showing posts with label typingChallenge. Show all posts

Thursday, November 5, 2015

An addendum to My First "Game"

I received a comment on my last post from Edhika stating that there was no way to restart the game. What kind of game makes you close and reopen in order to restart and go back to the beginning? Not a very user friendly game. Now, I could have said, that is what the instructions told me to do.

I decided to take the challenge and try to make it so the game "reset" after the game was over. Actually, I took it a step further and made it so you can restart the game at any time. I am not sure why you would want to start over in the middle, maybe it is getting to fast, or you didn't like how you were doing on that "level." At any rate, you can now start over at any point in the game.

It wasn't as difficult as I thought it was going to be. I ended up adding a message box to give you some stats and how to restart the game. I added an if statement that checks if the key pressed is Enter. Once that key is pressed I put a new function called startOver in my Stats class. The function resets the data, difficulty, and restarts the timer at 0.

Pretty simple, right? It didn't take me very long to figure out what I needed to do, but it got me thinking about another aspect of coding which I have not been involved in much. That is the design sessions to determine what needs to go into a program.

The book gave you directions on how to get a very simple game. I can understand that adding the function to restart the game would have been a couple more pages of code and writing and maybe it didn't fit in at this point in the book. At the same time, I didn't do anything new in order to reset the game. Everything I used and put in addition had been written about in the prior changes. The book really likes to use message boxes so creating one is ingrained in my head.

If this were a software company designing the typing game it never would have been shipped. There would have been meetings with all the smart people that are involved in the creation of the end product. Maybe one person didn't think about adding a "reset button" but another would have thought about it.

I have only been involved in one design meeting at work. I have said that I fix bugs at work, which I do the most of, but this was one of my first new features I added. It was a fun meeting and we came out with a great new feature, a button that reruns SSIS jobs. Well, my enhancement lasted about four weeks before another and more experienced coder ripped out the rerun guts and made it better. I know there was another design discussion because the changes were very significant.

Short story, a nice comment on my last post made me realize how important design discussions are and how they are needed. I know my "game" still isn't perfect, but that is why all software has new versions come out. Here is version 2 of the typing game. There are still the same limitations that I shared in the last post.

I also made the game too easy if K.C. can get 100% on 80 keystrokes! Maybe the next version will be more challenging for you.

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!