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

后端 未结 1 1242
不知归路
不知归路 2020-12-29 09:33

I am creating my first game in Java. The game is Monopoly. I am struggling with how I should design the game to model its turn-based structure (managing player turns). I

相关标签:
1条回答
  • 2020-12-29 10:25

    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.

    0 讨论(0)
提交回复
热议问题