R
r0ry
Guest
I need some help with a random number generator. Its for a game, and I need a new number to be generated within [1,13] each time a button is pressed. The button also shows certain picture boxes, determines the relationship of the generated number to another computer generated number (as a CPU opponent) and assigns points based on the relationship, and takes away a turn.
Public Class Form1
Dim x, y, z, a, b As Double
Dim r As New Random
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
x = r.Next(1, 14) random number changed by button
y = r.Next(1, 14) CPU opponent random number
z = 26 number of turns
a = 0 player points
b = 0 CPU points
here are the variables that I declared
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If x = 13 Then
PictureBox3.Hide()
PictureBox4.Hide()
PictureBox5.Hide()
PictureBox6.Hide()
PictureBox7.Hide()
PictureBox8.Hide()
PictureBox9.Hide()
PictureBox10.Hide()
PictureBox11.Hide()
PictureBox12.Hide()
PictureBox13.Hide()
PictureBox14.Hide()
PictureBox2.Show()
z = z - 1
If y < x Then
a = a + 1
ElseIf y > x Then
a = a
ElseIf y = x Then
Form2.Show()
Me.Hide()
End If
...(more similar code here)
Label6.Text = a
Label7.Text = b
Label6.Show()
Label7.Show()
If z = 0 And a > b Then
MsgBox("You win!")
End
End If
If z = 0 And b > a Then
MsgBox("You lose!")
End
End If
and here is the basic code for the game. is there any way to create a new random number so a different picture box is shown whenever the button is pressed?
Continue reading...
Public Class Form1
Dim x, y, z, a, b As Double
Dim r As New Random
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
x = r.Next(1, 14) random number changed by button
y = r.Next(1, 14) CPU opponent random number
z = 26 number of turns
a = 0 player points
b = 0 CPU points
here are the variables that I declared
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If x = 13 Then
PictureBox3.Hide()
PictureBox4.Hide()
PictureBox5.Hide()
PictureBox6.Hide()
PictureBox7.Hide()
PictureBox8.Hide()
PictureBox9.Hide()
PictureBox10.Hide()
PictureBox11.Hide()
PictureBox12.Hide()
PictureBox13.Hide()
PictureBox14.Hide()
PictureBox2.Show()
z = z - 1
If y < x Then
a = a + 1
ElseIf y > x Then
a = a
ElseIf y = x Then
Form2.Show()
Me.Hide()
End If
...(more similar code here)
Label6.Text = a
Label7.Text = b
Label6.Show()
Label7.Show()
If z = 0 And a > b Then
MsgBox("You win!")
End
End If
If z = 0 And b > a Then
MsgBox("You lose!")
End
End If
and here is the basic code for the game. is there any way to create a new random number so a different picture box is shown whenever the button is pressed?
Continue reading...