Rock Collection – More Generics & Collections



Here is another counting game that makes the use of generics along with some class inheritance built in. Like I said before I’m starting to like working with collections more and more because of the simplicity of dealing with them. It makes for some cleaner code. I also wanted to work in the class inheritance. Granted, yes, this is on a simple scale. However, I think it demonstrates the power of what inheritance can do. My idea for this program was a visualization of adding items to fish tank. Don’t laugh at the graphics aspect of this program. It was all in my head and I wanted to base the interface off my last post. Also note that I’m only going to include code for one of the rock objects. The other are pretty much the same so if you want to see them download the source and take a look.


Continue reading


Counting Money Game – Generics & Collections



This is a coin counting game that demonstrates the use of generic collections. Instead using arrays or arraylists collections are a better fit in most cases. Plus I’m finding out that in my collections classes my add, remove, sort, etc.., algorithms don’t have to be as complicated. It’s making for some cleaner code. This combined with the knowledge of events, event handlers, delegates, and lambda expressions things are moving right along. When the game is started a random amount is selected. The players job is to use the amount buttons provided to match that amount. There are mouse button event handlers in place to remove the money from the screen by clicking on them. I’m trying to create more classes that do the work behind the scenes away from my MainForm code.

Continue reading

Handling Exceptions With Try/Catch/Finally



It is inevitable at some point in coding that you will come across the need to handle errors and exceptions. You can take care of most predictable scenarios but checking variables and such. However users will always find ways to work with your programs in ways you never intended or saw coming. And in doing this they will introduce errors that you will need to handle. That’s where try/catch/finally comes into play. I made a simple text file reader to demonstrate the ability to throw custom errors based off the ReadAllText() method. This gives a small glimpse into catching and handling exceptions.

Continue reading

Target Game – Lambda Expressions



I have to admit that since figuring out how Lambda expressions work I’ve been using them quite a bit. This and becoming a fan of ArrayList and generic collections over arrays. But for this program I wanted concentrate on the usage of lambda expressions being used with event arguments. The goal of the game is to click on each target before the timer runs out. If you get 4 batches of hits total you progress to the next level. In later versions I’ll implement the ability to select the player level manually.

Continue reading

Balloon Game – Delegates & Events



Delegates and events. This was a hard concept for me to grasp when I first starting studying this. Actually let me be more specific. The Delegates part wasn’t that bad. Understanding how Events work, how they’re constructed, triggered, etc… Specifically custom events as you will see from the source. For example double-clicking on the Form_Load event to have Visual Studio create the event for you automatically is easy. But, for example, constructing menu clicks to custom event handlers to custom methods that fire off in a different class was a hard concept to grasp. However once I FINALLY understood all of this everything started falling into place. And I do use what I’ve learned a log inĀ  my other programs. If done right it just makes for cleaner, more understanding code.

Also if you notice I start using the ArrayList collection and you will see other collection methods moving forward as I’m learning about them. Don’t get me wrong Arrays are fun and have their place. But other collection methods can be used also.

Continue reading