現在のゲームサイクルの推測の順序数を1増やしたいのですが、最初に値を0に設定しましたが、1の後に更新しません。 試行回数は同じです。私は21に値を設定しているが、すぐにそれが20になるまで更新ではなく、あなたのボタンのイベントハンドラでそのVBで変数を更新する
Option Strict On
Option Explicit On
Public Class Form1
Private ReadOnly rand As New Random
Private value As Integer
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.value = rand.Next(minValue:=1, maxValue:=30)
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim guess As Integer 'guess number
Dim numTry As Integer 'No. of trys
Dim RandNo As Integer 'Random Number
Dim OrdNo As Integer 'Ordinal Number
Dim Score As Integer 'Score
Score = 0 'Initial value of score set as 0
OrdNo = CInt(1) 'Initial value of ordinal set as 1
numTry = CInt(21)
guess = CInt(TextBox1.Text)
OrdNo = +1
Label5.Text = CStr(OrdNo)
'Show Message Box if the guess is not within the range
If 1 > guess Then
MessageBox.Show("Input within the range (1-30)", "Error", MessageBoxButtons.OK)
Exit Sub
End If
'Show Message Box if the guess is not within the range
If guess > 30 Then
MessageBox.Show("Input within the range (1-30)", "Error", MessageBoxButtons.OK)
Exit Sub
End If
'Display result and message when guess is larger than the lucky number
If guess > Me.value Then
Label11.Text = CStr(guess)
Label10.Text = "The Lucky Number is smaller than your guess"
OrdNo = OrdNo + 1
Label5.Text = CStr(OrdNo)
numTry = numTry - 1
Label4.Text = CStr(numTry)
End If
'Display result and message when guess is smaller than lucky number
If guess < Me.value Then
Label11.Text = CStr(guess)
Label10.Text = "The Lucky Number is larger than your guess"
OrdNo = OrdNo + 1
Label5.Text = CStr(OrdNo)
numTry = numTry - 1
Label4.Text = CStr(numTry)
End If
'Display result and message when guess is equal to the lucky number
If guess = Me.value Then
Label11.Text = CStr(guess)
Label10.Text = "Congratulations ! This is the lucky number"
Score = +10 'Increase the score by 10
Label6.Text = CStr(Score)
numTry = numTry - 1
OrdNo = 1
Me.value = rand.Next(minValue:=1, maxValue:=30)
If numTry = 0 Then Application.Exit()
End If
End Sub
End Class
そして、何ですあなたの問題?あなたはどんなエラーを出しているのですか?何がうまくいかない? – Claudius
私は彼が正しいと推測するまで番号が同じであることを望んでいると思うが、このコードを見ると、間違って推測されるたびに乱数が変わると思う。 – Werdna
デバッグすることを覚えてください.. – cybermonkey