| 1 |
/* |
| 2 |
* status line test |
| 3 |
*/ |
| 4 |
|
| 5 |
#include "t3.h" |
| 6 |
#include "tads.h" |
| 7 |
|
| 8 |
_say_embed(str) { tadsSay(str); } |
| 9 |
|
| 10 |
class RuntimeError: object |
| 11 |
construct(errno, ...) { errno_ = errno; } |
| 12 |
display = "Runtime Error: <<exceptionMessage>>" |
| 13 |
errno_ = 0 |
| 14 |
exceptionMessage = '' |
| 15 |
; |
| 16 |
|
| 17 |
global: object |
| 18 |
turncount = 0 |
| 19 |
score = 0 |
| 20 |
statmsg = 'Start Room' |
| 21 |
; |
| 22 |
|
| 23 |
_main(args) |
| 24 |
{ |
| 25 |
try |
| 26 |
{ |
| 27 |
t3SetSay(&_say_embed); |
| 28 |
main(); |
| 29 |
} |
| 30 |
catch (RuntimeError rte) |
| 31 |
{ |
| 32 |
"\n<<rte.display>>\n"; |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
main() |
| 37 |
{ |
| 38 |
"Welcome! Type QUIT to quit, SCORE to add points to the score, @file |
| 39 |
to read a script file.\n"; |
| 40 |
|
| 41 |
for (;;) |
| 42 |
{ |
| 43 |
local cmd; |
| 44 |
|
| 45 |
/* update the status line */ |
| 46 |
showStatus(); |
| 47 |
|
| 48 |
/* count the turn */ |
| 49 |
++global.turncount; |
| 50 |
|
| 51 |
/* display the prompt and wait for a command */ |
| 52 |
"> "; |
| 53 |
cmd = inputLine(); |
| 54 |
|
| 55 |
/* check for a script file specification */ |
| 56 |
if (rexMatch(' *@(@?)(!?) *(.*)', cmd) != nil) |
| 57 |
{ |
| 58 |
local g; |
| 59 |
local flags = 0; |
| 60 |
|
| 61 |
/* if an extra @ was specified, turn off MORE mode */ |
| 62 |
g = rexGroup(1); |
| 63 |
if (g != nil && g[2] != 0) |
| 64 |
flags |= ScriptFileNonstop; |
| 65 |
|
| 66 |
/* if ! was specified, turn on QUIET mode */ |
| 67 |
g = rexGroup(2); |
| 68 |
if (g != nil && g[2] != 0) |
| 69 |
flags |= ScriptFileQuiet; |
| 70 |
|
| 71 |
/* get the filename part and open the script file */ |
| 72 |
g = rexGroup(3); |
| 73 |
setScriptFile(g[3], flags); |
| 74 |
|
| 75 |
/* done with this command */ |
| 76 |
continue; |
| 77 |
} |
| 78 |
|
| 79 |
/* see what we have */ |
| 80 |
switch(cmd.toLower()) |
| 81 |
{ |
| 82 |
case 'quit': |
| 83 |
"Bye!\n"; |
| 84 |
return; |
| 85 |
|
| 86 |
case 'score': |
| 87 |
"Adding ten points to the score.\n"; |
| 88 |
global.score += 10; |
| 89 |
break; |
| 90 |
|
| 91 |
default: |
| 92 |
"Ignored.\n"; |
| 93 |
break; |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
showStatus() |
| 99 |
{ |
| 100 |
/* |
| 101 |
* Update the score part. Note that we must update the entire |
| 102 |
* status line in order for the score portion to show up on the |
| 103 |
* screen, so set the right half before we do the update. |
| 104 |
*/ |
| 105 |
statusRight(cvtStr(global.score) + '/' + cvtStr(global.turncount)); |
| 106 |
|
| 107 |
/* display the status line */ |
| 108 |
statusMode(StatModeStatus); |
| 109 |
tadsSay(global.statmsg + '\n'); |
| 110 |
statusMode(StatModeNormal); |
| 111 |
} |
| 112 |
|