Beginner’s Guide to Boardgame.io (Part 4): Phases
Now that we have basic setup out of the way, we can get into the nitty gritty of how board games are structured on boardgame.io.
Phases
First, Boardgame.io has “phases”. Phases are periods of the game which override the default game configuration when toggled. For example, you may have different phases of the game that allow for different moves or different turn orders. The game will allow for different phases to be transitioned between, and for turns to occur inside each individual phase. For example, many modern drafting board games may have draw phases for cards, where cards are being drawn/selected, and then play phases where the cards are actually played.
Phases are set up in the game object like so:
phases is a property name of the game object, and you can detail multiple phases, each with their own individual movepool. In the above gist, you see a game with a draw phase and a play phase. If no moves are detailed in the phase object, then the general movepool of the game will be used.
Other Phase Object Flags
There are also other phase object flags to modify the behavior of the phase in the boardgame.io game. First, you can set the default/first phase of the game with the ‘start’ property name.
start: true,
You can also set an endIf condition that ends the phase if it fits the requirements, like so:
endIf: G => (G.deck <= 0),
Lastly, you can set what phase is the next phase that would be transitioned to if the phase ended via the endIf flag or the endPhase event.
next: 'play',
Ending Phase
As mentioned above, you can end the phase of a board game by setting an endIf property name in the phase object. Alternatively, you can end the phase using the event provided by boardgame.io. The event is passed into props as an event, and you can call this on your Board component to end the phase:
this.props.events.endPhase();
And lastly, you can manually set the phase if you want to force the phase to advance to a specific one:
this.props.events.setPhase();
In the arguments, you would provide the phase name as a string.
Conclusion
Phases are a fantastic way to organize your game, as it logically matches up to board games already. Boardgame.io thus gives you the tools to recreate phases in your online board games so phases are properly organized and so that moves and behaviors are properly separated and delineated.
Now, how about if different players will have different actions and moves available to them depending on whose turn it is? That is not solved by phases but with stages, which we will learn about next week.