1

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?

4

1 回答 1

5

您已经接近自己达到MVC 模式了。

所以你要做的就是将此 Game.cs 称为你的“模型”,它将包含与游戏状态相关的所有信息。那么你的表单的工作就是在游戏状态被修改时显示游戏的当前状态。(也许是事件驱动的表单更新?)它还将连接玩家通过 UI 执行的任何操作到控制器。控制器的工作将是提供采取行动的方法,并根据这些行动操纵游戏状态。例如 MoveRight() 将更新 Game.Position.X。

然后,您可以获取整个游戏状态并保存/加载,这是您的意图。因此,我认为您尝试做的事情没有问题。

于 2013-05-14T21:13:08.943 回答