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=hzg550' /> </object>
' Easy maze game 50Line program By NaochanON
' Use Right Left Up Down keys
GraphicsWindow
.
KeyDown
=
onkeydown
GUI
(
)
Sub
onkeydown
If
NN
<
starnumber
Then
xy0
=
"1="
+
Shapes
.
GetLeft
(
player
)
/
25
+
";2="
+
shapes
.
GetTop
(
player
)
/
25
' old position X, Y
KeyNo
=
text
.
GetCharactercode
(
GraphicsWindow
.
LastKey
)
' Right:82 Left:76 Up:85 Down:68
If
Math
.
Abs
(
(
KeyNo
-
79
)
/
3
)
=
1
Then
' Right or Left
dxy
=
"1="
+
(
KeyNo
-
79
)
/
3
+
";2=0"
' dxy[x]=1 or -1 dxy[y]=0
elseIf
Math
.
Abs
(
(
76.5
-
KeyNo
)
/
8.5
)
=
1
Then
' Up or Down
dxy
=
"1=0;2="
+
(
76.5
-
KeyNo
)
/
8.5
' dxy[x]=0 dxy[y]=1 or -1
endif
Xy1
=
"1="
+
(
Shapes
.
GetLeft
(
player
)
+
25
*
dxy
[
1
]
)
/
25
+
";2="
+
(
shapes
.
GetTop
(
player
)
+
25
*
dxy
[
2
]
)
/
25
' new position X,Y
if
list
[
Xy1
[
1
]
]
[
Xy1
[
2
]
]
=
4
Then
' 4= ■ check
Shapes
.
Move
(
player
,
25
*
xy0
[
1
]
,
25
*
xy0
[
2
]
)
' return old position
dxy
=
"1=0;2=0"
else
Shapes
.
Move
(
player
,
25
*
Xy1
[
1
]
,
25
*
Xy1
[
2
]
)
' move to new position
if
0
<
list
[
Xy1
[
1
]
]
[
Xy1
[
2
]
]
And
list
[
Xy1
[
1
]
]
[
Xy1
[
2
]
]
<
4
Then
' 1,2,3 ☆ ★ * check
Shapes
.
Remove
(
star
[
Xy1
[
1
]
]
[
Xy1
[
2
]
]
)
' erase star
list
[
Xy1
[
1
]
]
[
Xy1
[
2
]
]
=
0
' erase star list
NN
=
NN
+
1
' count gotten stars
EndIf
endif
GraphicsWindow
.
Title
=
"Elapsed time= "
+
Math
.
Floor
(
(
Clock
.
ElapsedMilliseconds
-
t0
)
/
100
)
/
10
+
" sec Stars gotten = "
+
NN
else
GraphicsWindow
.
DrawText
(
100
,
5
,
" Finished !!!!!!!!!!!!!! "
)
Sound
.
PlayBellRingAndWait
(
)
EndIf
EndSub
Sub
GUI
GraphicsWindow
.
FontSize
=
25
stars
=
"1=☆;2=★;3=*;4=■;5=・;6="
+
text
.
GetCharacter
(
2
*
16
*
16
*
16
+
6
*
16
*
16
+
12
*
16
+
4
)
' UTFcode=26C4
For
i
=
1
To
24
For
j
=
1
To
16
If
i
=
12
And
j
=
8
Then
else
list
[
i
]
[
j
]
=
math
.
Ceiling
(
5
-
Math
.
GetRandomNumber
(
4
)
/
Math
.
GetRandomNumber
(
10
)
)
' scatter stars
star
[
i
]
[
j
]
=
Shapes
.
AddText
(
stars
[
list
[
i
]
[
j
]
]
)
Shapes
.
Move
(
star
[
i
]
[
j
]
,
i
*
25
,
j
*
25
)
If
0
<
list
[
i
]
[
j
]
And
list
[
i
]
[
j
]
<
4
Then
' if star = 1=☆;2=★;3=*
StarNumber
=
StarNumber
+
1
EndIf
endif
EndFor
EndFor
GraphicsWindow
.
BrushColor
=
"red"
player
=
Shapes
.
AddText
(
stars
[
6
]
)
' Player
Shapes
.
Move
(
player
,
12
*
25
,
8
*
25
)
t0
=
clock
.
ElapsedMilliseconds
' start time
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.