Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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:

Model:
  bool selected = false

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

View:
  on draw model:
    if model.selected:
      render selected mesh/sprite/effect
    else:
      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.

share|improve this answer
    
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? –  10nikov Jul 17 '13 at 18:23
    
Not how I usually do it when I use MVC (never for games), but that seemed to be what you wanted. –  Sean Middleditch Jul 17 '13 at 18:41
    
More accurately, I never use MVC for non-UI bits of games. –  Sean Middleditch Jul 17 '13 at 18:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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