Gorilla.Arena.Match Unit Reference
Overview
The Gorilla.Arena.Match unit provides TGorillaArenaMatch, a
TGorillaArenaSession in which everybody takes turns. It adds seating, turn
order, host authority and state synchronisation, and drives an
IGorillaArenaRules implementation supplied by the application.
The host owns the only authoritative rules instance. Every other device keeps one purely to render the state the host ships it.
Class Hierarchy
TComponent
└── TGorillaArenaManager
└── TGorillaArenaSession
└── TGorillaArenaMatch
Constants
Payload field names used by the match messages.
| Constant | Value |
|---|---|
ARENA_DATA_IDS |
ids |
ARENA_DATA_NAMES |
names |
ARENA_DATA_HOST |
host |
ARENA_DATA_RULES |
rules |
ARENA_DATA_STARTED |
started |
ARENA_DATA_STATE |
state |
ARENA_DATA_HEADLINE |
headline |
ARENA_DATA_MEMBER |
member |
ARENA_DATA_TURN |
turn |
ARENA_DATA_BY |
by |
ARENA_DATA_MOVE |
move |
ARENA_DATA_NAME |
name |
The message types themselves are in Gorilla.Arena.Message.
Event Types
| Type | Signature |
|---|---|
TGorillaArenaMoveEvent |
procedure(const ASender : TObject; const AName : String; const AMove : TJSONObject) of object |
TGorillaArenaCreateRulesEvent |
procedure(const ASender : TObject; const AId : String; out ARules : IGorillaArenaRules) of object |
AMove is borrowed and may be nil. Leave ARules nil for an id this build
cannot produce.
TGorillaArenaMatch
Published Properties
| Property | Type | Description |
|---|---|---|
RulesComponent |
TGorillaArenaRules |
A rules component on the same form, used when nothing else builds the rules |
OnMatchChanged |
TNotifyEvent |
The state, the turn or the outcome changed |
OnRemoteMove |
TGorillaArenaMoveEvent |
Somebody else moved |
OnCreateRules |
TGorillaArenaCreateRulesEvent |
Build the rules behind an id |
Public Properties
| Property | Type | Description |
|---|---|---|
Rules |
IGorillaArenaRules |
The rules in play. Settable for one fixed set |
RulesId |
String |
Id of the rules in play (read only) |
HostId |
String |
Id of whoever is hosting (read only) |
InMatch |
Boolean |
True while a match is running |
Public Methods
| Method | Description |
|---|---|
StartMatch(const ARulesId : String = '') |
Host only. Builds the rules, checks MinMembers, fixes the seating and announces the start |
SubmitMove(AMove : TJSONObject) |
Reports what we did on our turn. Takes ownership; AMove may be nil. Does nothing unless it was our turn |
CloseSession() |
Overridden: clears the match state, then leaves the session |
IsMyTurn() : Boolean |
Our turn, and we have not moved yet |
TurnSeat() : Integer |
Seat of whoever is on turn, or -1 |
TurnMemberName() : String |
Their name, or '' |
SeatOf(const AId : String) : Integer |
Seat of an id, or -1 |
Participants() : TGorillaArenaMembers |
Everybody, in the order they should be listed |
Scoreboard() : TGorillaArenaScoreboard |
The rules' scoreboard, or empty |
Headline() : String |
The rules' headline, or '' |
Protected Methods (Extension Points)
| Method | Description |
|---|---|
CreateRules(const AId : String) : IGorillaArenaRules |
Asks OnCreateRules, then falls back to RulesComponent. Override to use a registry |
DoDecorateStart(AMsg) |
Host: add application data to the start message |
DoApplyStart(AMsg) |
Client: read it back |
DoDecorateTurn(AMsg) |
Host: add application data to a turn message |
DoApplyTurn(AMsg) |
Client: read it back |
DoRemoteMove(const AName : String; const AMove : TJSONObject) |
Somebody else moved. The base raises OnRemoteMove |
MatchChanged() |
Raises OnMatchChanged |
Protected Fields
| Field | Type | Description |
|---|---|---|
FRules |
IGorillaArenaRules |
The rules in play |
FRulesId |
String |
Their id |
FHostId |
String |
Id of the host |
FSeating |
TList<TGorillaArenaMember> |
Seating order; the truth on the host, a copy elsewhere |
FRoster |
TList<TGorillaArenaMember> |
Client side: who the host says is in |
FStarted |
Boolean |
A match is running |
FTurnId |
String |
Who is on turn |
FTurnNo |
Integer |
Which turn — distinguishes a new instruction from a repeat |
FReported |
Boolean |
Client side: we have already moved for FTurnNo |
Behaviour Notes
Seating is fixed at the start. A member who leaves keeps their seat and
score and is marked Here := False; the rules are told through MemberLeft.
Turn numbers stop double moves. The host re-sends the current turn whenever somebody greets, and the session layer greets more than once per join. A turn message repeating the number this device already answered is ignored.
Participants() answers differently by situation — the seating during a
match, the host's roster on a client before one, and the session's member list
otherwise. A roster the client is not itself in is ignored.
Two hosts meeting settle by id: the lower id keeps the session, the other
switches to asrClient.
A newcomer mid match gets the lobby, the current state, and the running turn marked as a repeat.