Tuesday, July 24, 2012

Console Game Architecture: Part 1

This is something that I feel is poorly addressed to many students and aspiring game developers.  So, I just thought I would take a little time to write a little about some of the parts that make this work the way it's supposed to.  I am writing it against C# and posting some code snippets to make better sense of it.  But, it's not really a tutorial.

One crucial part to all games is the While loop.  So, in console games many people make this mistake in thinking.  Oh it's text based so I don't need that.  Sorry, you really do.  Granted you can avoid it, but you're only making it harder if you don't use the loop.  That means you need a boolean field which determines if the game is running and a while loop which utilizes that value.  here is the simplest way to approach this.











Nothing hard about that.  Making sure you start here is crucial to saving yourself thousands of headaches later.  Now, another big mistake I see is the lack of use for input handler methods.  I'm going to write a few examples and show you what I mean by this.



This is our global input handler, you use this one to handle input that you want for any and all input manipulation.  Pretty neat concept right?  There are two methods one for a one shot call, and the second which actually handles the input so it can be called by other handlers.







The ones below are for handling the concept of room navigation.  Same concept of the two methods, but notice in the RoomInputHandler method I call GlobalInputhandle.  The nRoomIndex argument is used to update the current room, this handler does all this for you with the room information set up accordingly.  The RoomInfo[] is a simple struct which holds the name and description.  All the rest of this is the same as the global handler.





































The coolest part about all this so far.  That's majority of it.  The rest is pretty much whatever you want it to be.  I'm adding a few other parts to this as a series, but this covers 99% of what most students which consult me are missing.

Hope this helps.

P.S. I used screenshots so you can actually write the code yourself and not just copy it on purpose ;-)

No comments:

Post a Comment