本文主要是介绍vb.net极简版扫雷16*16,40雷源代码,仅供学习和参考,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
效果图:下载地址:链接:https://pan.baidu.com/s/14rrZujpQbfs-9HMw_lL-3Q?pwd=1234
提取码:1234
源代码:只有120行
Imports System.Math
Public Class Form1Dim 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.LoadFlow1.Height = Flow1.WidthFor i = 0 To 16 * 16 - 1Dim but As New Buttonbut.Name = "but" & ibut.Tag = New Point(i Mod 16, i \ 16)but.BackColor = Color.LightBluebut.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_ClickAddHandler but.MouseDown, AddressOf But_MouseDownAddHandler but.MouseUp, AddressOf But_MouseUpFlow1.Controls.Add(but)NextDim 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) ThenGoTo HEnd IfLine.Add(Abs(s))NextFor i = 0 To 39Booms.Add(New Point(Line(i) Mod 16, Line(i) \ 16))NextEnd SubSub But_Click(sender As Object, e As EventArgs)If Booms.Contains(sender.tag) ThenIf sender.text <> "-1" ThenMsgBox("Boom!")End IfElseIf sender.text = "-1" ThenExit SubEnd Ifsender.text = 0sender.backcolor = Color.LightGrayDim P0 = sender.tagDim 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 WithFor Each boom In BoomsIf Round.Contains(boom) Thensender.text += 1End IfNextIf sender.text = 0 ThenFor Each but In Flow1.ControlsIf Round.Contains(but.tag) And but.text = "" Thenbut.PerformClickEnd IfNextEnd IfEnd IfEnd SubSub But_MouseDown(sender As Object, e As MouseEventArgs)If e.Button = MouseButtons.Right ThenIf sender.text = "-1" Thensender.text = ""sender.backcolor = Flow1.BackColorElseIf sender.text = "" Thensender.text = -1sender.backcolor = Color.RedElseDim P0 = sender.tagDim Pt = sender.textDim 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 WithDim BoomCount As IntegerFor Each but In Flow1.ControlsIf Round.Contains(but.tag) And but.text = "-1" ThenBoomCount += 1End IfNextIf Pt = BoomCount ThenFor Each but In Flow1.ControlsIf Round.Contains(but.tag) Thenbut.performclickEnd IfNextEnd IfEnd IfEnd IfEnd SubSub But_MouseUp(sender As Object, e As MouseEventArgs)Dim i As IntegerFor Each but In Flow1.ControlsIf but.text <> "" And but.text <> "-1" And Not Booms.Contains(but.tag) Theni += 1End IfNextIf i = 16 * 16 - 40 ThenMsgBox("你赢了!")End IfEnd Sub
End Class
这篇关于vb.net极简版扫雷16*16,40雷源代码,仅供学习和参考的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!