所以我做了一个猜谜游戏,它的工作率为 95%。但是,有两个问题我无法弄清楚。
- 每当所谓的随机数在 1 到 10 之间时,90% 的时间都是“7”。
- 我在表格 2 上有一个分数,但是每当添加一个分数时,它要么重置为一个,要么将一个添加到另一个玩家并从第一个玩家中删除一个。
这是代码,提前谢谢你!
Public Class Form1
Public turn As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim turn1 As Integer
Form2.Show()
Me.Hide()
turn1 = 2 * Rnd() + 0
If turn1 = 0 Then
turn = True
Else
turn = False
End If
If turn = True Then
PictureBox3.Hide()
PictureBox2.Show()
End If
If turn = False Then
PictureBox3.Show()
PictureBox2.Hide()
End If
If Form2.RadioButton5.Checked = True Then
PictureBox1.Image = My.Resources.animated_60
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
End If
If Form2.RadioButton6.Checked = True Then
PictureBox1.Image = My.Resources.myanistarb
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
End If
If Form2.RadioButton7.Checked = True Then
PictureBox1.Image = My.Resources.black_rain_fall_animated
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim player1guess As Integer = Val(TextBox1.Text)
Static onescore As Integer
If turn = True Then
PictureBox2.Show()
PictureBox3.Hide()
Select Case player1guess
Case Is = Form2.x
MsgBox("You Got It")
My.Computer.Audio.Play(My.Resources.wahoo, AudioPlayMode.Background)
onescore += 1
Me.Close()
Form2.Activate()
Form2.Label5.Text = Val(onescore)
Case Is > Form2.x
MsgBox("Too High")
Label4.Text = Label4.Text & player1guess & " - Too High" & vbCrLf
My.Computer.Audio.Play(My.Resources.daffy_26, AudioPlayMode.Background)
Case Is < Form2.x
MsgBox("Too Low")
Label4.Text = Label4.Text & player1guess & " - Too Low" & vbCrLf
My.Computer.Audio.Play(My.Resources.daffy_26, AudioPlayMode.Background)
End Select
turn = False
End If
If turn = False Then
PictureBox2.Hide()
PictureBox3.Show()
End If
If turn = False Then
Button1.BackColor = Color.Black
Button2.BackColor = Color.White
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim player2guess As Integer = Val(TextBox2.Text)
Static twoscore As Integer
If turn = False Then
PictureBox2.Hide()
PictureBox3.Show()
Select Case player2guess
Case Is = Form2.x
MsgBox("You Got It")
Form2.Label6.Text = Val(twoscore)
My.Computer.Audio.Play(My.Resources.wahoo, AudioPlayMode.Background)
twoscore += 1
Me.Close()
Form2.Show()
Case Is > Form2.x
MsgBox("Too High")
Label5.Text = Label5.Text & player2guess & " - Too High" & vbCrLf
My.Computer.Audio.Play(My.Resources.daffy_26, AudioPlayMode.Background)
Case Is < Form2.x
MsgBox("Too Low")
Label5.Text = Label5.Text & player2guess & " - Too Low" & vbCrLf
My.Computer.Audio.Play(My.Resources.daffy_26, AudioPlayMode.Background)
End Select
turn = True
End If
If turn = True Then
PictureBox2.Show()
PictureBox3.Hide()
End If
If turn = True Then
Button2.BackColor = Color.Black
Button1.BackColor = Color.White
End If
End Sub
End Class
这是生成随机数的地方:
Public Class Form2
Public x As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form1.NAME1.Text = TextBox1.Text
Form1.NAME2.Text = TextBox2.Text
If RadioButton1.Checked = True Then
x = Rnd() * 10
ElseIf RadioButton2.Checked = True Then
x = Rnd() * 100
ElseIf RadioButton3.Checked = True Then
x = Rnd() * 1000
ElseIf RadioButton4.Checked = True Then
x = Rnd() * 10000
End If
If TextBox1.Text = Nothing Then MsgBox("Please enter a name for Player 1")
If TextBox2.Text = Nothing Then MsgBox("Please enter a name for Player 2")
If TextBox1.Text <> Nothing And TextBox2.Text <> Nothing Then Form1.Show()
End Sub
End Class