Jason D
Jason D

Reputation: 2664

Need advice on design/structure of a game

I posted this on gamedev.stackexchange but haven't received any answers. Hopefully somebody here will be able to help me with this.

I am working on my first game in c#. It it a text-based game using Windows Forms. I was brainstorming on the best way to manage all of the data and thought about containing all of the information relevant to an instance of the game in one class (Game.cs) and have that class be responsible for keeping track of anything important. (Note: I am NOT talking about having a project with 1 class or anything like that) I figure that this will make saving and loading easier (simply save and load that instance of the class), as well as making starting a new game easier (currently I'm initializing all of the variables in an initialization class).

So, would this method be in good practice (having everything the game needs to keep track of in a single class)? If not, are there any other way that you might suggest handling and placing the data?

Upvotes: 1

Views: 424

Answers (1)

Tombala
Tombala

Reputation: 1690

You're close to arriving at an MVC pattern on your own.

So what you would do is call this Game.cs your "model" and it will contain all the information relevant to the state of a game. Then your form's job would be to display the current state of the game as the game state is modified. (maybe event driven updates to the form?) It will also hookup whatever actions your player would take through the UI to the Controller. The Controller's job will be to provide methods to take actions and to manipulate the game state based on those actions. E.g. MoveRight() will update Game.Position.X.

You can then take the whole game state and save/load, which is your intention. So I don't see a problem with what you're trying to do.

Upvotes: 5

Related Questions