After creating a Match m, UI follows a relatively simple loop,
Below is a rough sketch of user code flow. It is written in pseudocode and omits some details, but is useful for understanding the overall structure. For a real example have a look at `../interfaces/tkbglight/tklight.tcl'.
For lack of better names I shall call the two sides Hal (computer) and Dave (human).
Create m, display match score, cube, and initial board.
LOOP until match is over
Call actions (see below)
IF Dave turn and he may double
wait for Dave to either
double - and call Match::opDoubles
or roll - and call opRolls
ELSEIF Dave just rolled
collect a move, then call opPlays
END-LOOP
Notes:
IF statement by setting up the appropriate buttons/pointing device (as part of the actions code), then simply wait for Dave action.
actions code,
while ( unprocessed event e ) {
switch ( type(e) ) {
ROLLS:
IF Hal rolled - Draw dice on Hal side of the board[1].
IF Dave rolled - Draw dice on Hal side of the board.
MOVES:
Move checkers on board.
IF Hal moved
IF Dave may double
Enable double button
ELSE
// Nothing to do. The next action will be a roll for Dave.
ELSE
// Dave moved. We get this only when automoves are enabled and this
// was a forced move
Pause for a short time to let Dave see what is happening.
DOUBLES:
// This can only be Hal. Dave doubles are not reported back.
Draw doubling cube inside the board on Dave side of board.
Open a dialog box informing Dave he has been doubled, and ask if he
takes or drops.
IF Dave accepts
Notify Hal (call opTakes)
Draw doubling cube on board margins, on Dave side of the board
ELSE
Notify Hal (call opDrops)
TAKES:
// This can only be Hal. Dave takes are not reported back.
Draw doubling cube on board margins, on Hal side of the board
DROPS:
// This can only be Hal. Dave drops are not reported back.
Notify Dave that he won this game
RESIGNS:
// This can only be Hal. Dave drops are not reported back.
Inform Dave that Hal is resigning and how many points he will get. Call
opAccepts(true) if Dave agrees, opAnswers(false) otherwise.
WINS:
Notify Dave who won and how many points.
Set up for a new game - update display of scores, doubling cube, board
and so on.
CRAWFORD:
Don't let Dave double this game, as this is the Crawford game.
}
}