tags:

views:

88

answers:

1

I'm implementing a modular AI testing engine using the MVC pattern in python.

So far everything's ok: The AIs, mouse, keyboard are controllers, the model is a physic engine, the view is a pygame instance that renders everything. I have an event handler to handle most communication.

Now, I want to implement a menu system (imagine a game menu where you can choose Load, Save, Quit, etc). But I'm blocked, I can't figure out how should I implement it. The problem is I'm thinking it should be part controller and part view but I'm not sure.

Any ideas? Thank you

+1  A: 

First, a few points too often forgotten when talking about MVC:

  1. No pattern is a dogma. If the best solution is not MVC, that probably means MVC wasn't appropriate for the problem.

  2. MVC, the OOD style for GUI applications is very different from MVC, the layered architecture for web applications. In this case you need the first one, so many docs and articles about the second might not be good advice.

  3. In 'GUI-MVC', the Model-View-Controller triad is for each application module; there's no 'model layer', 'view layer' nor 'controller layer'.

now, for your specific case

You could see the menu system as an extra module, independent from your existing engine. This module can (if you find it convenient) have it's own MVC structure. The model can be the list (or tree) of commands, the views are the visible menus, the controller could be a dispatcher that gets the menu event and executes the commands.

Or, the whole menu can be just a GUI control; one of the many existing controllers. Like any GUI control, it has a visible part. If your base libraries are simple enough, the code to instatiate and mange the menus can be too simple to be worth of a complex internal structure.

Javier
I like the idea of having the menu system as an extra module. I was too influenced by the web application view. But even then I already was noticing the need to have modules with its own model-view-controller structure.The main reason I divided the whole app into MVC was having a View I could replace in the future independently of the model and controller layers. As you said in 1, I shouldn't try to force the app into the pattern.Thank you for your answer.
Ezequiel