home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / tipi / ppuzzle.tpi < prev    next >
Text File  |  1993-11-02  |  1KB  |  77 lines

  1. # PPUZZLE.TPI
  2. # by Kent Peterson 10/30/93
  3.  
  4. defstr board$
  5. "ABCDEFGHIJKLMNOP" board$ store
  6.  
  7. define display
  8.  0 0 locate
  9.  " 1|" print$
  10.  board$ fetch dup$ 4 left$ print$ cr
  11.  " 2|" print$
  12.  dup$ 5 4 mid$ print$ cr
  13.  " 3|" print$
  14.  dup$ 9 4 mid$ print$ cr
  15.  " 4|" print$
  16.  4 right$ print$ cr
  17.  " -+----" print$ cr
  18.  "  |5678" print$ cr
  19. enddef
  20.  
  21. define move ( n -- )
  22. # Changes the board in one of 8 ways
  23.  case 1 of
  24.  2 3 4 1 5 6 7 8 9 10 11 12 13 14 15 16
  25.  endof
  26.  2 of
  27.  1 2 3 4 6 7 8 5 9 10 11 12 13 14 15 16
  28.  endof
  29.  3 of
  30.  1 2 3 4 5 6 7 8 10 11 12 9 13 14 15 16
  31.  endof
  32.  4 of
  33.  1 2 3 4 5 6 7 8 9 10 11 12 14 15 16 13
  34.  endof
  35.  5 of
  36.  5 2 3 4 9 6 7 8 13 10 11 12 1 14 15 16
  37.  endof
  38.  6 of
  39.  1 6 3 4 5 10 7 8 9 14 11 12 13 2 15 16
  40.  endof
  41.  7 of
  42.  1 2 7 4 5 6 11 8 9 10 15 12 13 14 3 16
  43.  endof
  44.  8 of
  45.  1 2 3 8 5 6 7 12 9 10 11 16 13 14 15 4
  46.  endof
  47.  endcase
  48.  ""
  49.  16 do
  50.   board$ fetch 1 mid$ swap$ +$
  51.  loop
  52.  board$ store
  53. enddef
  54.  
  55. define getmove ( -- move )
  56.  "12345678" 27 chr$ +$
  57.  begin inkey$ len instr * 
  58.   dup if dup drop$ endif drop$
  59.  until
  60. enddef
  61.  
  62. cls
  63. randomize
  64. 1 10 locate "Shuffling..." print$
  65. 10 do display 8 random move loop
  66. 1 10 locate "Use the keys" print$
  67. 2 10 locate "1-8 to put the" print$
  68. 3 10 locate "puzzle back into" print$
  69. 4 10 locate "alphabetical order." print$
  70. 5 10 locate "Press [ESC] to exit." print$
  71. begin
  72.  display
  73.  getmove
  74.  dup 9 = if bye
  75.          else move endif
  76. 0 until
  77.