效果图:下载地址:链接:https://pan.baidu.com/s/14rrZujpQbfs-9HMw_lL-3Q?pwd=1234
提取码:1234
源代码:只有120行
Imports System.Math
Public Class Form1
Dim Booms As New List(Of Point)
Dim MyBooms As New List(Of Point)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Flow1.Height = Flow1.Width
For i = 0 To 16 * 16 - 1
Dim but As New Button
but.Name = "but" & i
but.Tag = New Point(i Mod 16, i \ 16)
but.BackColor = Color.LightBlue
but.Font = New Font(but.Font.FontFamily, 20, but.Font.Style)
but.Location = New Point(but.Tag.X * 52, but.Tag.y * 52)
but.Size = New Size(Flow1.Width / 16, Flow1.Height / 16)
AddHandler but.Click, AddressOf But_Click
AddHandler but.MouseDown, AddressOf But_MouseDown
AddHandler but.MouseUp, AddressOf But_MouseUp
Flow1.Controls.Add(but)
Next
Dim Line As New List(Of Integer)
For i = 1 To 40
H: Dim s = New Random().Next(0, 255)
Threading.Thread.Sleep(1)
s = Abs(New Random().Next(0, 24) - s)
If Line.Contains(s) Then
GoTo H
End If
Line.Add(Abs(s))
Next
For i = 0 To 39
Booms.Add(New Point(Line(i) Mod 16, Line(i) \ 16))
Next
End Sub
Sub But_Click(sender As Object, e As EventArgs)
If Booms.Contains(sender.tag) Then
If sender.text <> "-1" Then
MsgBox("Boom!")
End If
Else
If sender.text = "-1" Then
Exit Sub
End If
sender.text = 0
sender.backcolor = Color.LightGray
Dim P0 = sender.tag
Dim Round As New List(Of Point)
With Round
.Add(New Point(P0.x - 1, P0.y - 1))
.Add(New Point(P0.x, P0.y - 1))
.Add(New Point(P0.x + 1, P0.y - 1))
.Add(New Point(P0.x - 1, P0.y))
.Add(New Point(P0.x + 1, P0.y))
.Add(New Point(P0.x - 1, P0.y + 1))
.Add(New Point(P0.x, P0.y + 1))
.Add(New Point(P0.x + 1, P0.y + 1))
End With
For Each boom In Booms
If Round.Contains(boom) Then
sender.text += 1
End If
Next
If sender.text = 0 Then
For Each but In Flow1.Controls
If Round.Contains(but.tag) And but.text = "" Then
but.PerformClick
End If
Next
End If
End If
End Sub
Sub But_MouseDown(sender As Object, e As MouseEventArgs)
If e.Button = MouseButtons.Right Then
If sender.text = "-1" Then
sender.text = ""
sender.backcolor = Flow1.BackColor
ElseIf sender.text = "" Then
sender.text = -1
sender.backcolor = Color.Red
Else
Dim P0 = sender.tag
Dim Pt = sender.text
Dim Round As New List(Of Point)
With Round
.Add(New Point(P0.x - 1, P0.y - 1))
.Add(New Point(P0.x, P0.y - 1))
.Add(New Point(P0.x + 1, P0.y - 1))
.Add(New Point(P0.x - 1, P0.y))
.Add(New Point(P0.x + 1, P0.y))
.Add(New Point(P0.x - 1, P0.y + 1))
.Add(New Point(P0.x, P0.y + 1))
.Add(New Point(P0.x + 1, P0.y + 1))
End With
Dim BoomCount As Integer
For Each but In Flow1.Controls
If Round.Contains(but.tag) And but.text = "-1" Then
BoomCount += 1
End If
Next
If Pt = BoomCount Then
For Each but In Flow1.Controls
If Round.Contains(but.tag) Then
but.performclick
End If
Next
End If
End If
End If
End Sub
Sub But_MouseUp(sender As Object, e As MouseEventArgs)
Dim i As Integer
For Each but In Flow1.Controls
If but.text <> "" And but.text <> "-1" And Not Booms.Contains(but.tag) Then
i += 1
End If
Next
If i = 16 * 16 - 40 Then
MsgBox("你赢了!")
End If
End Sub
End Class