Математическая игра - Как сделать 10 вопросов круглым - PullRequest
0 голосов
/ 29 ноября 2018

Я играю в математическую викторину, и мне интересно, почему вопрос не меняется на НОВЫЙ, когда я получаю правильный ответ и КАК сделать 10 и перестать работать, затем выскочить в окне сообщения, чтобы спросить пользователя, хотите лиИГРАТЬ СНОВА или нет?

Public Class Multiplication
Dim TotalQuestion As Integer
Dim CorrectAnswer As Integer
Dim WrongAnswer As Integer
Dim R As New Random
Dim numOne As Integer = R.Next(0, 10)
Dim numTwo As Integer = R.Next(1, 10)

Dim Ans As Integer = 0
Dim Tries As Integer = 0

Private Sub Multiplication_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Generate()
End Sub

Sub Generate()
    TotalQuestion = TotalQuestion + 1
    Dim Show As String
    Show = numOne & " x " & numTwo & " = "
    lblQuestionMUL.Text = Show
End Sub

Private Function Multiply(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
    Return num1 * num2
    Generate()
End Function

Private Sub btnEnter_Click(sender As Object, e As EventArgs) Handles btnEnter.Click
    Integer.TryParse(lblQuestionMUL.Text, numOne & numTwo)
    Ans = Multiply(numOne, numTwo)
    If Val(txtAnswer.Text) = Ans Then
        CorrectAnswer = CorrectAnswer + 1
    Else
        WrongAnswer = WrongAnswer + 1
    End If
    lblCorrectAns.Text = CorrectAnswer
    lblWrongAns.Text = WrongAnswer
    txtAnswer.Clear()
    txtAnswer.Focus()
    Generate()
End Sub
End Class

1 Ответ

0 голосов
/ 29 ноября 2018

В дополнение к предыдущим комментариям вы должны установить переменные numOne и numTwo в случайные числа в Generate Sub (Сохранение объявления в качестве глобальных переменных).Ваш код просто устанавливает их в начале случайных чисел только один раз.Проверьте код ниже:

Public Class Multiplication

Dim TotalQuestion As Integer = 0
Dim CorrectAnswer As Integer
Dim WrongAnswer As Integer
Dim R As New Random
Dim NumOne As Integer
Dim NumTwo As Integer
Dim QuizCompleted As Boolean = False

Dim Ans As Integer = 0
Dim Tries As Integer = 0

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

    Generate()

End Sub


Sub Generate()

    If TotalQuestion < 10 Then

        NumOne = R.Next(0, 10)
        NumTwo = R.Next(1, 10)

        TotalQuestion = TotalQuestion + 1
        Dim Show As String
        Show = NumOne & " x " & NumTwo & " = "
        lblQuestionMUL.Text = Show

    Else

        QuizCompleted = True

    End If

End Sub

Private Function Multiply(ByVal num1 As Integer, ByVal num2 As Integer) As Integer

    Generate()
    Return num1 * num2

End Function

Private Sub btnEnter_Click(sender As Object, e As EventArgs) Handles btnEnter.Click

    Integer.TryParse(lblQuestionMUL.Text, NumOne & NumTwo)
    Ans = Multiply(NumOne, NumTwo)
    If Val(txtAnswer.Text) = Ans Then
        CorrectAnswer = CorrectAnswer + 1
    Else
        WrongAnswer = WrongAnswer + 1
    End If
    lblCorrectAns.Text = CorrectAnswer
    lblWrongAns.Text = WrongAnswer
    txtAnswer.Clear()
    txtAnswer.Focus()

    If QuizCompleted Then

        MsgBox("Quiz Completed")

    End If

End Sub
End Class
...