Microsoft Small Basic

Program Listing: SNM509
GraphicsWindow.Title = "Dots-And-Lines/Game"
GraphicsWindow.Width = 800
GraphicsWindow.Height = 600
GraphicsWindow.CanResize = "False"
GraphicsWindow.Top = 0
GraphicsWindow.Left = 0
TextWindow.Top = 0
TextWindow.Left = 850
TextWindow.Hide()
'GraphicsWindow.BrushColor = "red"
gh = GraphicsWindow.Height
gw = GraphicsWindow.Width
score1 = 0
score2 = 0
color = 1
lines = 0



'gw = 200
'gh = 200


menu()


sub menu
GraphicsWindow.Clear()
mainbg = ImageList.LoadImage(Program.Directory + "/pics/mainbg.jpg")
GraphicsWindow.DrawResizedImage(mainbg, 0, 0, gw, gh)


start = Controls.AddButton("Let's begin", gw/2-150, gh/5+30)
'instr = Controls.AddButton("Instruction", gw/2-150, 2*gh/5+30)
'credit = Controls.AddButton("Credits", gw/2-150, 3*gh/5+30)


exit = Controls.AddButton("Exit", gw/2-150, 4*gh/5-300)

Controls.ButtonClicked = handleButton
EndSub

Sub handleButton
Controls.Remove(start)
' Controls.Remove(instr)
' Controls.Remove(credit)
Controls.Remove(exit)
b = Controls.LastClickedButton

If(b = exit) Then
Program.End()
'ElseIf(b = instr) then
'elseIf(b = credit) then
elseif (b = p1dec or b = p1inc or b = p2dec or b = p2inc) then
changeScore()
elseif (b = back) then
menu()
Else

main()
EndIf
EndSub

Sub main
GraphicsWindow.Clear()
score2Shape = Shapes.AddText("Player 2: "+score2)
Shapes.Move(score2shape, 650, 10)

score1Shape = Shapes.AddText("Player 1: "+score1)
Shapes.Move(score1Shape, 250, 10)


p1inc = Controls.AddButton(">>>", 350, 10)
p1dec = Controls.AddButton("<<<", 200, 10)
p2inc = Controls.AddButton(">>>", 750, 10)
p2dec = Controls.AddButton("<<<", 600, 10)
back = Controls.AddButton("<==", 50, 570)
For i=50 To gw - 10 Step 50
For j=50 To gh - 10 Step 50
dot = Shapes.AddEllipse(10, 10)
Shapes.Move(dot, i, j)

EndFor
EndFor

startover:
GraphicsWindow.MouseDown = handleMouse
EndSub

Sub handleMouse

x = GraphicsWindow.MouseX
y = GraphicsWindow.MouseY

If (x > 50 And x< gw-50 and y> 50 And y< gh-50) Then


areaX = Math.Floor((x)/50)
x1 = areaX*50 + 5
X2 = x1 + 50

areaY = Math.Floor((y)/50)
y1 = areaY*50 + 5
y2 = y1 + 50


If (Math.Remainder(y, 50) = 5) Then
Shapes.AddLine(x1, y, X2,y)
EndIf

If (Math.Remainder(x, 50) = 5) Then
Shapes.AddLine(x, y1, x,y2)
EndIf

' TextWindow.WriteLine("areaX = " + areaX+ " areaY = "+ areaY)

'AREA 1
If ((y-y1 < ((y1 - y2)/(X2 - x1))*(x-x2)) And (y-y1 < ((y1 - y2)/(X1 - x2))*(x-x1))) And (y > y1) Then

Array[areaX+1][areaY+1] = 1
' TextWindow.WriteLine("array["+(areaX+1)+"]["+(areaY+1)+"] = 1")

'TextWindow.WriteLine("upline")
color = 1 - color
lines = lines + 1
Sound.PlayClick()
If(color = 0) then
GraphicsWindow.BrushColor = "red"
Else
GraphicsWindow.BrushColor = "black"
EndIf
Shapes.AddLine(x1, y1, X2,y1)

'AREA 2
ElseIf (((y-y1 < ((y1 - y2)/(X2 - x1))*(x-x2)) And (y-y1 > ((y1 - y2)/(X1 - x2))*(x-x1))) And (x > x1)) then

Array[areaX-1][areaY+1] = 1
' TextWindow.WriteLine("array["+(areaX-1)+"]["+(areaY+1)+"] = 1")
lines = lines + 1
color = 1 - color
Sound.PlayClick()
If(color = 0) then
GraphicsWindow.BrushColor = "red"
Else
GraphicsWindow.BrushColor = "black"
EndIf
Shapes.AddLine(x1, y1, X1,y2)

'AREA 3
ElseIf (((y-y1 > ((y1 - y2)/(X2 - x1))*(x-x2)) And (y-y1 > ((y1 - y2)/(X1 - x2))*(x-x1))) And (y < y2)) then
lines = lines + 1
Array[areaX+1][areaY+2] = 1
' TextWindow.WriteLine("array["+(areaX+1)+"]["+(areaY+2)+"] = 1")

color = 1 - color
Sound.PlayClick()
If(color = 0) then
GraphicsWindow.BrushColor = "red"
Else
GraphicsWindow.BrushColor = "black"
EndIf
Shapes.AddLine(x1, y2, X2,y2)

'AREA 4
ElseIf (((y-y1 > ((y1 - y2)/(X2 - x1))*(x-x2)) And (y-y1 < ((y1 - y2)/(X1 - x2))*(x-x1))) And (x < x2)) then
lines = lines + 1

Array[areaX][areaY+1] = 1
' TextWindow.WriteLine("array["+(areaX)+"]["+(areaY+1)+"] = 1")
color = 1 - color
Sound.PlayClick()
If(color = 0) then
GraphicsWindow.BrushColor = "red"
Else
GraphicsWindow.BrushColor = "black"
EndIf
Shapes.AddLine(x2, y1, X2,y2)


EndIf
EndIf



EndSub

'
Sub changeScore
GraphicsWindow.BrushColor = "black"

b = Controls.LastClickedButton
Sound.PlayClick()
If (b = p1dec) Then
score1 = score1 - 1
Shapes.Remove(score1Shape)
score1Shape = Shapes.AddText("Player 1: "+score1)
Shapes.Move(score1Shape, 250, 10)
ElseIf (b = p1inc) Then
score1 = score1 + 1
Shapes.Remove(score1Shape)
score1Shape = Shapes.AddText("Player 1: "+score1)
Shapes.Move(score1Shape, 250, 10)
ElseIf (b = p2dec) Then
score2 = score2 - 1
Shapes.Remove(score2Shape)
score2Shape = Shapes.AddText("Player 2: "+score2)
Shapes.Move(score2Shape, 650, 10)

Else
score2 = score2 + 1
Shapes.Remove(score2Shape)
score2Shape = Shapes.AddText("Player 2: "+score2)
Shapes.Move(score2Shape, 650, 10)


EndIf

EndSub