DisplayField:
PROC[t: T, context: Imager.Context, erase:
BOOL] = {
x, y: REAL;
rope: ROPE;
IF erase THEN Erase[t, context, ImagerBackdoor.GetBounds[context]];
IF t.viewer.column = color
THEN {
Imager.SetColor[context, ImagerColor.ColorFromRGB[[R: 0, G: 1, B: 0]]];
Imager.MaskRectangle[context, ImagerBackdoor.GetBounds[context]];
Imager.SetColor[context, Imager.white];
};
y ← fieldWidth*yard;
DrawLine[context, -10*yard, 0, 110*yard, 0];
DrawLine[context, -10*yard, fieldWidth*yard, 110*yard, fieldWidth*yard];
DrawLine[context, -10*yard, 0, -10*yard, y];
DrawLine[context, 110*yard, 0, 110*yard, y];
FOR i:
INTEGER
IN [0..10]
DO
x ← i*10*yard;
y ← fieldWidth*yard;
DrawLine[context, x, 0, x, y];
DrawLine[context, x-3, y/3, x+3, y/3];
DrawLine[context, x-3, 2*y/3, x+3, 2*y/3];
IF i = 0
OR i = 10
THEN rope ← Rope.FromChar['G]
ELSE rope ← Convert.RopeFromInt[MIN[100-i*10, i*10]];
DrawRope[context, rope, x-5, y+5];
DrawRope[context, rope, x-5, -15];
ENDLOOP;
IF t.viewer.column # color
THEN {
Imager.SetGray[context, 0.5];
Imager.MaskBox[context, [-10*yard, 0, 0, fieldWidth*yard]];
Imager.MaskBox[context, [100*yard, 0, 110*yard, fieldWidth*yard]];
Imager.SetGray[context, black];
};
};
DisplayStats:
PROC[t: T, context: Imager.Context, erase:
BOOL] = {
(home)
HOME* First Quarter VISITORS
7 7:14 14
4 - timeouts - 4
first down and goal on the 4
OPEN t;
number: ROPE;
IF erase THEN Erase[t, context, scoreboard];
MessageWindow.Clear[]; -- remove any messages.
first line
IF myTeam = home
THEN DrawRope[context, "(home)", statsX+82, statsY+15]
ELSE DrawRope[context, "(visitors)", statsX+75, statsY+15];
Imager.SetXY[context, [statsX, statsY]];
IF game.offense = home
THEN MyShowRope[context, "HOME* "]
ELSE MyShowRope[context, "HOME "];
SELECT game.quarter
FROM
1 => MyShowRope[context, " First Quarter "];
2 => MyShowRope[context, " Second Quarter "];
3 => MyShowRope[context, " Third Quarter "];
4 => MyShowRope[context, " Fourth Quarter "];
5 => MyShowRope[context, " Game Over "];
ENDCASE => ERROR;
IF game.offense = visitors
THEN MyShowRope[context, "VISITORS* "]
ELSE MyShowRope[context, "VISITORS "];
second line
number ← Convert.RopeFromInt[game.score[home]];
DrawRope[context, number, statsX+20, statsY-15];
(clock drawn separately)
number ← Convert.RopeFromInt[game.score[visitors]];
DrawRope[context, number, statsX+185, statsY-15];
third line
number ← Convert.RopeFromInt[game.timeouts[home]];
DrawRope[context, number, statsX+20, statsY-30];
DrawRope[context, " - timeouts - ", statsX+60, statsY-30];
number ← Convert.RopeFromInt[game.timeouts[visitors]];
DrawRope[context, number, statsX+185, statsY-30];
fourth line
SELECT game.down
FROM
1 => number ← "first down and ";
2 => number ← "second down and ";
3 => number ← "third down and ";
4 => number ← "fourth down and ";
ENDCASE => number ← ">>>> down and ";
DrawRope[context, number, statsX-20, statsY-45];
IF game.firstDownMarker <= 0
OR game.firstDownMarker >= 100
THEN number ← "goal"
ELSE {toGo:
INTEGER;
toGo ← Real.Round[ABS[game.scrimmage-game.firstDownMarker]];
number ← IF toGo < 1 THEN "inches" ELSE Convert.RopeFromInt[toGo]};
MyShowRope[context, number];
MyShowRope[context, " to go on the "];
number ← Convert.RopeFromInt[
MIN[Real.Round[game.scrimmage], Real.Round[100-game.scrimmage]]];
MyShowRope[context, number];
MyShowRope[context, " yard line."];
display status
Imager.SetXY[context, [statsX - 20, statsY - 60]];
IF game.penalties # [none, none] THEN {DisplayPenalties[t, context]; RETURN};
Imager.SetXY[context, [statsX + 60, statsY - 60]];
SELECT game.score[home] - oldScore[home]
FROM
7 => FlashMessage["TOUCHDOWN! "];
3 => FlashMessage["FIELD GOAL! "];
2 => FlashMessage["SAFETY! "];
ENDCASE;
SELECT game.score[visitors] - oldScore[visitors]
FROM
7 => FlashMessage["TOUCHDOWN! "];
3 => FlashMessage["FIELD GOAL! "];
2 => FlashMessage["SAFETY! "];
ENDCASE;
};
DisplayPenalties:
PROC[t: T, context: Imager.Context] = {
DisplayPenalty[context, t.game.penalties[home], home];
IF t.game.penalties[visitors] # none
THEN {
IF t.game.penalties[home] # none THEN MyShowRope[context, " and "];
DisplayPenalty[context, t.game.penalties[visitors], visitors]};
MyShowRope[context, ": "];
SELECT t.game.penaltyState
FROM
accepted => MyShowRope[context, "ACCEPTED."];
declined => MyShowRope[context, "DECLINED."];
canceled => MyShowRope[context, "CANCELED."];
ENDCASE;
};
DisplayClock:
PROC[t: T, context: Imager.Context, clock:
INTEGER, erase:
BOOL] = {
stream: IO.STREAM ← IO.ROS[];
IF erase THEN Erase[t, context, [statsX+89, statsY-16, 60, 12]];
stream.PutF["%2d:%02d", IO.int[clock/60], IO.int[clock MOD 60]];
DrawRope[context, IO.RopeFromROS[stream], statsX+90, statsY-15];
stream.Close[];
};
DisplayPlayer:
PROC[t: T, context: Imager.Context, player: Player, erase:
BOOL] = {
i: Position;
x, y: REAL;
same: BOOL;
char: CHAR;
i ← player.position;
x ← Real.Round[player.x*yard];
y ← Real.Round[player.y*yard];
char ← IF TeamOf[i] = home THEN 'O ELSE 'X;
same ← (x = t.shadow[i].oldX AND y = t.shadow[i].oldY AND char = t.shadow[i].char);
IF erase AND same THEN RETURN;
IF erase AND ~same THEN DrawChar[context, t.shadow[i].char, t.shadow[i].oldX, t.shadow[i].oldY];
DrawChar[context, char, x, y];
t.shadow[i].oldX ← x;
t.shadow[i].oldY ← y;
t.shadow[i].char ← char;
};