Imagine a turn-based tile game, that generally looks like Heroes' combat view. Except for the fact a player can choose any of his units to command.

Our team is implementing the game according to MVC paradigm.

Some logic needs to be defined in order to allow selecting only allied units, for instance. And the selected one should be highlighted by the View.

For now we have made a Controller responsible for this. But to me it feels strange when the View is rendering data that comes from the Controller itself instead of the Model.

Is there any common practice to put such logic in Model or Controller?


I'd warn against MVC for games in the first place, but putting said logic in the controller is fine. You can also put a small bit in the model if you want to be really pure. The Model contains a selection state and the Controller modifies this. Then the View uses this state to do its rendering.

Something like:

  bool selected = false

  on click:
    old_unit.selected = false
    new_unit.selected = true

  on draw model:
    if model.selected:
      render selected mesh/sprite/effect
      render regular mesh/sprite

You can use more intricate state than just a boolaen if you need for better effects, such as timers to smoothly animate selection effects, or states for active player unit, active enemy unit, select for combat, select for movement, whatever.

  • \$\begingroup\$ Sounds reasonable. To do a bit more generalization: you seem to find it vital for MVC to base your view only on data provided by Model, aren't you? \$\endgroup\$
    – 10nikov
    Jul 17 '13 at 18:23
  • \$\begingroup\$ Not how I usually do it when I use MVC (never for games), but that seemed to be what you wanted. \$\endgroup\$ Jul 17 '13 at 18:41
  • \$\begingroup\$ More accurately, I never use MVC for non-UI bits of games. \$\endgroup\$ Jul 17 '13 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.