随机数的加法和减法

时间:2015-04-01 13:15:31

标签: vb.net winforms visual-studio-2010

我正在尝试制作一个由3种形式组成的简单数学游戏。第一种形式是标题屏幕,其具有开始游戏的按钮。按下按钮时,它将使表格2可见。表格2将生成2个随机数字和“+”或“ - ”符号并开始计时器。然后,用户将答案输入文本框并单击“检查答案”按钮,该按钮将显示“正确”或“不正确”标签。我想要重复5次,最后时间将显示表格3,它将显示总时间和正确答案的数量。

到目前为止,我的第一个表格是:

Public Class startForm
Public randomNumber As New Random()

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Me.Hide()
    questionForm.Show()

    questionForm.num1.Text = randomNumber.Next(1, 100)
    questionForm.num2.Text = randomNumber.Next(1, 100)
    questionForm.mathSymbol.Text = randomNumber.Next(1, 10)

    If questionForm.mathSymbol.Text = 1 Then
        questionForm.mathSymbol.Text = "+"
    ElseIf questionForm.mathSymbol.Text = 2 Then
        questionForm.mathSymbol.Text = "+"
    ElseIf questionForm.mathSymbol.Text = 3 Then
        questionForm.mathSymbol.Text = "+"
    ElseIf questionForm.mathSymbol.Text = 4 Then
        questionForm.mathSymbol.Text = "+"
    ElseIf questionForm.mathSymbol.Text = 5 Then
        questionForm.mathSymbol.Text = "+"
    Else
        questionForm.mathSymbol.Text = "-"
    End If

End Sub

End Class

我的第二种形式是:

Public Class questionForm

Public count As Integer = 0
Public ans As Integer


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    If mathSymbol.Text = "+" Then
        Convert.ToInt32(num1.Text)
        Convert.ToInt32(num2.Text)
        ans = num1.Text + num2.Text
    Else
        ans = num1.Text - num2.Text
    End If

    If answerBox.Text = ans Then
        correctLabel.Visible = True
    Else
        incorrectLabel.Visible = True
    End If

End Sub

End Class

这会导致答案始终显示为“不正确”,那么我该怎么做才能修复它?我也无法让定时器工作。

谢谢。

0 个答案:

没有答案
相关问题