home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 5
/
ctrom5b.zip
/
ctrom5b
/
PROGRAM
/
DIVERSEN
/
TIPI2A
/
PPUZZLE.TPI
< prev
next >
Wrap
Text File
|
1994-09-10
|
2KB
|
93 lines
# PPUZZLE.TPI
# by Kent Peterson 10/30/93
defstr board$
"ABCDEFGHIJKLMNOP" board$ store
defvar counter
0 counter store
define display
0 0 locate
" 1|" print$
board$ fetch dup$ 4 left$ print$ cr
" 2|" print$
dup$ 5 4 mid$ print$ cr
" 3|" print$
dup$ 9 4 mid$ print$ cr
" 4|" print$
4 right$ print$ cr
| -+----
| |5678
enddef
define move ( n -- )
# Changes the board in one of 8 ways
case 1 of
2 3 4 1 5 6 7 8 9 10 11 12 13 14 15 16
endof
2 of
1 2 3 4 6 7 8 5 9 10 11 12 13 14 15 16
endof
3 of
1 2 3 4 5 6 7 8 10 11 12 9 13 14 15 16
endof
4 of
1 2 3 4 5 6 7 8 9 10 11 12 14 15 16 13
endof
5 of
5 2 3 4 9 6 7 8 13 10 11 12 1 14 15 16
endof
6 of
1 6 3 4 5 10 7 8 9 14 11 12 13 2 15 16
endof
7 of
1 2 7 4 5 6 11 8 9 10 15 12 13 14 3 16
endof
8 of
1 2 3 8 5 6 7 12 9 10 11 16 13 14 15 4
endof
endcase
""
16 do
board$ fetch 1 mid$ swap$ +$
loop
board$ store
enddef
define getmove ( -- move )
"12345678" 27 chr$ +$
begin inkey$ len instr *
dup if dup drop$ endif drop$
until
enddef
define checkforwin
counter fetch dup 1 + counter store
1 30 locate print | moves
board$ fetch "ABCDEFGHIJKLMNOP" =$
if 2 30 locate | You win!
begin key until
8 0 locate 1 cursor bye
endif
enddef
cls
0 cursor
randomize
1 10 locate | Shuffling...
10 do display 8 random move loop
1 10 locate | Use the keys
2 10 locate | 1-8 to put the
3 10 locate | puzzle back into
4 10 locate | alphabetical order.
5 10 locate | Press [ESC] to exit.
begin
display
checkforwin
getmove
dup 9 = if 8 0 locate
1 cursor bye
else move endif
0 until