生命游戏点击并拖动

时间:2013-06-12 15:11:55

标签: vb.net conways-game-of-life

我正在进行生活游戏并遇到了一个我无法解决的问题。

对于游戏,我在代码中创建了一个按钮网格,我想添加一个处理程序,当单击鼠标按钮并将其拖过任何按钮时,它会使按钮处于活动状态或死亡状态。

但我找不到任何有助于此的处理程序 这是我每次创建新按钮时添加处理程序的方式:

Dim x, y As Integer
'  Start 15 px in from left hand side of form
Dim left As Integer = 0
'  Set the size of the textbox dimensions (height and width)
Dim boxdims As Integer
'  Start 20 px from the top of the form
Dim topgap As Integer = 25
' Number of cells (horCell by VerCell)
Dim right As Integer = 15

If cboCellWorldSize.SelectedIndex = 2 Then
    boxdims = 40
    horCell = (screenWidthRes \ boxdims)
    verCell = (screenHeightRes \ boxdims)
ElseIf cboCellWorldSize.SelectedIndex = 1 Then
    boxdims = 25
    horCell = (screenWidthRes \ boxdims)
    verCell = (screenHeightRes \ boxdims)
ElseIf cboCellWorldSize.SelectedIndex = 0 Then
    boxdims = 15
    horCell = (screenWidthRes \ boxdims)
    verCell = (screenHeightRes \ boxdims)
End If

ReDim cellArray(horCell, verCell)


For x = 0 To horCell  '  Nested loop for rows and cols
    For y = 0 To verCell

        '  Create a new Button
        Dim NextButton As New Button
        '  Set some of its Properties
        With NextButton
            .Left = left
            .Height = boxdims
            .Width = boxdims
            .BackColor = dead
            .Top = topgap + (NextButton.Height * y)
            .FlatAppearance.BorderSize = 0

            AddHandler NextButton.MouseEnter, AddressOf Me.btnClick


        End With


        cellArray(x, y) = NextButton
        '  Add this new button to the Form's Controls Collection

        Me.Controls.Add(NextButton)

    Next
    '  Ready to start the next column
    '  Move the left side of the next column of textboxes
    '  over to the right.
    left += boxdims
Next

我目前正在使用mouseEnter事件,但它没有正确配置游戏

0 个答案:

没有答案