Turn-based Game Design: Event-Driven vs. Game Loop

此生再无相见时 提交于 2019-11-30 07:08:08

The comment from SirDarius is spot on.

Though, for something as simple as advancing player turns, you don't really need to bother implementing a full fledged finite state machine.

In terms of MVC, this is what you should do for human players:

  • The Model: Provide methods for advancing the active player to the next player and for running through the "turn process" (i.e. rolling the dice, moving the active player's token, etc.). Because much of the turn process is event driven, these method calls will be made from event listeners in the controller.

  • The View: Raise an event when the active player finishes their turn, as well as raising events on various other input.

  • The Controller: Whenever a player finishes their turn, tell the model to advance to the next player, and start the "turn process" again. Whenever a player provides input, an event will be fired that tells the model to advance to the next stage of the turn.

For AI players, the majority of the same code can be used, but it does not make sense to have the turn progression be driven by the view. Instead, the model would need to have another "turn process" method which would be specifically for AI players. The only difference being that the code would execute in succession without waiting for input from the view, instead of being a series of event listeners.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!