Microsoft Small Basic

Program Listing: VRZ081-0
' Solitaire Marbles Game
' Version 0.2
' Copyright © 2016 Nonki Takahashi. The MIT License.
' Last update 2016-03-18
' Program ID VRZ081-0
'
GraphicsWindow.Title = "Solitaire Marbles Game 0.2"
gw = 600
gh = 600
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
InitBoard()
img = ImageList.LoadImage(folder + "/Marble.png")
n = 0
For row = 1 To 7
y = y1 + (row - 1) * size * 2
For col = 1 To 7
x = x1 + (col - 1) * size * 2
If board[row][col] Then
n = n + 1
shp[n] = Shapes.AddImage(img)
Shapes.Move(shp[n], x - size / 2, y - size / 2)
r[n] = row
c[n] = col
EndIf
EndFor
EndFor
GraphicsWindow.MouseDown = OnMouseDown
While "True"
If mouseDown Then
If 0 < picked Then
y = y1 + (r[picked] - 1) * size * 2
x = x1 + (c[picked] - 1) * size * 2
Shapes.Move(shp[picked], x - size / 2, y - size / 2)
picked = 0
Else
CheckPicked()
If 0 < picked Then
y = y1 + (r[picked] - 1) * size * 2
x = x1 + (c[picked] - 1) * size * 2
Shapes.Move(shp[picked], x - size / 2, y - size * 0.7)
EndIf
EndIf
mouseDown = "False"
Else
Program.Delay(200)
EndIf
EndWhile
Sub CheckPicked
For i = 1 To n
y = y1 + (r[i] - 1) * size * 2
x = x1 + (c[i] - 1) * size * 2
ox = x - mx ' offset
oy = y - my
d = Math.SquareRoot(ox * ox + oy * oy)
If d < size / 2 Then
picked = i
i = n ' break
EndIf
EndFor
EndSub
Sub OnMouseDown
mx = GraphicsWindow.MouseX
my = GraphicsWindow.MouseY
mouseDown = "True"
EndSub
Sub InitBoard
b[1] = "XX@@@XX"
b[2] = "X@@@@@X"
b[3] = "@@@@@@@"
b[4] = "@@@ @@@"
b[5] = "@@@@@@@"
b[6] = "X@@@@@X"
b[7] = "XX@@@XX"
For row = 1 To 7
For col = 1 To 7
c = Text.GetSubText(b[row], col, 1)
If c = "@" Then
board[row][col] = "True"
ElseIf c = " " Then
board[row][col] = "False"
ElseIf c = "X" Then
board[row][col] = "OB"
EndIf
EndFor
EndFor
folder = "http://www.nonkit.com/smallbasic.files"
GraphicsWindow.DrawImage(folder + "/SolitaireMarblesGameBoard.png", 0, 0)
size = 30 ' ball size
xc = gw / 2
yc = gh / 2
x1 = xc - 6 * size
y1 = xc - 6 * size
EndSub