button.BackColor语句似乎已执行,但未显示任何颜色更改

时间:2013-10-31 19:06:17

标签: vb.net

我正在尝试为项目重新创建经典游戏“Simon”。我在这里的代码应该有希望创建一个随机数,将其转换为随机按钮的颜色变化,等待一小段时间,然后对另一个随机按钮执行相同操作。我无法发现任何问题,但在执行时按钮保持不变。

Public Class MenuForm

Dim failure As Boolean
Dim pattern() As Integer
Dim maincounter As Integer = 1
Dim diff As Integer
Dim sender As Object
Dim e As EventArgs
Dim timewaited As Integer
Dim timefinished As Boolean



Private Sub Menuform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    'Get the difficulty level from the player  

    Dim InputtedDifficulty As Integer = InputBox("Please enter difficulty. 1-Easy 2-Medium 3-Hard")


    'Validate difficulty choice
    Do While InputtedDifficulty > 3 Or InputtedDifficulty < 1
        InputtedDifficulty = InputBox("Input incorrect. Please re-enter selection. 1-Easy 2-Medium 3-Hard")
    Loop

    'Set speed of blinking based on difficulty choice
    Select Case InputtedDifficulty
        Case 1
            diff = 1000
        Case 2
            diff = 500
        Case 3
            diff = 20
    End Select


End Sub
Private Sub run_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles run.Click

    Call GameController()

End Sub
Private Sub GameController()

    Dim buttonRepeater As Integer

    'Call checkFail()
    Do While failure = False
        maincounter = maincounter + 1
        Call Pattern_creator(sender, e)
        For buttonRepeater = 1 To maincounter


            Call button_controller(sender, e)

            timewaited = 0
            timefinished = False

            ButtonTimer.Enabled = True
            If timefinished = True Then
            End If

            Button1.BackColor = Color.Blue
            Button2.BackColor = Color.Blue
            Button3.BackColor = Color.Blue
            Button4.BackColor = Color.Blue
        Next buttonRepeater

    Loop

End Sub

Private Sub Pattern_creator(ByVal sender As System.Object, ByVal e As System.EventArgs)

    ReDim Preserve pattern(maincounter)

    Randomize()
    pattern(maincounter) = Int((Rnd() * 4) + 1)
    ReDim Preserve pattern(maincounter + 1)

End Sub

Private Sub button_controller(ByVal sender As System.Object, ByVal e As System.EventArgs)

    'Ths case statement takes the random number generated earlier and translates that to 
    'a button flash

    Select Case pattern(maincounter)
        Case 1
            Button1.BackColor = Color.Red
        Case 2
            Button2.BackColor = Color.Red
        Case 3
            Button3.BackColor = Color.Red
        Case 4
            Button4.BackColor = Color.Red
    End Select

End Sub

Private Sub ButtonTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonTimer.Tick

    If timewaited = 5 Then
        ButtonTimer.Enabled = False
        timefinished = True
    Else
        timewaited = timewaited + 1
    End If


End Sub
End Class

任何帮助都会非常感激,我一直盯着这个很久没有进展。

0 个答案:

没有答案