0

我正在创建一个游戏,玩家回答一个问题,然后如果他们回答正确,那么他们可以翻转两张牌以查看它们是否匹配(有点像配对游戏)。但是,我正在努力弄清楚如何停止输入框(用户如何输入他们的答案),如果玩家正确回答问题,则出现一段时间,直到玩家选择了两张牌。

我正在使用两个数组,一个用于保存问题,另一个用于保存答案。Ps 请原谅最后几个问题,在我完成所有问题之前试图让它发挥作用。

Private Sub Questions()

    strQuestions(0) = "A common noun refers to the name of things."
    strQuestions(1) = "A pronoun is a word that takes the place of nouns."
    strQuestions(2) = "'She' is a pronoun that would replace a woman's name."
    strQuestions(3) = "The days of the week are proper nouns."
    strQuestions(4) = "'He', 'She' and 'them' are all pronouns."
    strQuestions(5) = "Spain is a proper noun."
    strQuestions(6) = "Proper nouns always start with a capital letter."
    strQuestions(7) = "The place 'England' is referred to as a proper noun."
    strQuestions(8) = "A 'camera' is a common noun."
    strQuestions(9) = "FE"
    strQuestions(10) = "GR"

    strAnswers(0) = "TRUE"
    strAnswers(1) = "TRUE"
    strAnswers(2) = "TRUE"
    strAnswers(3) = "TRUE"
    strAnswers(4) = "TRUE"
    strAnswers(5) = "TRUE"
    strAnswers(6) = "TRUE"
    strAnswers(7) = "TRUE"
    strAnswers(8) = "TRUE"
    strAnswers(9) = "TRUE"
    strAnswers(10) = "TRUE"

    Dim userAnswer As String

    For i = 0 To UBound(strQuestions)
        userAnswer = InputBox(strQuestions(i))
        If userAnswer <> strAnswers(i) Then
            MsgBox("Incorrect. Try again.")
        Else
            MsgBox("Correct! Make your move.")
            WHAT GOES HERE?
        End If
    Next i
End Sub

Private Sub label_click(ByVal sender As System.Object,
                        ByVal e As System.EventArgs) Handles Label9.Click, Label8.Click, Label7.Click, Label6.Click, Label5.Click,
                    Label4.Click, Label3.Click, Label2.Click, Label16.Click, Label15.Click, Label14.Click, Label13.Click, Label12.Click,
                    Label11.Click, Label10.Click, Label1.Click

    ' The timer is only on after two non-matching 
    ' icons have been shown to the player, 
    ' so ignore any clicks if the timer is running
    If Timer1.Enabled Then Exit Sub

    Dim clickedLabel = TryCast(sender, Label)

    If clickedLabel IsNot Nothing Then

    End If
    ' If the clicked label is black, the player clicked
    ' an icon that's already been revealed --
    ' ignore the click
    If clickedLabel.ForeColor = Color.Black Then Exit Sub

    ' If firstClicked is Nothing, this is the first icon 
    ' in the pair that the player clicked, 
    ' so set firstClicked to the label that the player 
    ' clicked, change its color to black, and return
    If firstClicked Is Nothing Then
        firstClicked = clickedLabel
        firstClicked.ForeColor = Color.Black
        Exit Sub
    End If

    ' If the player gets this far, the timer isn't 
    ' running and firstClicked isn't Nothing, 
    ' so this must be the second icon the player clicked
    ' Set its color to black
    secondClicked = clickedLabel
    secondClicked.ForeColor = Color.Black

    CheckForWinner()

    ' If the player clicked two matching icons, keep them 
    ' black and reset firstClicked and secondClicked 
    ' so the player can click another icon
    If firstClicked.Text = secondClicked.Text Then
        firstClicked = Nothing
        secondClicked = Nothing
        Questions()
        Exit Sub
    End If

    ' If the player gets this far, the player 
    ' clicked two different icons, so start the 
    ' timer (which will wait three quarters of 
    ' a second, and then hide the icons)
    Timer1.Start()

    Questions()
Exit Sub
4

1 回答 1

1

您需要重组您的程序,以使提出问题的部分不在循环中。而是考虑使用一个要求下一个答案的 sub。如果给出正确答案,则子退出并且应用程序等待用户选择卡片。

选择卡片后,您再次调用提问子。通过问题列表的位置作为变量存储在表单中。每次执行 ask a question sub 时,它都会检查是否已到达列表末尾,如果已到达则结束游戏。

像这样的东西(尽管我写任何 VB 已经有一段时间了!)

Private CurrentQuestion As Integer

Private Sub Questions()
    CurrentQuestion = 0

    ...


    AskQuestion
End Sub

Private Sub AskQuestion
    If CurrentQuestion = UBound(strQuestions)
        EndGame
    Else
        userAnswer = InputBox(strQuestions(CurrentQuestion))
        If userAnswer <> strAnswers(CurrentQuestion) Then
            MsgBox("Incorrect. Try again.")
            AskQuestion
        Else
            CurrentQuestion = CurrentQuestion + 1
            MsgBox("Correct! Make your move.")
        End If
    End If
End Sub

Private Sub label_click(ByVal sender As System.Object,

    ....

    AskQuestion
End Sub
于 2013-07-09T10:13:35.590 回答