Skip to content

ArenaBuilder

Joseph Newman edited this page Sep 22, 2021 · 1 revision

ArenaBuilders are one of the main creative objects in the Spite Framework. As the name implies, they create Arenas for you to manage your games. Arena Builders are also used to configure and set up other pieces of information, such as relationships between teams and so forth.

Example ArenaBuilder

This example comes from the Battleship example from the Spite Framework Examples repository.

Arena arena = new ArenaBuilder<BattleshipTeam>()
    // This sets the maximum number of teams. Could be useful if you're deserializing some kind of arena definition.
    .SetTeamCount(2)
    // Add the teams that are participating in this game
    .AddTeam(playerTeam) // Teams may be created through teambuilders
    .AddTeam(enemyTeam)
    // Set up the relationship between the teams. Not crucial in Battleship, but important in other scenarios.
    // See AllianceGraph for more information.
    .AddBidirectionalTeamRelationship(playerTeam, enemyTeam, TeamRelationship.Opposing)
    // This tells the arena to use the default "Discrete Player" turn scheme. She turn schemes for more information
    .SetTurnScheme(TurnSchemeType.DiscretePlayer)
    // Turn managers will use this to determine if a game has ended
    .SetBattleOverCondition(() =>
    {
        return playerTeam.CurrentStanding == TeamStanding.Defeated || enemyTeam.CurrentStanding == TeamStanding.Defeated;
    })
    // You can react to changes in the current phase using this method
    .AddPhaseChangedDelegateToTurnManager((ITurnPhase oldPhase, ITurnPhase nextPhase, ITurnManager turnManager) =>
	{
            if (nextPhase is PlayerPhase<ITeamExecutor> playerPhase)
	    {
                currentTeam = (BattleshipTeam)playerPhase.CurrentPlayer;
	    }
	})
     // Get the actual arena
     .Finish();
Clone this wiki locally