' ------------------------------------------
' Game..
' Put the numbers in order
' ------------------------------------------
bf$    = "<SPAN STYLE='font-family:arial; font-weight:700; font-size:20pt'>"
call SetCSS
 
dim xBox(16)
' -------------------------------------
' Fill the boxes with numbers 1 to 15
' -------------------------------------
for i = 1 to 15
xBox(i)    = i
next i
 
' -----------------------------------
' Randomally select a box to be open
' The open box has the number 0
' -----------------------------------
x         = int(rnd(1)*15) + 1
xBox(x)        = 0
xBox(16)    = x
 
' ----------------------------------
' The boxes are in order by 1 to 15
' Here we shuffle the boxes to make
' the boxes random
' ----------------------------------
numShuffles    = 2
for     i     = 1 to 16 * numShuffles
    i1    = int(rnd(1)*16) + 1
    i2    = int(rnd(1)*16) + 1
    hold    = xBox(i1)
    xBox(i1)= xBox(i2)
    xBox(i2)= hold
next i
 
 
' ----------------------------------
' find the open box (0) and call it
' the openBox
' ----------------------------------
for i = 1 to 16
if xBox(i) = 0 then openBox = i
next i
 
' ---------------------------------------
' The main loop
' ---------------------------------------
[loop]
 
' ----------------------------------------
' Find the row and column of the openBox
' ----------------------------------------
openRow    = int((openBox -1) / 4) + 1
openCol    = ((openBox - 1) mod 4) + 1
 
cls
' --------------------------------------
' Number Puzzle
' Goal - place numbers in order
' --------------------------------------
html bf$;"<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=6 width=320 height=240 bgcolor=yellow>"
thisBox = 0
for thisRow = 1 to 4
    html "<TR align=center>"
    for thisCol = 1 to 4
        thisBox    = thisBox + 1
        if thisBox = openBox then
            html "<TD bgcolor=white></TD>"    ' open box
        else
            html "<TD BGCOLOR=lightblue width=25%>"
 
            ' -------------------------------------------------
            ' This determines if this box's row and col is next
            ' to the open box's row and col
            ' If it is then display it as a link
            ' -------------------------------------------------
            xRow    = abs(thisRow - openRow)
            xCol    = abs(thisCol - openCol)
            if xRow + xCol = 1 then
            link    #movBox,str$(xBox(thisBox)),[doMov]
                #movBox cssclass("sBtn")
                #movBox setkey(thisBox)
            else
                html xBox(thisBox)
            end if
        html "</TD>"
        end if
    next thisCol
    html "</TR>"
next thisRow
html "</TABLE>"
wait
 
' -------------------------------------
' Move the users selected box
' -------------------------------------
[doMov]
thisBox     = val(EventKey$)
hold        = xBox(openBox)
xBox(openBox)    = xBox(thisBox)
xBox(thisBox)    = hold
openBox        = thisBox
 
' -------------------------------
' See if the numbers are in order
' If so - they are a winner
' -------------------------------
youWin        = 1
for i = 1 to 15
if xBox(i) <> i then youWin = 0
next i
if youWin = 1 then
    print "Horray! You Win"
    wait
end if
 
goto [loop]
wait
 
' ----------------------------
' CSS
' ----------------------------
SUB SetCSS
CSSClass "a.sBtn", "{
Border-Width:6px; Border-Color:lightGreen; Border-Style:solid; background:lightGreen;
Font-Size:20pt; Font-Weight:Bold; Font-Family:Arial; color:black;Text-Decoration:None;
}"
 END SUB