Sign in to follow this  

Basic MVC Architecture Question

Recommended Posts

Hey everyone, I'm new to game programming and fairly new to the community, and I have a couple of questions regarding the MVC paradigm. I've got a couple of games under my belt (Tic-tac-toe and Pong clones) that use SDL, but instead of employing any sort of OOP functionality, I've relied on basic C programming -- functions, structs, etc. Before moving forward with my next projects (Space Invaders, Tetris, and 2D sidescroller clones), I've decided that it would be worthwhile to make the jump to OO Programming (specifically using the MVC Design Pattern). So, while designing my classes and their interfaces, I ran into some problems. My issues specifically pertain to drawing the various game objects. The way it stands now, I have an std::list of GameObjects that serves as the model. When it comes time to render, the Controller loops through the list, and sends information about each object to the View class, which in turn renders that object onto the screen surface. Now here is where I get lost. Currently, I use an enum called ObjectType that is a member of each GameObject. Depending on what the value of that enumerator is, the View will render a specific SDL_Surface to the screen. For instance, let's say we have a GameObject that represents an "invader" from Space Invaders. It has various values, such as its x coordinate, its y coordinate, direction that it's traveling, and its ObjectType. In this case, the ObjectType would be INVADER as defined by the ObjectType enumerator. The View also knows about this enumerator, so it knows what surface to apply. That way, the View is notified of the type of surface that it should draw at the coordinates. I realize that this is probably not the "prettiest" or "proper" way to do things -- the best way would most likely involve some form of inheritance/polymorphism, where every type of game object inherits from the base class called GameObject. But, using polymorhism, I cannot think of a clean way to notify the View of the type of surface to render -- keeping the Model class and View classes separate is one of the fundamental aspects of the MVC paradigm. How would you suggest that I approach this? Am I on the right track? I know that this post could've been more concise, and if any part of it is unclear, let me know and I will try to clarify. Thanks in advance.

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