Vb.net 乘法游戏计数器

Vb.net 乘法游戏计数器,vb.net,random,Vb.net,Random,这个乘法游戏的功能应该是正常的。我只是需要一种方法,让游戏的用户能够看到他们有多少问题是错的和对的。我需要实现一个计数器,但大多数在线指南都被证明是无用的。我决定发布代码,看看是否有人能帮我。您可以声明两个新变量来存储错误和正确的问题值 Public Class Form1 ' num1 and num2 now generate a number between 1 and 10 Dim num1 As Integer = CInt(Int((10 * Rnd()) + 1)) Dim cou

这个乘法游戏的功能应该是正常的。我只是需要一种方法,让游戏的用户能够看到他们有多少问题是错的和对的。我需要实现一个计数器,但大多数在线指南都被证明是无用的。我决定发布代码,看看是否有人能帮我。

您可以声明两个新变量来存储错误和正确的问题值

Public Class Form1
' num1 and num2 now generate a number between 1 and 10
Dim num1 As Integer = CInt(Int((10 * Rnd()) + 1))
Dim counter As Integer
Dim num2 As Integer = CInt(Int((10 * Rnd()) + 1))

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



End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    ' Generates a new question everytime the button is clicked
    num1 = CInt(Int((10 * Rnd()) + 1))
    num2 = CInt(Int((10 * Rnd()) + 1))
    'Displays question in textbox2
    TextBox2.Text = num1 & "*" & num2
End Sub

Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged

End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    If TextBox1.Text = num1 * num2 Then
        ' If they get the answer right, they recieve postive feedback
        Label2.Text = "Correct!!11"
    Else
        ' Any other answer results in negative feedback
        Label2.Text = "Incorrect, sorry about
然后使用

Dim wrongQuestions as Integer = 0
Dim correctQuestions as Integer = 0

  If TextBox1.Text = num1 * num2 Then
        ' If they get the answer right, they recieve postive feedback
        Label2.Text = "Correct!!11"
        correctQuestions += 1
    Else
        ' Any other answer results in negative feedback
        Label2.Text = "Incorrect, sorry about"
        wrongQuestions += 1

使用随机和用户输入错误检查

 msgbox("Correct Questions: " &  correctQuestions & " Incorrect Questions: " & wrongQuestions )
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
    Me.AcceptButton = Button2
    Button1.PerformClick()
End Sub

Dim prng As New Random
Dim answer As Integer
Dim incorrect As Integer = 0
Dim correct As Integer = 0

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    ' Generates a new question everytime the button is clicked
    Dim num1 As Integer = prng.Next(1, 11)
    Dim num2 As Integer = prng.Next(1, 11)
    TextBox2.Text = String.Format("{0} * {1}", num1, num2)
    answer = num1 * num2
    TextBox1.Text = ""
    TextBox1.Select()
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    'check answer
    Dim useranswer As Integer
    If Integer.TryParse(TextBox1.Text, useranswer) Then
        If useranswer = answer Then
            correct += 1
            Label2.Text = "Correct  "
        Else
            incorrect += 1
            Label2.Text = "Incorrect"
        End If
        Label2.Text &= String.Format("     Totals: correct = {0}, incorrect = {1}", _
                                     correct, incorrect)
        Button1.PerformClick()
    Else
        Label2.Text = "answer should be numeric"
    End If
End Sub