XNA Game – Rotation – Finishing up rotation… – Part 18

This will be the final part of my series on making an XNA game from scratch. I hope you have enjoyed the series and learnt a thing or two along the way.

The last part that I needed to do was adding a count of how many rotations the player has made. Then each time the user rotates (either left or right) to decrement the count. If the user makes a block then the user gets an extra rotation for every square in the block. This gives the player a goal for the game.

Again I sound like a broken record here but hopefully this is hammering the point home for any doubters, by using the single responsibility principle and writing decoupled code this was very easy to implement. All I needed to do was have a new class called the RotationManger whose job it is to keep track of rotations that the player has made. The RotationManager has two methods on it rotation made and block found. One will decrement the rotations as a rotation has been made. The other will simply loop around all of the squares in all of the blocks made and count them and add them onto the total amount of rotations that the player has left.

This is again a very simple class to write. After that is done all that was left was to call it in the correct places which is for when a rotation is made there are two events that are fired rotated right and rotation left events. Then when the player finds a block the blocks found event fires. This for me really does emphasize how if you structure your code correctly then adding to it is very easy. They are like lots of little building blocks that you can stick together to make a sky scraper.

As always you can grab all of the source code from github. This is part18 or at the time of writing the master branch also. If you are unsure how to get the code then check out this page.

There are many ways you could take the game from here like add menus, high scores, sounds etc. I hope I’ve given you a taster of what is possible…

I’d like to thank you for reading my series on rotation the game. As always comments welcome.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s