Microsoft Small Basic

Program Listing: ZJL122
Titel = "Color Memory Game" 'Titel of the Game
InitWindow() 'initializise the window and show it
InitColour() 'initializise the color
BeforeOrAfter() 'show the titel with effect
' The following line could be harmful and has been automatically commented.
' fp = File.GetSettingsFilePath()
For i = Text.GetLength(fp) to 1 step - 1
If Text.GetSubText(fp, i , 1) = "\" Then
pos = i
i = 1
EndIf
EndFor
fp = Text.GetSubText(fp,1,pos)
fp = fp + "Color Memory Game HIGHSCORE.ARR"
ReadHighScore()
If HC = "" then
For i = 1 to 10
HC[i] = " ********** 0"
EndFor
EndIf
ShowHighscore()
points = 0
life = 3
ca = 3 '
cp = 0
tp = 600
B[100] = Controls.AddButton(" CONTINUE ", (ww/3) - 50, wh - 70)
Controls.HideControl(B[100])
B[101] = Controls.AddButton(" E N D ", 2*(ww/3) - 50, wh - 70)
Controls.HideControl(B[101])
B[102] = Controls.AddButton(" Start ", (ww/2) - 50, wh - 70)
B[200] = Controls.AddTextBox(ww/2 - 50, 12*40)
Controls.HideControl(B[200])
loop = 1
While loop = 1
GraphicsWindow.BrushColor = C[Math.GetRandomNumber(9)]
Titel = "Please click the colour in the correct order!"
GraphicsWindow.DrawText((ww-text.GetLength(Titel))/2-150, wh-100, Titel)
GraphicsWindow.BrushColor = "Moccasin"
GraphicsWindow.FillRectangle(0,wh-20,ww,20)
GraphicsWindow.BrushColor = "SteelBlue"
ShowPoints = "Points: "
ShowPoints = Text.Append(ShowPoints, points)
GraphicsWindow.DrawText(0,wh-20,ShowPoints)
ShowLife = "Life: "
ShowLife = Text.Append(ShowLife, life)
GraphicsWindow.DrawText(200,wh-20,ShowLife)
While A[an] <> B[102]
EndWhile
Controls.HideControl(B[102])
While A[an] <> B[101]
Init()
NewColour()
ShowColour()
Wait4Answer()
ShowResult()
If life < 1 Then
A[an] = B[101]
EndIf
EndWhile
Highscore()
Controls.ShowControl(B[102])
points = 0
life = 3
ca = 3 '
cp = 0
tp = 600
EndWhile

'----------------------------------------------------------------------------------------

Sub InitWindow
ww = 970 ' window white pixel
wh = 600 'window high pixel
Controls.ButtonClicked = OnButtonClicked 'Event of ButtonClicked
GraphicsWindow.KeyUp = OnKeyUp 'Event of KeyUp
GraphicsWindow.Top = 0 'show window in the first line of the screen
GraphicsWindow.Left = 0 'show windor in the first row of the screen
GraphicsWindow.Width = ww 'set the white of the window
GraphicsWindow.Height = wh 'set the high of the window
GraphicsWindow.Title = Titel 'set the title of the game
GraphicsWindow.BrushColor = "SteelBlue" 'set the bruschcolor steelblue
GraphicsWindow.PenColor = "Black" 'set the pencolor black
GraphicsWindow.BackgroundColor = "Moccasin"'set the backgroundcolor moccasin
GraphicsWindow.FontBold = "True" 'set the fontbold
GraphicsWindow.FontName = "Arial" 'set the fontname arial
GraphicsWindow.FontSize = 14 'set the fontsizw 14
GraphicsWindow.Show() 'show the window
EndSub 'InitWindow

Sub InitColour
C[1] = "Snow"
C[2] = "Gray"
C[3] = "Yellow"
C[4] = "DarkOrange"
C[5] = "Red"
C[6] = "Seagreen"
C[7] = "Purple"
C[8] = "Blue"
C[9] = "Black"

Col[1] = " White "
Col[2] = " Gray "
Col[3] = " Yellow "
Col[4] = " Orange "
Col[5] = " Red "
Col[6] = " Green "
Col[7] = " Violet "
Col[8] = " Blue "
Col[9] = " Black "

EndSub 'InitColour

Sub BeforeOrAfter
'Clear old title
For i = 1 to 30
SH[i] = " "
endfor
'Set new title
For i = 1 To Text.GetLength(Titel)
co = co + 1
If co = 10 Then
co = 1
EndIf
GraphicsWindow.BrushColor = C[co]
SH[i] = Shapes.AddText(Text.GetSubText(Titel,i,1))
Shapes.HideShape(SH[i])
Shapes.Zoom(sh[i], 4, 4)
EndFor
sl = Array.GetItemCount(SH)
For i = 1 To sl
y = wh / 2 - 100
x = i * 40 - 40
Shapes.ShowShape(SH[i])
Shapes.Animate(SH[i], x, y, 1500)
GraphicsWindow.BackgroundColor = "Moccasin"
Program.Delay(400)
EndFor
program.Delay(400)
For j = 1 to 2
For i = 1 To sl
x = i * 50 - 40
If Math.Remainder(i, 2) = 0 Then
y = GraphicsWindow.Height / 2 - 100 + 30
Else
y = GraphicsWindow.Height / 2 - 100 - 30
EndIf
Shapes.Animate(SH[i], x, y, 1500)
EndFor
Program.Delay(500)
For i = 1 To sl
x = i * 50 - 40
If Math.Remainder(i, 2) = 0 Then
y = GraphicsWindow.Height / 2 - 100 - 30
Else
y = GraphicsWindow.Height / 2 - 100 + 30
EndIf
Shapes.Animate(SH[i], x, y, 1500)
EndFor
Program.Delay(500)
EndFor
For i = 1 To sl
x = i * 50 - 40
y = GraphicsWindow.Height / 2 - 100
Shapes.Animate(SH[i], x, y, 1500)
EndFor
Program.Delay(200)
For i = sl To 1 Step - 1
Shapes.HideShape(SH[i])
Program.Delay(100)
EndFor
GraphicsWindow.BrushColor = "SteelBlue"
EndSub ''BeforeOrAfter

Sub Init
an = 0
cp = cp + 1
If Math.Remainder(cp, 3) = 0 Then
tp = tp - 10
If tp < 200 then
tp = 200
EndIf
ca = ca + 1
EndIf
For i = 1 to 9
p = (i * 80) - 80
GraphicsWindow.BrushColor = C[i]
B[i] = Controls.AddButton(Col[i], p,wh - 70)
Controls.HideControl(B[i])
EndFor
GraphicsWindow.BrushColor = "Moccasin"
GraphicsWindow.BrushColor = "Moccasin"
GraphicsWindow.FillRectangle(0,0,ww,wh-100)
GraphicsWindow.BrushColor = "SteelBlue"
GraphicsWindow.BrushColor = "Black"
Zeig = "Points: "
Zeig = Text.Append(zeig, points)
GraphicsWindow.DrawText(0,580,zeig)
EndSub 'Init

Sub NewColour
For i = 1 to ca
RC[i] = Math.GetRandomNumber(9)
If ca < 5 Then
Controls.ShowControl(B[RC[i]])
EndIf
EndFor
If ca >= 5 Then
For i = 1 to 9
Controls.ShowControl(B[i])
EndFor
endif
GraphicsWindow.BrushColor = "Moccasin"
GraphicsWindow.BrushColor = "Moccasin"
GraphicsWindow.FillRectangle(0,0,ww,wh-100)
GraphicsWindow.BrushColor = "SteelBlue"
GraphicsWindow.BrushColor = "Black"
EndSub 'NewColour

Sub ShowColour
For i = 1 to ca
GraphicsWindow.BrushColor = C[RC[i]]
ShowIt()
Program.Delay(tp)
GraphicsWindow.BrushColor = "Moccasin"
GraphicsWindow.BrushColor = "Moccasin"
GraphicsWindow.FillRectangle(0,0,ww,wh-100)
GraphicsWindow.BrushColor = "SteelBlue"
GraphicsWindow.BrushColor = "Black"
Program.Delay(tp)
EndFor
GraphicsWindow.BrushColor = "SteelBlue"
EndSub 'ShowColour

Sub ShowIt
g = Math.GetRandomNumber(5)
If g = 1 Then
x1 = Math.GetRandomNumber(100)
y1 = Math.GetRandomNumber(100)
x2 = Math.GetRandomNumber(100) + 250
y2 = X2
x1 = (ww - x2) / 2
y1 = (wh - y2) / 2
GraphicsWindow.FillRectangle(x1,y1,x2,y2)
ElseIf g = 2 Then
x1 = Math.GetRandomNumber(100)
y1 = Math.GetRandomNumber(100)
x2 = Math.GetRandomNumber(100) + 250
y2 = Math.GetRandomNumber(100) + 250
x1 = (ww - x2) / 2
y1 = (wh - y2) / 2
GraphicsWindow.FillRectangle(x1,y1,x2,y2)
ElseIf g = 3 Then
x1 = Math.GetRandomNumber(100)
y1 = Math.GetRandomNumber(100)
x2 = Math.GetRandomNumber(100) + 250
y2 = x2
x1 = (ww - x2) / 2
y1 = (wh - y2) / 2
GraphicsWindow.FillEllipse(x1,y1,x2,y2)
ElseIf g = 4 Then
x1 = Math.GetRandomNumber(100)
y1 = Math.GetRandomNumber(100)
x2 = Math.GetRandomNumber(100) + 250
y2 = Math.GetRandomNumber(100) + 250
x1 = (ww - x2) / 2
y1 = (wh - y2) / 2
GraphicsWindow.FillEllipse(x1,y1,x2,y2)
Else
x1 = Math.GetRandomNumber(100)
y1 = Math.GetRandomNumber(100) + 200
x2 = Math.GetRandomNumber(100) + 250
y2 = Math.GetRandomNumber(100) + 100
x3 = y2
y3 = x2
x1 = (ww - x2) / 2
y1 = (wh - y2) / 2
GraphicsWindow.FillTriangle(x1,y1,x2,y2,x3,y3)
EndIf
EndSub 'ShowIt

Sub Wait4Answer
an = 0
While an < ca
EndWhile
EndSub 'Wait4Answer

Sub ShowResult
For i = 1 to 9
Controls.HideControl(B[i])
EndFor
For i = 1 to ca
Zeig = i
Zeig = Text.Append(Zeig, ". ")
Zeig = Text.Append(Zeig, C[RC[i]])
If B[RC[i]] = A[i] Then
Zeig = Text.Append(Zeig, " correct ")
points = points + 10
Else
Zeig = Text.Append(Zeig, " incorrect ")
points = points - 15
life = life - 1
EndIf
p = i * 24
GraphicsWindow.DrawText(1, p, Zeig)
ShowPandL()
EndFor
Controls.ShowControl(B[100])
Controls.ShowControl(B[101])
an = 0
While an = 0
EndWhile
Controls.HideControl (B[100])
Controls.HideControl (B[101])
GraphicsWindow.BrushColor = "Moccasin"
GraphicsWindow.FillRectangle(0,0,ww,wh-100)
GraphicsWindow.BrushColor = "SteelBlue"
EndSub 'ShowResult

Sub ShowPandL
If points < 0 Then
points = 0
EndIf
If life < 0 Then
life = 0
EndIf
GraphicsWindow.BrushColor = "Moccasin"
GraphicsWindow.FillRectangle(0,wh-20,ww,20)
GraphicsWindow.BrushColor = "SteelBlue"
ShowPoints = "Points: "
ShowPoints = Text.Append(ShowPoints, points)
GraphicsWindow.DrawText(0,wh-20,ShowPoints)
ShowLife = "Life: "
ShowLife = Text.Append(ShowLife, life)
GraphicsWindow.DrawText(200,wh-20,ShowLife)
EndSub

Sub Highscore
If points > 0 Then
ShowHighscore()
GraphicsWindow.DrawText(ww/2 - 150, 12 * 40, "Your name ENTER")
Controls.ShowControl(B[200])
LK = ""
While LK <> "Return"
if LKP = 1 Then
LKP = 0
LK = GraphicsWindow.LastKey
EndIf
EndWhile
LK = ""
Controls.HideControl(B[200])
yn = Controls.GetTextBoxText(B[200])
lenyn = Text.GetLength(yn)
While lenyn <> 10
If lenyn > 10 Then
yn = Text.GetSubText(yn,1,10)
lenyn = Text.GetLength(yn)
Else
yn = yn + " "
lenyn = lenyn + 1
EndIf
EndWhile

lenp = Text.GetLength(points)
Fpoints = points
For i = 1 To 15 - lenp
Fpoints = " " + Fpoints
EndFor
NewHC = yn + " " + Fpoints
For i = 1 To 10
HCPoints = Text.GetSubText(HC[i],14,15)
If points > HCPoints Then
NI = i
i = 10
EndIf
EndFor
For i = 10 To NI Step -1
HC[i+1] = HC[i]
EndFor
HC[NI] = NewHC
EndIf
ShowHighscore()
Program.Delay(2000)
SaveHighScore()
EndSub 'Highscore

Sub ShowHighscore
GraphicsWindow.BrushColor = "Moccasin"
GraphicsWindow.BrushColor = "Moccasin"
GraphicsWindow.FillRectangle(0,0,ww,wh-100)
GraphicsWindow.BrushColor = "SteelBlue"
GraphicsWindow.PenColor = "Black"
GraphicsWindow.DrawText(ww/2 - 90, 10, "H I G H S C O R E")
For i = 1 To 10
GraphicsWindow.DrawText(ww/2 - 100, i * 40, HC[i])
Program.Delay(100)
EndFor
EndSub ' ShowHighscore

Sub ReadHighScore
' The following line could be harmful and has been automatically commented.
' HC = File.ReadContents(fp)
EndSub 'ReadHighScore

Sub SaveHighScore
' The following line could be harmful and has been automatically commented.
' File.WriteContents(fp, HC)
EndSub 'SaveHighScore

Sub OnButtonClicked
an = an + 1
A[an] = Controls.LastClickedButton
EndSub 'OnButtonClicked

Sub OnKeyUp
LKP = 1
EndSub 'OnKeyUp