Geeks With Blogs

News QTP and Stuff
Theo Moore Questions... Morphology? Longevity? Incept dates?

I was just introduced to a novel approach for game development: using a Stack. Those of you who have known this for ages are going to probably chuckle at my expense, and it's well-warranted. I confess that although I'd heard of them before, I had never made the connection between a stack and an undo cache before. However, it's simply perfect for it. You can store the moves the player makes in the stack using Push. When you want to back up/undo, simply use Pop to get the last move out. I was pretty darn happy to hear of this. I've used all kinds of approaches in the past including arrays and collections, but these methods weren't really a good solution. Collections had too much overhead and arrays had real performance issues (Redim sucks for speed), but they were all that occurred to me. Until now. The items in a stack are Pushed and Popped as objects, and you can mix types.

Something else interesting in regards to the Stack type: As of VS2005, you can use the Of statement to limit the types on your stack:

Dim Undo as Stack(Of String)

This is great for ensuring the proper data makes it into the stack, if your app cares about it. The Stack is also supported by the NETCF, so I am doubly excited.

Posted on Wednesday, September 27, 2006 1:53 PM | Back to top


Comments on this post: Game Dev: Undo moves

Comments are closed.
Comments have been closed on this topic.
Copyright © Theo Moore | Powered by: GeeksWithBlogs.net