Skip to content
Lingxiao Yu edited this page Oct 15, 2020 · 1 revision

Concepts

Concepts are borrowed from boardgame.io but simplified.

Action

An action defines Execute and Undo behaviours, they are the basic elements of a game. The final state of a game is procedurally built upon an ordered series of actions, thus we can go forward and backward by chaining Execute or Undo in a sequence.

I provide two types of actions:

  • ActionBase
  • StageAction : ActionBase

Actions undo can be disabled:

ActionBase action = CreateAction();
action.disableUndo = true;

Never call Execute and Undo on actions directly. Call them on sequence instead.

Sequence

A sequence contains two queues of actions: actionWait and actionDone. It provides ability to execute forward and backward. A sequence can be a turn, half turn, or even fine granular time elapse you want, depends on how many actions you allow players to undo (you store them in a sequence).

We need to enqueue actions before we proceed a sequence. Prepare the sequence as:

ActionSequence sequence = new ActionSequence();
ActionBase action = CreateAction();

sequence.Register(action);

We move actions from wait to done if we call:

  • NextAction(), once per time
  • RunUntilEnd(), run all until an action is not undoable, or queue is empty

And vice versa:

  • UndoAction()
  • UndoUntilEnd()

Slow mode

Set a delay in a sequence so it adds a delay to every action:

sequence.delayMS = 100; // 100 miliseconds

Stage

A stage is a game state. It provides two information:

  • What action is available?
  • Do actions hit a limit at this stage?

It provides a context for a sequence to execute. So you can take an action from a stage, and execute the action using a sequence, which automatically decrease the action limit for a stage.

The stage and action limit, for an action can be disabled.

/* use StageAction to link to a stage */
StageAction action = CreateAction();
Stage stage = new Stage() 
{
    moveLimit = 1,
    name = "InitStage"
}
ActionSequence sequence = new ActionSequence();

/* also need to register the action */
stage.Register(action);
sequence.Register(action);

/* decrease moveLimit */
sequence.NextAction();

This can be turned off:

StageAction action = CreateAction();
action.useMoveLimit = false;

/* an action can also don't have a stage, this is set by default */
action.stage = null;

You can also chain stages to switch between stages:

/* they have different actions available and different moveLimit */
stage1.NextStage = stage2;
Clone this wiki locally