Dots and Lines (Developed using Small Basic)

A Dots and Lines Game developed using Microsoft Small Basic. This time I didn’t spend much time on the program,. So the program might not be free of bugs. For example a simple bug that it has is that you should click next to each line to draw the line (not exactly on the line),

A Dots and Lines Game developed using Microsoft Small Basic. This time I didn't spend much time on the program,. So the program might not be free of bugs. For example a simple bug that it has is that you should click next to each line to draw the line (not exactly on the line), otherwise it won't draw a new line. 

This game can be played with a firend. The program does not automatically declare a winner, and scores can be changed manually by players (so watch out that your opponent doesn't cheat in the game!!!!)

-------------------------------------------------------

Challenges that I had while developing this game:

I had to divide each square into 4 triangular sections. then based on where the user clicks on the screen the program finds out in which of the 4 triangular sections the user has clicked. To accomplish this the program finds the equations for lines that create those 4 triangles, and accordingly decides where to draw each line. Look at the Small Basic code for line equations.

 

Like always don't expecpt to get a very amazing game. This was done by an intermediate programmer for learning purposes.

Here is the code in Small Basic language:

 

Visual Basic
Edit|Remove
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, 00, 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-1504*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, 65010) 
 
score1Shape = Shapes.AddText("Player 1: "+score1) 
Shapes.Move(score1Shape, 25010) 
 
 
p1inc = Controls.AddButton(">>>"35010) 
p1dec = Controls.AddButton("<<<"20010) 
p2inc = Controls.AddButton(">>>"75010) 
p2dec = Controls.AddButton("<<<"60010) 
back = Controls.AddButton("<=="50570For i=50 To gw - 10 Step 50 
  For j=50 To gh - 10 Step 50 
    dot = Shapes.AddEllipse(1010) 
    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-50Then 
 
 
  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) = 5Then 
      Shapes.AddLine(x1, y, X2,y) 
    EndIf 
 
  If (Math.Remainder(x, 50) = 5Then 
      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, 25010) 
  ElseIf (b = p1inc) Then 
    score1 = score1 + 1 
    Shapes.Remove(score1Shape) 
    score1Shape = Shapes.AddText("Player 1: "+score1) 
    Shapes.Move(score1Shape, 25010) 
  ElseIf (b = p2dec) Then 
    score2 = score2 - 1 
    Shapes.Remove(score2Shape) 
    score2Shape = Shapes.AddText("Player 2: "+score2) 
    Shapes.Move(score2Shape, 65010) 
 
Else 
    score2 = score2 + 1 
    Shapes.Remove(score2Shape) 
    score2Shape = Shapes.AddText("Player 2: "+score2) 
    Shapes.Move(score2Shape, 65010) 
 
 
  EndIf 
 
EndSub
 
</DIV>