As a university software engineering project, my group has to make a videogame out of the board game Galaxy Truckers (rules summary, if it helps), using the MVC pattern (we're using Java as a language, but this is a conceptual question).
The game has several actions that require a decision from the player to resolve, for example, in some cases, a player can choose to activate a cannon. Because, in the MVC pattern, the Model is passive and can't directly ask for input, our solution is to use an FSM, so that the Controller can monitor the Model's state and prompt the user for input based on the state. This is how we imagine the FSM, based on the various phases of the game: The problem is that we can't figure out who should be responsible for handling state transitions:
- Controller handles transitions: the Model simply contains the states and executes each state's code. The Controller reacts to inputs from the View and decides state transitions based on these inputs, forwarding inputs to the model when needed.
- Model handles trsnsitions: the Models performs state transitions, notifying the Controller when it does. Whenever the Model needs an input, it moves to some
InputRequest
state, which the Controller sees and prompts the View for an input. - Controller handles everything: the Model contains the states, but the Controller handles state transitions as well as instructing the Model on what to do based on the state.
Perhaps the third approach would actually make more sense if the FSM was actually in the Controller rather than the Model.
I hope the question is clear, thanks in advance for your help!