Gorilla.Arena.Rules Unit Reference

Overview

The Gorilla.Arena.Rules unit describes what a match is played by: the participants, the seating over them, the scoreboard, and the IGorillaArenaRules interface a TGorillaArenaMatch drives.

Nothing in the unit knows about tethering or FireMonkey, so a set of rules can be exercised on its own — without a network and without a form.

Class Hierarchy

TInterfacedObject
  └── TGorillaArenaCustomRules        implements IGorillaArenaRules

TComponent
  └── TGorillaArenaRules              implements IGorillaArenaRules

Records

TGorillaArenaMember

One participant, as the rules see them.

Field Type Description
Id String Stable identity, handed out by the session
Name String What the others read
Here Boolean False once somebody left mid match — their turns get skipped

TGorillaArenaMembers = TArray<TGorillaArenaMember>

TGorillaArenaScoreRow

Field Type Description
Name String Whose row this is
Score Integer The number that decides the ranking
Detail String Free text next to it
Current Boolean Marks the member whose turn it is
Gone Boolean Marks a member who left

TGorillaArenaScoreboard = TArray<TGorillaArenaScoreRow>

TGorillaArenaRulesInfo

What a lobby needs to know without instantiating anything.

Field Type Description
Id String Stable key. Travels on the wire — never translate it
Name String What the lobby shows
Description String One line under the name
MinMembers Integer Below this the match will not start
MaxMembers Integer Above this nobody else is seated. 0 means no limit

TGorillaArenaSeating

The seating of one match and the turn order over it. Held by both base classes so the way a table is walked round exists once.

Member Description
Members : TGorillaArenaMembers The seating
Reset(const AMembers) Takes a copy
MemberLeft(const ASeat : Integer) Marks one seat as left behind
NextPresentSeat(const AFrom : Integer) : Integer Next occupied seat after AFrom, or -1. One lap at most
PresentCount() : Integer How many are still here
Count() : Integer How many seats there are
SeatOf(const AId : String) : Integer Seat of an id, or -1

IGorillaArenaRules

GUID {6B1D2A54-9F73-4C86-A1E2-0D7F35C9B481}

Method Description
GetRulesInfo() : TGorillaArenaRulesInfo Describes the rules
Reset(const AMembers : TGorillaArenaMembers) Starts a fresh match in this seating order
CurrentSeat() : Integer Seat of whoever is to move, or -1 when the match is over
SubmitTurn(const ASeat : Integer; const AMove : TJSONObject) Feeds one move in and advances the turn. AMove is borrowed and may be nil
MemberLeft(const ASeat : Integer) A member is gone; their turns are skipped
Finished() : Boolean The match is over
StateToJSON() : TJSONObject Everything a client needs to render. The caller owns the result
StateFromJSON(const AState : TJSONObject) Applies what the host sent. Does not take ownership
Headline() : String One line above the scoreboard
Scoreboard() : TGorillaArenaScoreboard The rows to show

Only the host ever sees SubmitTurn, CurrentSeat and Finished acted upon; on a client the instance is a renderer fed by StateFromJSON.

TGorillaArenaCustomRules

Reference counted base for rules built on demand — a registry of several games, for instance.

Public Methods

GetRulesInfo, CurrentSeat, SubmitTurn, Finished, StateToJSON, StateFromJSON, Headline and Scoreboard are virtual; abstract — a descendant must supply them. Reset and MemberLeft are virtual and already maintain the seating; call inherited.

Protected Methods

Method Description
NextPresentSeat(const AFrom : Integer) : Integer Forwards to the seating
PresentCount() : Integer Forwards to the seating

Public Properties

Property Type Description
Members TGorillaArenaMembers The seating

TGorillaArenaRules

The same, as a component: drop a descendant on a form and point TGorillaArenaMatch.RulesComponent at it. TComponent implements IInterface without reference counting, so the match holding the interface does not change who owns the component — the form does.

Same method and property set as TGorillaArenaCustomRules.

See Also