Microsoft Small Basic
Program Listing:
Embed this in your website
<object id='sbapp' data='data:application/x-silverlight-2,' type='application/x-silverlight-2' width='640' height='480'> <param name='source' value='http://smallbasic.com/program/ClientBin/SBWeb.xap'/> <param name='onError' value='onSilverlightError' /> <param name='background' value='white' /> <param name='minRuntimeVersion' value='3.0.40624.0' /> <param name='autoUpgrade' value='true' /> <param name='initParams' value='programId=NMH162-1' /> </object>
Titel
=
" Color Memory Game"
ScreenInit
(
)
BeforeOrAfter
(
)
ColourInit
(
)
points
=
0
life
=
3
ca
=
3
cp
=
0
tp
=
600
B
[
102
]
=
Controls
.
AddButton
(
" Start "
,
300
,
(
ww
/
2
)
-
100
)
GraphicsWindow
.
DrawText
(
30
,
30
,
"Please click the colour in the correct order!"
)
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
Titel
=
points
Titel
=
Text
.
Append
(
Titel
,
" Points"
)
BeforeOrAfter
(
)
Titel
=
" END"
BeforeOrAfter
(
)
Program
.
Delay
(
600
)
Program
.
End
(
)
'----------------------------------------------------------------------------------------
Sub
BeforeOrAfter
GraphicsWindow
.
FontName
=
"Courier"
For
i
=
1
to
20
SH
[
i
]
=
" "
endfor
For
i
=
1
To
Text
.
GetLength
(
Titel
)
SH
[
i
]
=
Shapes
.
AddText
(
Text
.
GetSubText
(
Titel
,
i
,
1
)
)
Shapes
.
HideShape
(
SH
[
i
]
)
Shapes
.
Zoom
(
sh
[
i
]
,
4
,
4
)
EndFor
Program
.
Delay
(
1000
)
sl
=
Array
.
GetItemCount
(
SH
)
For
i
=
1
To
sl
y
=
GraphicsWindow
.
Height
/
2
-
100
x
=
i
*
40
-
40
Shapes
.
ShowShape
(
SH
[
i
]
)
Shapes
.
Animate
(
SH
[
i
]
,
x
,
y
,
1200
)
GraphicsWindow
.
BackgroundColor
=
"Moccasin"
Program
.
Delay
(
200
)
EndFor
program
.
Delay
(
2000
)
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
(
1500
)
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
(
1500
)
EndFor
For
i
=
1
To
sl
x
=
i
*
50
-
40
y
=
GraphicsWindow
.
Height
/
2
-
100
Shapes
.
Animate
(
SH
[
i
]
,
x
,
y
,
1200
)
EndFor
Program
.
Delay
(
1200
)
For
i
=
sl
To
1
Step
-
1
Shapes
.
HideShape
(
SH
[
i
]
)
Program
.
Delay
(
300
)
EndFor
GraphicsWindow
.
FontName
=
"Arial"
EndSub
''BeforeOrAfter
Sub
ScreenInit
ww
=
900
wh
=
600
Controls
.
ButtonClicked
=
OnButtonClicked
GraphicsWindow
.
Top
=
0
GraphicsWindow
.
Left
=
0
GraphicsWindow
.
Width
=
ww
GraphicsWindow
.
Height
=
wh
GraphicsWindow
.
Title
=
Titel
GraphicsWindow
.
BrushColor
=
"SteelBlue"
GraphicsWindow
.
PenColor
=
"Black"
GraphicsWindow
.
BackgroundColor
=
"Moccasin"
GraphicsWindow
.
FontBold
=
"True"
GraphicsWindow
.
FontName
=
"Arial"
GraphicsWindow
.
FontSize
=
14
GraphicsWindow
.
Show
(
)
EndSub
'ScreenInit
Sub
ColourInit
C
[
1
]
=
"White"
C
[
2
]
=
"Gray"
C
[
3
]
=
"Yellow"
C
[
4
]
=
"Orange"
C
[
5
]
=
"Red"
C
[
6
]
=
"Green"
C
[
7
]
=
"Violet"
C
[
8
]
=
"Blue"
C
[
9
]
=
"Black"
EndSub
'ColourInit
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
*
60
)
-
60
B
[
i
]
=
Controls
.
AddButton
(
C
[
i
]
,
p
,
500
)
Controls
.
HideControl
(
B
[
i
]
)
EndFor
B
[
100
]
=
Controls
.
AddButton
(
" CONTINUE "
,
200
,
500
)
Controls
.
HideControl
(
B
[
100
]
)
B
[
101
]
=
Controls
.
AddButton
(
" E N D "
,
300
,
500
)
Controls
.
HideControl
(
B
[
101
]
)
GraphicsWindow
.
BrushColor
=
"Moccasin"
GraphicsWindow
.
FillRectangle
(
0
,
580
,
500
,
20
)
GraphicsWindow
.
BrushColor
=
"SteelBlue"
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
EndSub
'NewColour
Sub
ShowColour
For
i
=
1
to
ca
GraphicsWindow
.
BrushColor
=
C
[
RC
[
i
]
]
ShowIt
(
)
Program
.
Delay
(
tp
)
GraphicsWindow
.
BrushColor
=
"Moccasin"
GraphicsWindow
.
FillRectangle
(
0
,
0
,
ww
,
wh
-
100
)
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
MidleIt
(
)
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
MidleIt
(
)
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
MidleIt
(
)
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
MidleIt
(
)
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
GraphicsWindow
.
FillTriangle
(
x1
,
y1
,
x2
,
y2
,
x3
,
y3
)
midleTri
(
)
EndIf
EndSub
'ShowIt
Sub
MidleIt
dif
=
(
ww
-
x1
-
x2
-
100
)
/
2
x1
=
x1
+
dif
x2
=
x2
+
dif
dif
=
(
wh
-
y1
-
y2
-
150
)
/
2
y1
=
y1
+
dif
y2
=
y2
+
dif
EndSub
'MidleIt
Sub
MidleTri
If
x1
>
x2
Then
If
x1
>
x3
Then
If
x2
>
x3
Then
difx
=
(
ww
-
x1
-
x2
-
100
)
/
2
Else
difx
=
(
ww
-
x1
-
x3
-
100
)
/
2
EndIf
Else
difx
=
(
ww
-
x1
-
x3
-
100
)
/
2
EndIf
Else
difx
=
(
ww
-
x2
-
x3
-
100
)
/
2
Endif
x1
=
x1
+
difx
x2
=
x2
+
difx
x3
=
x3
+
difx
If
y1
>
y2
Then
If
y1
>
y3
Then
If
y2
>
y3
Then
dify
=
(
ww
-
y1
-
y2
-
100
)
/
2
Else
dify
=
(
ww
-
y1
-
y3
-
100
)
/
2
EndIf
Else
dify
=
(
ww
-
y1
-
y3
-
100
)
/
2
EndIf
Else
dify
=
(
ww
-
y2
-
y3
-
100
)
/
2
Endif
y1
=
y1
+
dify
y2
=
y2
+
dify
y3
=
y3
+
dify
EndSub
'MidleTri
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
If
A
[
an
]
=
B
[
101
]
Then
Program
.
End
(
)
EndIf
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
OnButtonClicked
an
=
an
+
1
A
[
an
]
=
Controls
.
LastClickedButton
If
Controls
.
LastClickedButton
=
B
[
102
]
Then
A
[
an
]
=
B
[
100
]
EndIf
EndSub
'OnButtonClicked
Copyright (c) Microsoft Corporation. All rights reserved.