Sub Check
If Array.GetItemCount(box) = 81 Then
complete = "True"
' vertical check
For col = 1 To 9
found = ""
For row = 1 To 9
n = (row - 1) * 9 + col
found[box[n]] = "True"
EndFor
If Array.GetItemCount(found) < 9 Then
complete = "False"
col = 9 ' exit For
EndIf
EndFor
If complete Then
' horizontal check
For row = 1 To 9
found = ""
For col = 1 To 9
n = (row - 1) * 9 + col
found[box[n]] = "True"
EndFor
If Array.GetItemCount(found) < 9 Then
complete = "False"
row = 9 ' exit For
EndIf
EndFor
EndIf
If complete Then
' block check
For row1 = 1 To 7 Step 3
For col1 = 1 To 7 Step 3
found = ""
For row = row1 To row1 + 2
For col = col1 To col1 + 2
n = (row - 1) * 9 + col
found[box[n]] = "True"
EndFor
EndFor
If Array.GetItemCount(found) < 9 Then
complete = "False"
row1 = 7 ' exit For
col1 = 7 ' exit For
EndIf
EndFor
EndFor
EndIf
If complete Then
GraphicsWindow.BrushColor = "#66000000"
GraphicsWindow.PenWidth = 0
Shapes.AddRectangle(650, 490)
GraphicsWindow.BrushColor = "#66FFFFFF"
GraphicsWindow.FontSize = 80
comp = Shapes.AddText("COMPLETED!")
Shapes.Move(comp, 80, 170)
Timer.Pause()
EndIf
EndIf
EndSub
Sub DrawBox
' param col, row - selected box
x = 22 + (col - 1) * 40
y = 22 + (row - 1) * 40
GraphicsWindow.BrushColor = bc
GraphicsWindow.FillRectangle(x + 3, y + 3, 34, 34)
GraphicsWindow.FontSize = 25
GraphicsWindow.BrushColor = fc
GraphicsWindow.DrawText(x + 10, y + 6, box[n])
EndSub
Sub DrawGrid
pw = Math.Floor(GraphicsWindow.PenWidth / 2)
x1 = param["x"]
dx = param["size"]
x2 = x1 + param["nx"] * dx
y1 = param["y"]
dy = param["size"]
y2 = x1 + param["ny"] * dy
For x = x1 To x2 Step dx
GraphicsWindow.DrawLine(x, y1 - pw, x, y2 + pw)
EndFor
For y = y1 To y2 Step dy
GraphicsWindow.DrawLine(x1 - pw, y, x2 + pw, y)
EndFor
If "False" And (num = "") Then
n = 1
GraphicsWindow.FontSize = 12
GraphicsWindow.BrushColor = "Blue"
For y = y1 To y2 - dy Step dy
For x = x1 To x2 - dx Step dx
num = Shapes.AddText(n)
Shapes.Move(num, x + 3, y + 3)
n = n + 1
EndFor
EndFor
EndIf
EndSub
Sub Form
GraphicsWindow.BackgroundColor = bg[1]["c"]
GraphicsWindow.Width = 640
GraphicsWindow.Height = 480
GraphicsWindow.Title = "Small Basic Sudoku"
GraphicsWindow.CanResize = "False"
GraphicsWindow.Show()
bc = "White"
GraphicsWindow.BrushColor = bc
GraphicsWindow.FillRectangle(20, 20, 360, 360)
CreateGrid()
Sub GridColor
For gcLoop = 1 to 9
If (xpos > gc[gcLoop]["x"] And xpos < gc[gcLoop]["x"] + 20) Then
If (ypos > gc[gcLoop]["y"] And ypos < gc[gcLoop]["y"] + 20) Then
bc = gc[gcLoop]["c"]
GraphicsWindow.BrushColor = bc
GraphicsWindow.FillRectangle(20, 20, 360, 360)
CreateGrid()
Redraw()
endif
EndIf
endfor
Endsub
' sudoku answer
'box = "3=4;4=9;5=1;8=8;14=3;18=9;19=8;20=3;25=1;30=8;36=7;38=9;39=1;40=3;44=6;45=4;47=6;49=4;50=7;52=9;55=9;61=5;62=7;65=7;69=1;72=6;74=1;77=5;78=9;79=3;81=8;1=6;2=5;6=2;7=7;9=3;10=1;11=2;12=7;13=8;15=4;16=6;17=5;21=9;22=5;23=6;24=7;26=4;27=2;28=5;29=4;31=1;32=9;33=6;34=2;35=3;37=7;41=2;42=5;43=8;46=2;48=3;51=8;53=1;54=5;56=8;57=2;58=6;59=4;60=3;63=1;64=3;66=5;67=2;68=8;70=4;71=9;73=4;75=6;76=7;"
index = Array.GetAllIndices(fixed)
n = Array.GetItemCount(fixed)
For i = 1 To n
box[index[i]] = fixed[index[i]]
EndFor
EndSub
Sub OnKeyDown
key = GraphicsWindow.LastKey
If (0 < col) And (0 < row) Then
n = (row - 1) * 9 + col
Shapes.Remove(frame)
If Array.ContainsValue(number, key) Then
len = Text.GetLength(key)
box[n] = Text.GetSubText(key, len, 1)
DrawBox()
Check()
ElseIf (key = "Delete" Or key = "Space") Then
'Delete number in box
box[n] = ""
DrawBox()
EndIf
col = -1
row = -1
EndIf
EndSub
Sub OnMouseDown
xpos = GraphicsWindow.MouseX
ypos = GraphicsWindow.MouseY
if (xpos > 420 and xpos < 528) And (ypos > 60 And ypos< 160) then
SetBackground()
endif
If (xpos > 420 And xpos < 528) And (ypos > 215 And ypos < 316) then
GridColor()
endif
If (xpos > 297 And xpos < 381) And (ypos > 417 And ypos < 471) then
StartTimer()
endif
If (22 <= xpos) And (xpos < 382) And (22 <= ypos) And (ypos < 382) then
SelectBox()
Else
Shapes.Remove(frame)
col = -1
row = -1
Endif
Endsub
Sub Redraw
index = Array.GetAllIndices(box)
_n = Array.GetItemCount(box)
For i = 1 To _n
n = index[i]
col = Math.Remainder((n - 1), 9) + 1
row = Math.Floor((n - 1) / 9) + 1
If Array.ContainsIndex(fixed, n) Then
fc = "DimGray"
Else
fc = "Black"
EndIf
DrawBox()
EndFor
fc = "Black"
EndSub
Sub SetBackground
For bgLoop = 1 to 9
If (xpos > bg[bgLoop]["x"] And xpos < bg[bgLoop]["x"] + 20) Then
If (ypos > bg[bgLoop]["y"] And ypos < bg[bgLoop]["y"] + 20) Then
GraphicsWindow.BackgroundColor = bg[bgLoop]["c"]
EndIf
EndIf
EndFor
EndSub
Sub SelectBox
' Select the box
col = Math.Floor((xpos - 22) / 40) + 1
row = Math.Floor((ypos - 22) / 40) + 1
n = (row - 1) * 9 + col
Shapes.Remove(frame)
If Array.ContainsIndex(fixed, n) Then
col = -1
row = -1
Else
x = 22 + (col - 1) * 40
y = 22 + (row - 1) * 40
GraphicsWindow.PenWidth = 2
GraphicsWindow.PenColor = "Blue"
GraphicsWindow.BrushColor = "Transparent"
frame = Shapes.AddRectangle(38, 38)
Shapes.Move(frame, x + 1, y + 1)
EndIf
EndSub
Sub StartTimer
' Start the Timer
If (xpos > 297 And xpos < (297 + 84)) Then
If (ypos > 444 And ypos < (444 + 27)) Then
Timer.Tick = OnTick
GraphicsWindow.BrushColor = "GainsBoro"
GraphicsWindow.FillRectangle(299, 446, 80, 25)
EndIf
Endif
If (xpos > 297 And xpos < (297 + 42)) Then
If (ypos > 417 And ypos < (417 + 27)) Then
Timer.Pause()
EndIf
Endif
If (xpos > 339 And xpos < (339 + 84)) Then
If (ypos > 417 And ypos < (417 + 27)) Then
Timer.Resume()
EndIf
EndIf
EndSub