Microsoft Small Basic

Program Listing: DMR183
'
'@@ CREATE BACKING SCREEN AND TITLE @@
GraphicsWindow.Width = 1024
GraphicsWindow.Height = 768
GraphicsWindow.Title = "TILEPUZ"
GraphicsWindow.Left = (Desktop.Width - 1024) / 2
GraphicsWindow.Top = (Desktop.Height - 768) / 2
GraphicsWindow.BackgroundColor = "GREEN"
GraphicsWindow.FontSize = 100
GraphicsWindow.BrushColor = "WHITE"
GraphicsWindow.FillEllipse(230,25,560,130)
GraphicsWindow.BrushColor = "DARKRED"
GraphicsWindow.DrawText(290,30,"TILEPUZ")
'@@@ CREATE TILES @@@
GraphicsWindow.BrushColor = "ORANGE"
For I = 1 To 27
TILE[I] = Shapes.AddRectangle(100,100)
Shapes.Move(TILE[I],0,-150)
EndFor
ALPHA = "ABCDEFGHIJKLM NOPQRSTUVWXYZ"
GraphicsWindow.FontName = "KAITI"
GraphicsWindow.BrushColor = "WHITE"
GraphicsWindow.FontSize = 100
For I = 1 To 27
LETT[I] = Shapes.AddText(Text.GetSubText(ALPHA,I,1))
LETT2[I] = Text.GetSubText(ALPHA,I,1)
Shapes.Move(LETT[I],0,-150)
EndFor
A = 1
For I = 220 To 420 Step 100
For J = 60 To 860 Step 100
X[A] = J
Y[A] = I
A = A + 1
EndFor
EndFor
'@@ CREATE PLAYBOARD @@
GraphicsWindow.BrushColor = "DARKRED"
GraphicsWindow.FillRectangle(X[1]-20,Y[1]-20,940,340)
GraphicsWindow.BrushColor = "BLACK"
GraphicsWindow.FillRectangle(X[1]-10,Y[1]-10,920,320)
GraphicsWindow.BrushColor = "DARKGRAY"
GraphicsWindow.FillRectangle(X[1],Y[1],900,300)

For I = 1 To 27
If I <> 14 Then
Shapes.Move(TILE[I],X[I],Y[I])
Shapes.Move(LETT[I],X[I]+20,Y[I]-10)
EndIf
EndFor
' @@@@@@@@@@@@@@@
GraphicsWindow.MouseDown = MOUSEDOWN
INSTRUCTIONS()
'@@ START OR RESTART NEW PUZZLE @@
RESTART()
SUB RESTART
NUMBERFOUND = 0
GOVERNER = 0
GraphicsWindow.FontSize = 100
ALPHA2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
For I = 1 To 27
LETTB[I] = Text.GetSubText(ALPHA,I,1)
EndFor
For I = 1 TO 200
A = Math.GetRandomNumber(27)
If A <> 14 Then
DUMMY = LETTB[A]
LETTB[A] = LETTB[1]
LETTB[1] = DUMMY
EndIf
EndFor
GraphicsWindow.BrushColor = "BLACK"
For I = 1 To 27
GraphicsWindow.DrawText(X[I]+20,Y[I]-10,LETTB[I])
EndFor
GraphicsWindow.FontSize = 50
GraphicsWindow.DrawText(185,550,"PHASE 1 - CAPTURE LETTERS")
GraphicsWindow.DrawText(170,620,ALPHA2)
ENDSUB
'@@ MOUSE CONTROL @@
Sub MOUSEDOWN
If (Mouse.IsRightButtonDown) THEN
INSTRUCTIONS()
Goto NEXT1
ENDIF
X1 = GraphicsWindow.MouseX
Y1 = GraphicsWindow.MouseY
If X1 < 60 Or X1 >959 Or Y1 < 220 Or Y1 > 519 Or GOVERNER = 1 Then
Goto NEXT1
EndIf
SN1 = Math.Ceiling((X1 - 59)/100)
SN2 = Math.Ceiling(((Y1 - 219)/100)-1)
SN = SN2*9+SN1

'MOVE UP
IF LETT2[SN-9] = " " Then
GOVERNER = 1
LETT2[SN-9] = LETT2[SN]
LETT2[SN] = " "
For I = Y[SN] To Y[SN-9] Step -0.1
Shapes.Move(LETT[SN],X[SN]+20,I-10)
Shapes.Move(TILE[SN],X[SN],I)
EndFor
DUMMY = LETT[SN]
LETT[SN] = LETT[SN-9]
LETT[SN-9] = DUMMY
DUMMY = TILE[SN]
TILE[SN] = TILE[SN-9]
TILE[SN-9] = DUMMY
SN = SN - 9
If NUMBERFOUND < 26 THEN
PHASE1()
ELSE
PHASE2()
ENDIF
Goto NEXT1
EndIf
'MOVE DOWN
IF LETT2[SN+9] = " " Then
GOVERNER = 1
LETT2[SN+9] = LETT2[SN]
LETT2[SN] = " "
For I = Y[SN] To Y[SN+9] Step 0.1
Shapes.Move(LETT[SN],X[SN]+20,I-10)
Shapes.Move(TILE[SN],X[SN],I)
EndFor
DUMMY = LETT[SN]
LETT[SN] = LETT[SN+9]
LETT[SN+9] = DUMMY
DUMMY = TILE[SN]
TILE[SN] = TILE[SN+9]
TILE[SN+9] = DUMMY
SN = SN + 9
If NUMBERFOUND < 26 THEN
PHASE1()
ELSE
PHASE2()
ENDIF
Goto NEXT1
EndIf
'MOVE LEFT
IF LETT2[SN-1] = " " and X1 > 160 Then
GOVERNER = 1
LETT2[SN-1] = LETT2[SN]
LETT2[SN] = " "
For I = X[SN] To X[SN-1] Step -0.1
Shapes.Move(LETT[SN],I+20,Y[SN]-10)
Shapes.Move(TILE[SN],I,Y[SN])
EndFor
DUMMY = LETT[SN]
LETT[SN] = LETT[SN-1]
LETT[SN-1] = DUMMY
DUMMY = TILE[SN]
TILE[SN] = TILE[SN-1]
TILE[SN-1] = DUMMY
SN = SN - 1
If NUMBERFOUND < 26 THEN
PHASE1()
ELSE
PHASE2()
ENDIF
Goto NEXT1
EndIf
'MOVE RIGHT
IF LETT2[SN+1] = " " And X1 < 860 Then
GOVERNER = 1
LETT2[SN+1] = LETT2[SN]
LETT2[SN] = " "
For I = X[SN] To X[SN+1] Step 0.1
Shapes.Move(LETT[SN],I+20,Y[SN]-10)
Shapes.Move(TILE[SN],I,Y[SN])
EndFor
DUMMY = LETT[SN]
LETT[SN] = LETT[SN+1]
LETT[SN+1] = DUMMY
DUMMY = TILE[SN]
TILE[SN] = TILE[SN+1]
TILE[SN+1] = DUMMY
SN = SN + 1
If NUMBERFOUND < 26 THEN
PHASE1()
ELSE
PHASE2()
ENDIF
EndIf
NEXT1:
GOVERNER = 0
EndSub
'@@ PHASE 1 : CHECK FOR LETTER CAPTURE @@
Sub PHASE1
If LETT2[SN] = LETTB[SN] Then
A = Text.GetIndexOf(ALPHA2,LETT2[SN])-1
LETTB[SN] = ""
NUMBERFOUND = NUMBERFOUND + 1
GraphicsWindow.PenColor = "RED"
GraphicsWindow.DrawRectangle(170 + (A*26),623,25,51)
GraphicsWindow.BrushColor = "DARKGRAY"
GraphicsWindow.FillRectangle(X[SN],Y[SN],100,100)
If NUMBERFOUND = 26 Then
GraphicsWindow.BrushColor = "GREEN"
GraphicsWindow.FillRectangle(165,550,710,150)
GraphicsWindow.BrushColor = "BLACK"
GraphicsWindow.DrawText(185,550,"PHASE 2 - RETURN ALL TILES")
GraphicsWindow.DrawText(185,620,"TO THEIR STARTING POSITION")
EndIf
EndIf
EndSub
'@@ PHASE 2 : CHECK FOR ALL TILES REPLACED @@
Sub PHASE2
A = ""
For I = 1 To 27
A = Text.Append(A,LETT2[I])
EndFor
If A = ALPHA Then
GraphicsWindow.BrushColor = "GREEN"
GraphicsWindow.FillRectangle(165,550,710,150)
GraphicsWindow.ShowMessage("Leaving this message box will automatically start a new puzzle with hidden letters randomly placed. To quit exit this message box then click the quit button at the top right of the screen. Whatever your decision, thank you for playing.","THE PUZZLE IS SOLVED - WELL DONE !")
RESTART()
EndIf
EndSub
'@@ INSTRUCTIONS @@
Sub INSTRUCTIONS
GraphicsWindow.ShowMessage("Welcome to TILEPUZ - a tile puzzle with a difference. The playboard has two layers. An upper layer of moveable tiles individually marked with letters of the alphabet and a lower layer of the alphabet randomly placed. The lower level can only be viewed through the space between the tiles. PHASE 1 : The object of phase 1 is to capture all of the hidden letters on the lower level. This is achieved by placing it's identical lettered tile on top of it. Just mouse left click on the tile you want to move into the space to discover where the hidden letters reside. PHASE 2: Simply return all of the tiles to the position they were in at the start. These instuctions will appear whenever you right click the mouse.","TILEPUZ - INSTRUCTIONS")
EndSub
'@@ PROGAM WITH THE COMPLIMENTS OF KEN COOKSEY @@