Skip to content
webxoss edited this page Nov 23, 2018 · 2 revisions

Overview

WEBXOSS main loop

Image source

Powered by plantuml.

@startuml
hide empty description
[*] -> Initialize
Initialize: Create Players, Cards, etc.
Initialize -> SetupEffects: game.start()
SetupEffects: See [[https://github.com/webxoss/webxoss-core/wiki/Effects-Handling Effect Handling]]
SetupEffects -> GameLoop
GameLoop -> GameOver: By calling game.win(),\nbreak the loop.

state GameLoop {
  state "phase.setup" as PhaseSetup
  [*] -> PhaseSetup
  PhaseSetup -> UpPhase
  UpPhase -> OtherPhases
  OtherPhases -> EndPhase
  EndPhase -> UpPhase: Switch player\n(We call this **wixoss()** XD)
}

GameLoop -down-> IO: 1. Hangup on async calls.\n(See [[https://github.com/webxoss/webxoss-core/wiki/Async-Calls Async Calls]])
IO -> client: 2. Request input
client -> IO: 3. Send input
IO -down-> GameLoop: 4. Resume after user input.
@enduml

Description

A WEBXOSS game is initialized by calling Game() constructor. Once started, it setup all the Effects(See Effect Handling for more details.) and ran into the main loop.

The loop starts with phase.setup, deciding first hand player, giving initial hands and life bursts, etc, then loops over phases(From UpPhase to EndPhase then switch player and back to UpPhase) infinitely, which was interrupted when:

  1. Requiring user input;

    In WEBXOSS, a function call which requires user input was called an async call. When called, it pauses the loop until having received user input. We will discuss this in Async Calls.

  2. Calling game.win().

    game.win() might be called anywhere. Once called, we break the loop, send messages to client, end the game.