home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 5
/
ctrom5b.zip
/
ctrom5b
/
PROGRAM
/
DIVERSEN
/
TIPI2A
/
HANGMAN.TPI
< prev
next >
Wrap
Text File
|
1994-09-13
|
3KB
|
160 lines
# HANGMAN.TPI
# by Kent Peterson
define head
1 3 locate 1 chr$ print$
enddef
define shoulders
2 3 locate 206 chr$ print$
enddef
define hips
3 3 locate 202 chr$ print$
enddef
define leftarm
2 2 locate 201 chr$ print$
enddef
define leftleg
3 2 locate 201 chr$ print$
4 2 locate 188 chr$ print$
enddef
define rightleg
3 4 locate 187 chr$ print$
4 4 locate 200 chr$ print$
enddef
define rightarm
2 4 locate 187 chr$ print$
enddef
define gallows
0 0 locate
214 chr$ print$
2 do
196 chr$ print$
loop
191 chr$ print$ cr
4 do
186 chr$ print$ cr
loop
200 chr$ print$
4 do
205 chr$ print$
loop
enddef
defstr word$
defstr used$
define pickword
"R" "HANGWORD.TXT" 1 open
1 isinput
1 EOF FILEPOS 10 -
dup 0 < if | HANGWORD.TXT not found!
| program aborting!
bye
endif
random 1 swap filepos drop
get$ drop$ get$ dup$ "<END>" =$
if drop$ 1 1 filepos get$ drop$ get$ endif
1 close
console isinput
lcase$
word$ store
"" used$ store
enddef
deftable drawpart
head shoulders leftarm rightarm hips leftleg rightleg
endtable
define drawman
# draws parts of the man depending
# on n
0 cursor drawpart 1 cursor
enddef
define isupper? ( -- n )
( a$ -- a$ )
# n is true if a$ is uppercase
asc 64 >
if asc 91 <
if 1 else 0 endif
else 0 endif
enddef
define display
word$ fetch len
do
len 1 + index -
dup$ 1 mid$ isupper? if print$
else drop$ "-" print$ endif
" " print$
loop
drop$
enddef
define message
1 10 locate print$
enddef
define hangman
cls
pickword
gallows
5 10 locate display
begin
"Guess a letter." message
begin
key dup if dup endif
until
" " message
dup 27 = if cls bye endif
word$ fetch dup$
dup chr$ lcase$ dup$ ucase$ replace$
dup$ word$ store
=$ if chr$ ucase$
used$ fetch swap$ +$
used$ dup$ store
len dup drawman
3 10 locate print$
7 = if
"Sorry, You Lose!"
message
begin
key
until
word$ fetch ucase$
word$ store
5 10 locate display
"LOST" word$ store
endif
else drop 5 10 locate display
endif
word$ fetch dup$ ucase$ =$
until
"LOST" word$ fetch =$ not if
"You Win!!! "
message
endif
begin
key
until
enddef
randomize
begin
hangman
"Would you like to play again?"
message
begin
key dup if dup endif
until
chr$ ucase$ 1 left$ "Y" =$ not
until
cls