⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.vb

📁 打地鼠游戏
💻 VB
字号:
Imports System.Drawing.Image
Imports System.Drawing
Imports System.Windows.Forms
Public Class Form1
    Dim bl As Boolean = True
    Dim bbl As Boolean = True
    Dim tm As Integer = 0
    Dim tmm As Integer = 0
    Dim i, j, k As Integer
    Dim m As Integer
    Dim getscor As Integer = 0
    Dim sumscor As Integer = 0
    Dim btn As Button
    Dim bt(35) As Button
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.SelectedItem = "键盘" Then
            For m = 0 To 25
                bt(m).Text = "&" & CStr(Chr(m + 97))
            Next
            For m = 26 To 35
                bt(m).Text = "&" & CStr(m - 26)
            Next
        End If
        If ComboBox1.SelectedItem = "鼠标" Then
            For m = 0 To 25
                bt(m).Text = ""
            Next
            For m = 26 To 35
                bt(m).Text = ""
            Next
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        bt(0) = Button1 : bt(1) = Button2 : bt(2) = Button3 : bt(3) = Button4 : bt(4) = Button5 : bt(5) = Button6
        bt(6) = Button7 : bt(7) = Button8 : bt(8) = Button9 : bt(9) = Button10 : bt(10) = Button11 : bt(11) = Button12
        bt(12) = Button13 : bt(13) = Button14 : bt(14) = Button15 : bt(15) = Button16 : bt(16) = Button17 : bt(17) = Button18
        bt(18) = Button19 : bt(19) = Button20 : bt(20) = Button21 : bt(21) = Button22 : bt(22) = Button23 : bt(23) = Button24
        bt(24) = Button25 : bt(25) = Button26 : bt(26) = Button27 : bt(27) = Button28 : bt(28) = Button29 : bt(29) = Button30
        bt(30) = Button31 : bt(31) = Button32 : bt(32) = Button33 : bt(33) = Button34 : bt(34) = Button35 : bt(35) = Button36
        For i = 0 To 35
            AddHandler bt(i).Click, AddressOf Me.bt_click
        Next
        ComboBox1.Items.Add("鼠标")
        ComboBox1.Items.Add("键盘")
        ComboBox2.Items.Add("初级  3s")
        ComboBox2.Items.Add("中级 1.5s")
        ComboBox2.Items.Add("高级  0.7s")
        ComboBox3.Items.Add("1个")
        ComboBox3.Items.Add("2个")
        ComboBox1.SelectedIndex = 0
        ComboBox2.SelectedIndex = 0
        Timer1.Interval = 3000
        ComboBox3.SelectedIndex = 0
        i = 1
    End Sub

    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        If ComboBox2.SelectedItem = "初级  3s" Then
            Timer1.Interval = 3000
        End If
        If ComboBox2.SelectedItem = "中级 1.5s" Then
            Timer1.Interval = 1500
        End If
        If ComboBox2.SelectedItem = "高级  0.7s" Then
            Timer1.Interval = 700
        End If
    End Sub

    Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
        If ComboBox3.SelectedItem = "1个" Then
            i = 1
        End If
        If ComboBox3.SelectedItem = "2个" Then
            i = 2
        End If
    End Sub

    Private Sub Button37_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button37.Click
        Timer2.Enabled = True
        Timer1.Enabled = True
    End Sub

    Private Sub Button38_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button38.Click
        Timer1.Enabled = False
        Timer2.Enabled = False
    End Sub

    Private Sub Button39_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button39.Click
        Dim res As Microsoft.VisualBasic.MsgBoxResult
        Timer1.Enabled = False
        Timer2.Enabled = False
        res = MsgBox("你确定要退出游戏吗?", MsgBoxStyle.OkCancel, "提示")
        If res = MsgBoxResult.Ok Then
            Me.Close()
        Else
            Timer1.Enabled = True
            Timer2.Enabled = True
        End If
    End Sub
    Private Sub bt_click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim bb As Button
        bb = CType(sender, Button)
        If Not bb.Image Is Nothing Then
            getscor = getscor + 1
        End If
        bb.Image = Nothing
        bb.Image = Nothing
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        bt(j).Image = Nothing
        bt(k).Image = Nothing
        If bbl = True Then
            Select Case ComboBox2.SelectedItem & ComboBox3.SelectedItem
                Case "初级  3s" & "1个"
                    tmm = 0
                    TextBox5.Text = "一"
                Case "初级  3s" & "2个"
                    tmm = 60
                    TextBox5.Text = "二"
                Case "中级 1.5s" & "1个"
                    tmm = 120
                    TextBox5.Text = "三"
                Case "中级 1.5s" & "2个"
                    tmm = 180
                    TextBox5.Text = "四"
                Case "高级  0.7s" & "1个"
                    tmm = 240
                    TextBox5.Text = "五"
                Case "高级  0.7s" & "2个"
                    tmm = 300
                    TextBox5.Text = "六"
            End Select
        End If
        bbl = False
        TextBox2.Text = getscor
        TextBox3.Text = sumscor - getscor
        If bl = False Then
            TextBox4.Text = Math.Round(getscor / sumscor, 2)
        End If
        bl = False
        Dim filename As String = Application.StartupPath & "\Image\1.jpg"
        filename = filename.Remove(filename.LastIndexOf("b") - 6, ("bin\Debug\").Length)
        ' Dim filename As String = Application.UserAppDataPath
        Dim im As Image
        im = Image.FromFile(filename)    
        If i = 1 Then
            Randomize()
            j = CInt(Rnd() * 35)
            bt(j).Image = im
            sumscor = sumscor + 1
        End If
        If i = 2 Then
            Randomize()
            j = CInt(Rnd() * 35)
            k = CInt(Rnd() * 35)
            While k = j
                k = CInt(Rnd() * 35)
            End While
            bt(j).Image = im
            bt(k).Image = im
            sumscor = sumscor + 2
        End If
    End Sub
    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Dim t1 As Microsoft.VisualBasic.MsgBoxResult
        Dim t2 As Microsoft.VisualBasic.MsgBoxResult
        TextBox1.Text = tm
        tm = tm + 1
        tmm = tmm + 1
        If tmm Mod 60 = 0 And Val(TextBox4.Text) < 0.8 Then
            Timer1.Enabled = False
            Timer2.Enabled = False
            t1 = MsgBox("闯关失败,要重新开始游戏吗?", MsgBoxStyle.OkCancel, "提示")
            If t1 = MsgBoxResult.Ok Then
                ComboBox2.SelectedItem = ""
                ComboBox3.SelectedItem = ""
                TextBox1.Text = ""
                TextBox2.Text = ""
                TextBox3.Text = ""
                TextBox4.Text = ""
                TextBox5.Text = ""
                tm = 0
                getscor = 0
                sumscor = 0
                TextBox4.Text = 0
                TextBox5.Text = "一"
                ComboBox2.SelectedItem = "初级  3s"
                ComboBox3.SelectedItem = "1个"
                Timer1.Enabled = True
                Timer2.Enabled = True
                Exit Sub
            Else
                Me.Close()
            End If
        End If
        If tmm Mod 60 = 0 And Val(TextBox4.Text) > 0.8 Then
            Select Case tmm \ 60
                Case 1
                    Timer1.Enabled = False
                    Timer2.Enabled = False
                    t2 = MsgBox("你已闯过第一关" & Chr(13) & Chr(10) & "请进入第二关", 0, "恭喜你")
                    If t2 = MsgBoxResult.Ok Then
                        Timer1.Enabled = True
                        Timer2.Enabled = True
                        tm = 0
                        getscor = 0
                        sumscor = 0
                        TextBox4.Text = 0
                    End If
                    TextBox5.Text = "二"
                    ComboBox2.SelectedItem = "初级  3s"
                    ComboBox3.SelectedItem = "2个"
                Case 2
                    Timer1.Enabled = False
                    Timer2.Enabled = False
                    t2 = MsgBox("你已闯过第二关" & Chr(13) & Chr(10) & "请进入第三关", 0, "恭喜你")
                    If t2 = MsgBoxResult.Ok Then
                        Timer1.Enabled = True
                        Timer2.Enabled = True
                        tm = 0
                        getscor = 0
                        sumscor = 0
                        TextBox4.Text = 0
                    End If
                    TextBox5.Text = "三"
                    ComboBox2.SelectedItem = "中级 1.5s"
                    ComboBox3.SelectedItem = "1个"
                Case 3
                    Timer1.Enabled = False
                    Timer2.Enabled = False
                    t2 = MsgBox("你已闯过第三关" & Chr(13) & Chr(10) & "请进入第四关", 0, "恭喜你")
                    If t2 = MsgBoxResult.Ok Then
                        Timer1.Enabled = True
                        Timer2.Enabled = True
                        tm = 0
                        getscor = 0
                        sumscor = 0
                        TextBox4.Text = 0
                    End If
                    TextBox5.Text = "四"
                    ComboBox2.SelectedItem = "中级 1.5s"
                    ComboBox3.SelectedItem = "2个"
                Case 4
                    Timer1.Enabled = False
                    Timer2.Enabled = False
                    t2 = MsgBox("你已闯过第四关" & Chr(13) & Chr(10) & "请进入第五关", 0, "恭喜你")
                    If t2 = MsgBoxResult.Ok Then
                        Timer1.Enabled = True
                        Timer2.Enabled = True
                        tm = 0
                        getscor = 0
                        sumscor = 0
                        TextBox4.Text = 0
                    End If
                    TextBox5.Text = "五"
                    ComboBox2.SelectedItem = "高级  0.7s"
                    ComboBox3.SelectedItem = "1个"
                Case 5
                    Timer1.Enabled = False
                    Timer2.Enabled = False
                    t2 = MsgBox("你已闯过第五关" & Chr(13) & Chr(10) & "请进入第六关", 0, "恭喜你")
                    If t2 = MsgBoxResult.Ok Then
                        Timer1.Enabled = True
                        Timer2.Enabled = True
                        tm = 0
                        getscor = 0
                        sumscor = 0
                        TextBox4.Text = 0
                    End If
                    TextBox5.Text = "六"
                    ComboBox2.SelectedItem = "高级  0.7s"
                    ComboBox3.SelectedItem = "2个"
                Case Else
                    Timer1.Enabled = False
                    Timer2.Enabled = False
                    MsgBox("你是真正的高手之王" & Chr(13) & Chr(10) & "祝你今晚睡个好觉", 0, "恭喜你")
                    Me.Close()
            End Select
        End If
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -