'===========================================================================
' Subject: SLIDING PUZZLE                     Date: 05-04-96 (12:00)       
'  Author: Michael Stein                      Code: QB, QBasic, PDS        
'  Origin: www.nerc.com/~dstein/bas/        Packet: GAMES.ABC
'===========================================================================
'
'
'
'------------------------------Sliding Puzzle------------------------------------
'
'by Michael Stein     Email:dstein@nerc1.nerc.com
'
'Remeber those little toys that have numbers on them and you have to slide the
'numbers around to get them in the right order?  This is similar to that.
'On the main menu, choose 1 to Quit, 2 to Play, and 3 to CHange Diffuculty.
'On the difficulty, 1 is easiest, and 10 is hardest.  Try to get the numbers
'in this order:
'1 2 3
'4 5 6
'7 8 9
'
'If you do, a screen will pop up that says 'YOU WIN!!!'.
'The harder the diffuculty, the longer the puzzle takes to load up.
'-----------------------------------------------------------------------------
'P.S. This program is ShareWare.  Please give this to your friends and family.
'Please Email me at the adress above to tell me how you liked the program.
'
'Thanx,
'Michael Stein


'The actual program begins here.  Press the F5 key to start!

CLS
SCREEN 12
DIM sp(9)
CLS
diff = 1
mainmenu:
CLS
PRINT "Sliding Puzzle!!!! by Mike Stein"
PRINT "Choose:"
PRINT "1-Quit"
PRINT "2-Play"
PRINT "3-Change diffuculty"
PRINT "Diffuculty-"; diff
DO
a$ = INKEY$
LOOP WHILE a$ = ""
IF a$ = "1" THEN SYSTEM
IF a$ = "2" THEN GOTO ready
IF a$ = "3" THEN
LET diff = diff + 1
IF diff = 11 THEN LET diff = 1
END IF
GOTO mainmenu
ready:
FOR y = 1 TO 8
LET sp(y) = y
NEXT y
LET sp(9) = 9
PRINT "Loading puzzle... Please wait....."
PRINT "GET READY.....";
difff = diff * 165
FOR d = 1 TO difff
IF d = (difff \ 5) THEN PRINT "5";
IF d = ((difff \ 5) * 2) THEN PRINT "4";
IF d = ((difff \ 5) * 3) THEN PRINT "3";
IF d = ((difff \ 5) * 4) THEN PRINT "2";
IF d = difff THEN PRINT "1"
RANDOMIZE TIMER
    x = INT(RND * 4) + 1
IF x = 1 THEN LET y$ = "2"
IF x = 2 THEN LET y$ = "4"
IF x = 3 THEN LET y$ = "6"
IF x = 4 THEN LET y$ = "8"
FOR s = 1 TO 9
IF sp(s) = 9 THEN LET gas = s
NEXT s
IF y$ = "4" THEN
IF gas = 3 OR gas = 6 OR gas = 9 THEN GOTO ffjku
LET pot = gas + 1
SWAP sp(pot), sp(gas)
ffjku:
END IF
IF y$ = "6" THEN
IF gas = 1 OR gas = 4 OR gas = 7 THEN GOTO ffjkuu
LET pot = gas - 1
SWAP sp(pot), sp(gas)
ffjkuu:
END IF
IF y$ = "8" THEN
IF gas = 7 OR gas = 8 OR gas = 9 THEN GOTO ffjkuuu
LET pot = gas + 3
SWAP sp(pot), sp(gas)
END IF
ffjkuuu:
IF y$ = "2" THEN
IF gas = 1 OR gas = 2 OR gas = 3 THEN GOTO ffjjkuu
LET pot = gas - 3
SWAP sp(pot), sp(gas)
ffjjkuu:
END IF
NEXT d
PRINT "Press a key."
DO
LOOP WHILE INKEY$ = ""
CLS



playing:
CLS
SCREEN 12
LINE (150, 100)-(450, 350), 2, B
LINE (150, 183)-(450, 183), 2
LINE (150, 266)-(450, 266), 2
LINE (250, 100)-(250, 350), 2
LINE (350, 100)-(350, 350), 2
LOCATE 9, 24
IF sp(1) < 9 THEN PRINT sp(1) ELSE LOCATE 9, 24: PRINT " "
LOCATE 9, 37
IF sp(2) < 9 THEN PRINT sp(2)
LOCATE 9, 50
IF sp(3) < 9 THEN PRINT sp(3)
LOCATE 14, 24
IF sp(4) < 9 THEN PRINT sp(4)
LOCATE 14, 37
IF sp(5) < 9 THEN PRINT sp(5)
LOCATE 14, 50
IF sp(6) < 9 THEN PRINT sp(6)
LOCATE 19, 24
IF sp(7) < 9 THEN PRINT sp(7)
LOCATE 19, 37
IF sp(8) < 9 THEN PRINT sp(8)
LOCATE 19, 50
IF sp(9) < 9 THEN PRINT sp(9)
FOR t = 1 TO 8
IF sp(t) = t THEN LET prt = prt + 1
NEXT t
IF prt = 8 THEN GOTO winner
prt = 0
DO
y$ = INKEY$
LOOP WHILE y$ = ""
IF y$ = CHR$(27) THEN GOTO mainmenu
FOR s = 1 TO 9
IF sp(s) = 9 THEN LET gas = s
NEXT s
IF y$ = "4" THEN
IF gas = 3 OR gas = 6 OR gas = 9 THEN GOTO fjku
LET pot = gas + 1
SWAP sp(pot), sp(gas)
fjku:
END IF
IF y$ = "6" THEN
IF gas = 1 OR gas = 4 OR gas = 7 THEN GOTO fjkuu
LET pot = gas - 1
SWAP sp(pot), sp(gas)
fjkuu:
END IF
IF y$ = "8" THEN
IF gas = 7 OR gas = 8 OR gas = 9 THEN GOTO fjkuuu
LET pot = gas + 3
SWAP sp(pot), sp(gas)
END IF
fjkuuu:
IF y$ = "2" THEN
IF gas = 1 OR gas = 2 OR gas = 3 THEN GOTO fjjkuu
LET pot = gas - 3
SWAP sp(pot), sp(gas)
fjjkuu:
END IF
GOTO playing
winner:
CLS
PRINT "You WON!!!!"
PRINT "Press a key."
DO: LOOP WHILE INKEY$ = ""
CLS
GOTO mainmenu
