| 1 |
#include <tads.h> |
| 2 |
|
| 3 |
|
| 4 |
class Thing: object |
| 5 |
desc() |
| 6 |
{ |
| 7 |
ldesc; |
| 8 |
inherited(); |
| 9 |
} |
| 10 |
ldesc = "" |
| 11 |
; |
| 12 |
|
| 13 |
enum small, medium, large, gigantic; |
| 14 |
|
| 15 |
class Sizable: object |
| 16 |
desc() |
| 17 |
{ |
| 18 |
"It appears to be <<if size == small>>small<<else if |
| 19 |
size == medium>>medium<<else if size == large>>large<< |
| 20 |
else if size == gigantic>>gigantic<<end>> in size. "; |
| 21 |
inherited(); |
| 22 |
} |
| 23 |
size = medium |
| 24 |
; |
| 25 |
|
| 26 |
class Openable: object |
| 27 |
desc() |
| 28 |
{ |
| 29 |
"The <<name>> is <<if isOpen>>open<<else>>closed<<end>>. "; |
| 30 |
inherited(); |
| 31 |
} |
| 32 |
isOpen = true |
| 33 |
size = medium |
| 34 |
; |
| 35 |
|
| 36 |
class Moistenable: object |
| 37 |
desc() |
| 38 |
{ |
| 39 |
"<<if isMoist>>It appears to be a bit damp. "; |
| 40 |
inherited(); |
| 41 |
} |
| 42 |
isMoist = nil |
| 43 |
; |
| 44 |
|
| 45 |
box: Thing, Sizable, Openable, Moistenable |
| 46 |
name = 'box' |
| 47 |
ldesc = "It's a brown cardboard box. " |
| 48 |
isOpen = true |
| 49 |
size = large |
| 50 |
isMoist = true |
| 51 |
; |
| 52 |
|
| 53 |
cabinet: Thing, Sizable, Openable, Moistenable |
| 54 |
name = 'cabinet' |
| 55 |
ldesc = "It's a large oak cabinet. " |
| 56 |
isOpen = nil |
| 57 |
; |
| 58 |
|
| 59 |
oven: Thing |
| 60 |
name = 'oven' |
| 61 |
desc = "The oven door is <<if isOpen>>open<<if isLit>> and |
| 62 |
the light inside is on<<end>><<else>>closed<<end>>. " |
| 63 |
|
| 64 |
isOpen = nil |
| 65 |
isLit = nil |
| 66 |
|
| 67 |
test(o, l) |
| 68 |
{ |
| 69 |
isOpen = o; |
| 70 |
isLit = l; |
| 71 |
desc; |
| 72 |
"\n"; |
| 73 |
} |
| 74 |
; |
| 75 |
|
| 76 |
main(args) |
| 77 |
{ |
| 78 |
box.desc(); "\b"; |
| 79 |
cabinet.desc(); "\b"; |
| 80 |
|
| 81 |
for (local i in 1..10) |
| 82 |
"\*Nested if with i=<<i>>: |
| 83 |
<<if i < 5>><<if i < 3>>i is less than 3<<else |
| 84 |
>>i is at least 3 but less than 5<<else if i <= 7>> |
| 85 |
i is 5-7<<else>>i is greater than 7<<end>>\n"; |
| 86 |
|
| 87 |
"\b"; |
| 88 |
for (local i in 10..100 step 10) |
| 89 |
{ |
| 90 |
local s = 'i=<<i>>, which is <<if i < 50>>less than |
| 91 |
fifty<<else if i < 70>>at least fifty, but less |
| 92 |
than seventy<<else>>seventy and up'; |
| 93 |
"<<s>>\n"; |
| 94 |
} |
| 95 |
|
| 96 |
"\b"; |
| 97 |
oven.test(nil, nil); |
| 98 |
oven.test(nil, true); |
| 99 |
oven.test(true, nil); |
| 100 |
oven.test(true, true); |
| 101 |
|
| 102 |
"\b"; |
| 103 |
local a = 5; |
| 104 |
"""This is an "unless" test. <<unless a < 3>>'a' is not less than 3. |
| 105 |
<<end>><<unless a > 3>>'a' is not greater than 3."""; |
| 106 |
|
| 107 |
"\b"; |
| 108 |
"""Second "unless" test. <<unless a < 7>>'a' is not less than 7."""; |
| 109 |
|
| 110 |
"\b"; |
| 111 |
"""Third "unless" test. <<unless a < 3>>'a' is not less than 3."""; |
| 112 |
|
| 113 |
"\b"; |
| 114 |
local s = '''Another "unless" test. <<unless a > 3>>'a' is not |
| 115 |
greater than 3.<<otherwise if a > 7>>'a' is more than 7. |
| 116 |
<<otherwise unless a > 6>>'a' is less than 6. '''; |
| 117 |
"<<s>>"; |
| 118 |
|
| 119 |
// test from example in doc |
| 120 |
"\b"; |
| 121 |
{ |
| 122 |
local i = 3, j = 'boo'; |
| 123 |
local s = 'The value of i is <<i>>, and j is <<j>>!'; |
| 124 |
"s is: <<s>>\n"; |
| 125 |
i = 7; |
| 126 |
j = 'boo hoo'; |
| 127 |
"s is now: <<s>>\n"; |
| 128 |
} |
| 129 |
|
| 130 |
// another doc example |
| 131 |
"\b"; |
| 132 |
{ |
| 133 |
local i = 3, j = 'boo'; |
| 134 |
local s = {: 'The value of i is <<i>>, and j is <<j>>!'}; |
| 135 |
"s is: <<s()>>\n"; |
| 136 |
i = 7; |
| 137 |
j = 'boo hoo'; |
| 138 |
"s is now: <<s()>>\n"; |
| 139 |
} |
| 140 |
|
| 141 |
"\n"; |
| 142 |
} |