I'd like to make a 2D game in Java using the Model-View-Controller (MVC) pattern, but I have some issues concerning the battles.

There are two groups of characters in each battle: heroes and monsters. The player controls the heroes. My game is turn-based: I'd like to select one character at a time, ask the player the action to use, its target, and finally execute the action. However I can't seem to adjust this sequence of commands with the MVC pattern.

Could anyone help me?

  • 4
    \$\begingroup\$ Yep, someone can help you. But you'll have to make it clearer what you're asking. What have you tried? Why is it failing? \$\endgroup\$
    – Anko
    Apr 30 '13 at 15:30
  • \$\begingroup\$ My problem is the turn-based battle implementation. I created a Battle object in my model. This Battle object knows the two groups. It is able to run a turn at a time as well. In my point of view, it should also be able to run the battle in its entirety : each character attacks and it goes on until the death of one of the groups. But between every attack, for the heroes, I need the commands of the player, which will be received by the GUI, and given to the controller. So, I'd like to know if it's correct or which path should i take to resolve this little problem... Thx ! \$\endgroup\$ May 1 '13 at 8:52
  • \$\begingroup\$ Edit : I've implemented what I just said. The battle object is able to manage turns : I invoke a new turn after each attack. Therefore, the entirety of the battle is managed by the view, and it doesn't seem normal to me. That's my problem and what I'd like to do. Sorry for not being clear... And thanks. \$\endgroup\$ May 1 '13 at 9:10

You can solve this by implementing the controller as a state machine with four states:

  • select character
  • select action
  • select target
  • wait for animation to finish

In each of these state different GUI elements are shown/hidden and the inputs of the user are interpreted differently.

Instead of implementing it as a state machine, you could also implement it with four individual controller classes, one for each state.


Not the answer you're looking for? Browse other questions tagged .