home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / tipi / hangman.tpi < prev    next >
Text File  |  1993-11-05  |  3KB  |  162 lines

  1. # HANGMAN.TPI
  2.  
  3. define head
  4.  1 3 locate 1 chr$ print$
  5. enddef
  6.  
  7. define shoulders
  8.  2 3 locate 206 chr$ print$
  9. enddef
  10.  
  11. define hips
  12.  3 3 locate 202 chr$ print$
  13. enddef
  14.  
  15. define leftarm
  16.  2 2 locate 201 chr$ print$
  17. enddef
  18.  
  19. define leftleg
  20.  3 2 locate 201 chr$ print$
  21.  4 2 locate 188 chr$ print$
  22. enddef
  23.  
  24. define rightleg
  25.  3 4 locate 187 chr$ print$
  26.  4 4 locate 200 chr$ print$
  27. enddef
  28.  
  29. define rightarm
  30.  2 4 locate 187 chr$ print$
  31. enddef
  32.  
  33. define gallows
  34.  0 0 locate
  35.  214 chr$ print$
  36.  2 do
  37.   196 chr$ print$
  38.  loop
  39.  191 chr$ print$ cr
  40.  4 do
  41.   186 chr$ print$ cr
  42.  loop
  43.  200 chr$ print$
  44.  4 do
  45.   205 chr$ print$
  46.  loop
  47. enddef 
  48.  
  49. defstr word$
  50. defstr used$
  51.  
  52. deftable wordlist
  53.  "china"   "computer" "radio"
  54.  "river"   "elbow"    "escort"
  55.  "example" "talk"     "work"
  56.  "pizza"   "thing"    "dangerous"
  57.  "example" "kidney"   "budget"
  58.  "space"   "billion"  "brain"
  59.  "drawing" "winter"   "message"
  60.  "monster" "visual"   "unusual"
  61.  "monkey"  "triangle" "magazine"
  62.  "jacket"  "bottle"   "alligator"
  63. endtable
  64.  
  65. define pickword
  66.  30 random wordlist
  67.  word$ store
  68.  "" used$ store
  69. enddef 
  70.  
  71. deftable drawpart
  72.  head shoulders leftarm rightarm hips leftleg rightleg
  73. endtable
  74.  
  75. define drawman
  76. # draws parts of the man depending
  77. # on n
  78.  0 cursor drawpart 1 cursor
  79. enddef
  80.  
  81. define isupper? ( -- n )
  82.                 ( a$ -- a$ )
  83. # n is true if a$ is uppercase
  84.  asc 64 >
  85.  if asc 91 <
  86.   if 1 else 0 endif
  87.  else 0 endif
  88. enddef     
  89.  
  90. define display
  91.  word$ fetch len
  92.  do
  93.   len 1 + index -
  94.   dup$ 1 mid$ isupper? if print$
  95.   else drop$ "-" print$ endif
  96.   " " print$
  97.  loop
  98.  drop$ 
  99. enddef 
  100.  
  101. define message
  102.  1 10 locate print$
  103. enddef
  104.  
  105. define hangman
  106. cls
  107. gallows
  108. pickword
  109. 5 10 locate display
  110. begin
  111.  "Guess a letter." message
  112.  begin
  113.   key dup if dup endif
  114.  until
  115.  "                   " message
  116. dup 27 = if cls bye endif
  117. word$ fetch dup$
  118. dup chr$ lcase$ dup$ ucase$ replace$
  119. dup$ word$ store
  120.  =$ if chr$ ucase$
  121.        used$ fetch swap$ +$
  122.        used$ dup$ store
  123.        len dup drawman
  124.        3 10 locate print$
  125.        7 = if
  126.          "Sorry, You Lose!"
  127.          message
  128.          begin
  129.           key
  130.          until
  131.          word$ fetch ucase$
  132.          word$ store
  133.          5 10 locate display
  134.          "LOST" word$ store
  135.         endif
  136.     else drop 5 10 locate display
  137.     endif
  138. word$ fetch dup$ ucase$ =$
  139. until
  140. "LOST" word$ fetch =$ not if
  141.  "You Win!!!                "
  142.  message
  143. endif
  144. begin
  145.  key
  146. until
  147. enddef
  148.  
  149. randomize
  150. begin
  151.  hangman
  152.  "Would you like to play again?"
  153.  message
  154.  begin
  155.   key dup if dup endif
  156.  until
  157.  chr$ ucase$ 1 left$ "Y" =$ not
  158. until
  159. cls
  160. bye
  161.  
  162.