Sign in to follow this  
w00

MVC pattern?

Recommended Posts

Hey, i was wondering if what i'm doing is close to a MVC Pattern. I have the following classes: Model: Game.cs; in this main form the game itself is rendered + the extra GUI elements like Inventory.cs, CharacterStats.cs etc. Control: GUIHanlder.cs; This handles the GUI elements. Like if a button is pressed in CharacterStats.cs, then it gets handled in GUIHandler.cs Views: [i/These are the GUI files (User Controls) that can be Shown (Show()) or Hidden (Hide()) on the main form Game.cs[/i] Inventory.cs CharacterStats.cs Skills.cs My Question: ------------ Now what i want to know is, how to implement it properly. Should Game.cs pass an instance of itself to GUIHandler.cs? And should GUIHandler.cs create an instance to all the GUI elements? So i could do the following: (some pseudo code)
Game.cs:
GUIHandler GUI = new GUIHandler();
GUI.ShowCharacterStats();
---------------------------------------------

GUIHanlder.cs
Game game;
//.ctor
GUIHandler(Game game)
{
    this.game = game;
    CharacterStats cStats = new CharacterStats();
    cStats = new Point(200,300);
    game.Controls.Add(cStats);
    //Same goes for all the other View classes!!
    Iventory invent = new CharacterStats();
    invent = new Point(200,300);
    ...etc
    ...etc
}

public void ShowInventory()
{
    invent.Show();
}

pulbic void btCharStats_CraftStats()
{
   //Code to update the View to display the users current Crafting status.
}
Or is better that Game.cs creates an instance to the Views it needs instead of doing that in GUIHandler? So that i just keep GUIHanlder for the button presses that occure on the forms of the Views?

Share this post


Link to post
Share on other sites
Iirc, the MVC pattern is implemented at a lower level, for example, with a single control item like a button or a set of controls like a toolbar with an edit window. "Game" seems to me like a higher level abstraction, a container that holds many other patterns.

Share this post


Link to post
Share on other sites
Quote:
Original post by w00

Model:
Game.cs; in this main form the game itself is rendered + the extra GUI elements like Inventory.cs, CharacterStats.cs etc.


If it has gui elements then it isn't the model. The model should be all game world entities and only game world entities. The model should the run game and provide a way for the view to know the state of the game. If the model depends on a view or a controller you have done MVC incorrectly.

Share this post


Link to post
Share on other sites
Quote:
Original post by stonemetal
Quote:
Original post by w00

Model:
Game.cs; in this main form the game itself is rendered + the extra GUI elements like Inventory.cs, CharacterStats.cs etc.


If it has gui elements then it isn't the model. The model should be all game world entities and only game world entities. The model should the run game and provide a way for the view to know the state of the game. If the model depends on a view or a controller you have done MVC incorrectly.
This. The model is simply the state of the game world, the view is, as the name implies, what lets the player know things about the game world (all rendering and sound goes here) and the controller is what lets the player interact with the game world.

The player will talk to the controller who will update the model accordingly, which is then presented to the player through the view.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this