Skip to main content
gamedev.net
🔒 Locked

[.net] GameState Class (Stack), using C#

Started by krovisser Feb 17, 2007 at 11:31 PM 4 replies 2.4k views
Original Post
krovisser
krovisser
I want to be able to use a stack data collection, but to store game states. That is, a menu screen would be a state "superimposed" over the game state. So that the game continues to run, but there's a transparent menu drawn over it. I don't want to use unsafe code... and I'm not all that familiar with a safe (ie - c#) way to do a stack. I'm very familiar with the c++ implementation, however. This would help a bunch! Thanks.
mutex
mutex
If you're using .NET 2.0, there's System.Collections.Generic.Stack. If you're not, try writing your own considering you're familiar with C++ stacks :)

Bob Janova
Bob Janova
In .Net 1 there is a (non-generic) System.Collections.Stack. Check out my Ten Hour Game entry for a rudimentary implementation (I only push one state, but the stack mechanism is there).
krovisser
krovisser
Sweet. Thanks. This forum is really nice and helpful. I think I'll subscribe.

On second thought, if it were a true stack, only the top-most item could be accessed, but nevertheless it would save the game state, which is what I am looking for.
Dave Hunt
Dave Hunt
Quote:
Original post by krovisser
On second thought, if it were a true stack, only the top-most item could be accessed, but nevertheless it would save the game state, which is what I am looking for.


You can still use foreach to traverse through the elements in the stack. It will traverse from top to bottom, though, which is the reverse of what you want for rendering. It might be better to use System.Collections.Generic.List so that you can traverse it in any order you want, such as back to front for update, and front to back for rendering.
Iarus
Iarus
looks at this : http://blogs.msdn.com/etayrien/archive/2006/12/12/game-engine-structure.aspx I found it really interesting.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.