推測ゲームを作ってみたところ、95% うまくいきました。しかし、私が理解できない2つの問題があります。
- 乱数と思われる数値が 1 から 10 の間である場合、90% の確率で "7" になります。
- フォーム 2 にスコアがありますが、スコアが追加されるたびに、スコアが 1 にリセットされるか、他のプレーヤーに 1 つ追加されて最初のプレーヤーから 1 つが削除されます。
これがコードです。よろしくお願いします!
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