Public Class Form1
Private iX As Integer
Private iY As Integer
Private count As Integer
Dim g As Graphics = Me.CreateGraphics
Private Sub MakeGo(ByVal x As Integer, ByVal y As Integer)
If count Mod 2 = 0 Then
count = count + 1
Dim rect As New Rectangle(x, y, 40, 45)
Dim circle_brush As New SolidBrush(Color.White)
g.FillEllipse(circle_brush, rect) '<<<
Dim circle_pen As New Pen(Color.White, 5)
g.DrawEllipse(circle_pen, rect) '<<<
Else
count = count + 1
Dim rect As New Rectangle(x, y, 40, 45)
Dim circle_brush As New SolidBrush(Color.Black)
g.FillEllipse(circle_brush, rect) '<<<
Dim circle_pen As New Pen(Color.Black, 5)
g.DrawEllipse(circle_pen, rect) '<<<
End If
End Sub
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
iX = e.X
iY = e.Y
'แถวที่ 1
If iX < 50 And iY > 0 And iY < 55 Then
MakeGo(10, 10)
ElseIf iX < 100 And iY > 0 And iY < 55 Then
MakeGo(60, 10)
ElseIf iX < 150 And iY > 0 And iY < 55 Then
MakeGo(110, 10)
ElseIf iX < 200 And iY > 0 And iY < 55 Then
MakeGo(160, 10)
ElseIf iX < 250 And iY > 0 And iY < 55 Then
MakeGo(210, 10)
End If
'แถวที่ 2
If iX < 50 And iY > 55 And iY < 110 Then
MakeGo(10, 65)
ElseIf iX < 100 And iY > 55 And iY < 110 Then
MakeGo(60, 65)
ElseIf iX < 150 And iY > 55 And iY < 110 Then
MakeGo(110, 65)
ElseIf iX < 200 And iY > 55 And iY < 110 Then
MakeGo(160, 65)
ElseIf iX < 250 And iY > 55 And iY < 110 Then
MakeGo(210, 65)
End If
'แถวที่ 3
If iX < 50 And iY > 110 And iY < 165 Then
MakeGo(10, 120)
ElseIf iX < 100 And iY > 110 And iY < 165 Then
MakeGo(60, 120)
ElseIf iX < 150 And iY > 110 And iY < 165 Then
MakeGo(110, 120)
ElseIf iX < 200 And iY > 110 And iY < 165 Then
MakeGo(160, 120)
ElseIf iX < 250 And iY > 110 And iY < 165 Then
MakeGo(210, 120)
End If
'แถวที่ 4
If iX < 50 And iY > 165 And iY < 215 Then
MakeGo(10, 175)
ElseIf iX < 100 And iY > 165 And iY < 215 Then
MakeGo(60, 175)
ElseIf iX < 150 And iY > 165 And iY < 215 Then
MakeGo(110, 175)
ElseIf iX < 200 And iY > 165 And iY < 215 Then
MakeGo(160, 175)
ElseIf iX < 250 And iY > 165 And iY < 215 Then
MakeGo(210, 175)
End If
'แถวที่ 5
If iX < 50 And iY > 215 And iY < 270 Then
MakeGo(10, 230)
ElseIf iX < 100 And iY > 215 And iY < 270 Then
MakeGo(60, 230)
ElseIf iX < 150 And iY > 215 And iY < 270 Then
MakeGo(110, 230)
ElseIf iX < 200 And iY > 215 And iY < 270 Then
MakeGo(160, 230)
ElseIf iX < 250 And iY > 215 And iY < 270 Then
MakeGo(210, 230)
End If
If count > 24 Then
MessageBox.Show("Total = " + count.ToString())
End If
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim rec1 As New Rectangle(5, 5, 50, 55)
Dim brownpen As New Pen(Color.White, 3)
g.DrawRectangle(brownpen, rec1)
Dim rec3 As New Rectangle(55, 5, 50, 55)
g.DrawRectangle(brownpen, rec3)
Dim rec4 As New Rectangle(105, 5, 50, 55)
g.DrawRectangle(brownpen, rec4)
Dim rec5 As New Rectangle(155, 5, 50, 55)
g.DrawRectangle(brownpen, rec5)
Dim rec6 As New Rectangle(205, 5, 50, 55)
g.DrawRectangle(brownpen, rec6)
Dim rec21 As New Rectangle(5, 60, 50, 55)
g.DrawRectangle(brownpen, rec21)
Dim rec22 As New Rectangle(55, 60, 50, 55)
g.DrawRectangle(brownpen, rec22)
Dim rec23 As New Rectangle(105, 60, 50, 55)
g.DrawRectangle(brownpen, rec23)
Dim rec24 As New Rectangle(155, 60, 50, 55)
g.DrawRectangle(brownpen, rec24)
Dim rec25 As New Rectangle(205, 60, 50, 55)
g.DrawRectangle(brownpen, rec25)
Dim rec31 As New Rectangle(5, 115, 50, 55)
g.DrawRectangle(brownpen, rec31)
Dim rec32 As New Rectangle(55, 115, 50, 55)
g.DrawRectangle(brownpen, rec32)
Dim rec33 As New Rectangle(105, 115, 50, 55)
g.DrawRectangle(brownpen, rec33)
Dim rec34 As New Rectangle(155, 115, 50, 55)
g.DrawRectangle(brownpen, rec34)
Dim rec35 As New Rectangle(205, 115, 50, 55)
g.DrawRectangle(brownpen, rec35)
Dim rec41 As New Rectangle(5, 170, 50, 55)
g.DrawRectangle(brownpen, rec41)
Dim rec42 As New Rectangle(55, 170, 50, 55)
g.DrawRectangle(brownpen, rec42)
Dim rec43 As New Rectangle(105, 170, 50, 55)
g.DrawRectangle(brownpen, rec43)
Dim rec44 As New Rectangle(155, 170, 50, 55)
g.DrawRectangle(brownpen, rec44)
Dim rec45 As New Rectangle(205, 170, 50, 55)
g.DrawRectangle(brownpen, rec45)
Dim rec51 As New Rectangle(5, 225, 50, 55)
g.DrawRectangle(brownpen, rec51)
Dim rec52 As New Rectangle(55, 225, 50, 55)
g.DrawRectangle(brownpen, rec52)
Dim rec53 As New Rectangle(105, 225, 50, 55)
g.DrawRectangle(brownpen, rec53)
Dim rec54 As New Rectangle(155, 225, 50, 55)
g.DrawRectangle(brownpen, rec54)
Dim rec55 As New Rectangle(205, 225, 50, 55)
g.DrawRectangle(brownpen, rec55)
End Sub
End Class
Tag : .NET, Win (Windows App), VB.NET, VS 2008 (.NET 3.x)
ต้องขอปรบมือไห้ก่อน algo สุดยอดมากครับ
ส่วนตรงห้ามคลิกซ้ำ ก็เพิ่มตัวแปร point ไว้เช็คครับ
Code (VB.NET)
Private _listPoint As New List(Of Point)
Private Sub MakeGo(ByVal x As Integer, ByVal y As Integer)
Dim p As New Point(x, y)
If _listPoint.Contains(p) Then
Exit Sub
Else
_listPoint.Add(p)
End If
If count Mod 2 = 0 Then
count = count + 1
Dim rect As New Rectangle(x, y, 40, 45)
Dim circle_brush As New SolidBrush(Color.White)
g.FillEllipse(circle_brush, rect) '<<<
Dim circle_pen As New Pen(Color.White, 5)
g.DrawEllipse(circle_pen, rect) '<<<
Else
count = count + 1
Dim rect As New Rectangle(x, y, 40, 45)
Dim circle_brush As New SolidBrush(Color.Black)
g.FillEllipse(circle_brush, rect) '<<<
Dim circle_pen As New Pen(Color.Black, 5)
g.DrawEllipse(circle_pen, rect) '<<<
End If
End Sub