最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

model view controller - Handling input requests in MVC pattern with an FSM - Stack Overflow

programmeradmin2浏览0评论

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:

  1. 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.
  2. 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.
  3. 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!

发布评论

评论列表(0)

  1. 暂无评论