Microsoft Small Basic

Program Listing: LSM678-0
' Connect Four 0.2a
' Clone version written by Nonki Takahashi
'
' History:
' 0.2a 2013-11-10 Modified as demo version. (LSM678-0)
' 0.1a 2013-11-07 Created as alpha version. (LSM678)
'
gw = 640
gh = 480
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.Title = "Connect Four 0.2a"
dx = 90
dy = 80
InitDisks()
InitBoard()
'DrawGrid()
a2col = "A=1;B=2;C=3;D=4;E=5;F=6;G=7;"
rec = "1=D;2=D;3=E;4=C;5=C;6=D;7=F;8=G;9=F;"
For i = 1 To Array.GetItemCount(rec)
col = a2col[rec[i]]
DropDisk()
EndFor
Sub InitDisks
color = "1=Gold;2=Red;"
GraphicsWindow.PenWidth = 0
For i = 1 To 42
GraphicsWindow.BrushColor = color[Math.Remainder(i - 1, 2) + 1]
disk[i] = Shapes.AddEllipse(dy, dy)
Shapes.Move(disk[i], 0, -100)
EndFor
EndSub
Sub InitBoard
For i = 1 To 42
board[i] = 0
EndFor
url = "http://www.nonkit.com/smallbasic.files/Connect4Board.png"
Shapes.AddImage(url)
EndSub
Sub DropDisk
' param i - disk index
' param col - column number 1..7
' return succeed - "True" if succeed
succeed = "False"
x = (col - 1) * dx + 10
ms = 500
For row = 6 To 1 Step -1
If board[(row - 1) * 7 + col] = 0 Then
Shapes.Move(disk[i], x, -100)
y = (row - 1) * dy + 5
Shapes.Animate(disk[i], x, y, ms)
Program.Delay(ms)
Sound.PlayClick()
board[(row - 1) * 7 + col] = Math.Remainder(i - 1, 2) + 1
succeed = "True"
Goto break
EndIf
EndFor
break:
EndSub