none
關於vb2010踩地雷 RRS feed

  • 問題

  • Public Class Form1
        Private n
        Private X As Integer = 6
        Private Y As Integer = 6
        Private i As Integer
        Private boomnumber As Integer = 10
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Dim x, y, d
            Dim B As Button
            n = New Button
            For x = 1 To 6
                For y = 1 To 6
                    n(x, y) = New Button With {.Name = n(x - 1, y - 1)}
                    n(x, y).indexX = x
                    n(x, y).indexY = y
                    Controls.Add(n(x, y))
                    AddHandler n(x, y).click, AddressOf n_click
                Next
            Next

            Call putboom()
        End Sub
        Private Sub putboom()
            Dim tempary() As Integer = New Integer(6 * 6) {}
            Dim temp = tempary.Length
            Dim boom As Integer

            For Me.i = 0 To tempary.Length
                tempary(i) = i
            Next

            Randomize()
            For Me.i = 1 To boomnumber
                boom = Int(Rnd() * temp)
                n(tempary(boom) Mod 6, Int(tempary(boom) / 6)).text = 1
                tempary(boom) = tempary(temp)
                temp -= 1
            Next
        End Sub
        Private Sub gameover()
            Dim x, y As Integer
            For x = 0 To 5
                For y = 0 To 5
                    If n(x, y).text = 1 Then
                        n(x, y).text = "B"
                    End If
                    n(x, y).enabled = False
                Next
            Next
        End Sub
        Private Sub n_click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
            Dim b As Button = sender
            Dim box As Integer = 0

            If e.Button = Windows.Forms.MouseButtons.Left Then
                If Not n.Click.Enabled = False Then
                    If b.Text = 1 Then
                        Call gameover()
                        b.Text = "B"
                        MsgBox("game over!")
                    End If
                    removeboom(b)
                End If
                End If
        End Sub
        Private Sub removeboom(ByVal b As Button)
            Dim x, y As Integer
            Dim a, d As Integer
            Dim boom As Integer = 0

            If b.Enabled = True Then
                For x = -1 To 1
                    For y = -1 To 1
                        a = x
                        d = y
                        If (Not (x = 0 And y = 0)) And a >= 0 And a < 6 And y >= 0 And y < 6 Then
                            If n(x, y).haveboom = True Then boom += 1
                        End If
                    Next
                Next
            End If
        End Sub
    End Class

    請問一下我係唔係寫錯program...

    2014年6月16日 下午 01:48

解答