![]() |
Help with rock paper scissor program
I'm trying to write a vb.net program using random generation with rock paper scissor. I'm having problems writing the program. This is what I have so far. Can someone help me out with this. I need to use case structure to get it running and to play it 100 times automatically.
Dim random As New Random Dim Rock, Paper, Scissor, P1, P2 As Integer Rock = 1 Paper = 2 Scissor = 3 Select Case P1 Case 1 Select Case P2 Case 1 End Select End Select |
Still having some problems. This is how far I got but still nothing.
Really need help with this. Can't seem to ranomize or start the program. Private Sub btnrun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnrun.Click Dim random As Integer Dim Rock, Paper, Scissor, P1, P2 As Integer Rock = 1 Paper = 2 Scissor = 3 Randomize() random = Int(3 * Rnd()) Select Case P1 Case 1 Select Case P2 Case 1 lstbox.Items.Add("Rock") Case 2 lstbox.Items.Add("Paper") Case 3 lstbox.Items.Add("Scissor") Select Case P1 Case 2 Select Case P2 Case 1 lstbox.Items.Add("Rock") Case 2 lstbox.Items.Add("Paper") Case 3 lstbox.Items.Add("Scissor") Select Case P1 Case 3 Select Case P2 Case 1 lstbox.Items.Add("Rock") Case 2 lstbox.Items.Add("Paper") Case 3 lstbox.Items.Add("Scissor") End Select End Select End Select End Select End Select End Select End Sub End Class |
Please, put code tags around this - need tabbing!
|
[PHP]Dim random As Integer
Dim Rock, Paper, Scissor, P1, P2 As Integer Rock = 1 Paper = 2 Scissor = 3 Randomize() random = Int(3 * Rnd()) Select Case Rock Case 1 Select Case P2 Case 1 lstbox.Items.Add("Rock" & Rock) Case 2 lstbox.Items.Add("Paper" & Paper) Case 3 lstbox.Items.Add("Scissor" & Scissor) Select Case Paper Case 2 Select Case P2 Case 1 lstbox.Items.Add("Rock" & Rock) Case 2 lstbox.Items.Add("Paper" & Paper) Case 3 lstbox.Items.Add("Scissor" & Scissor) Select Case P1 Case 3 Select Case Scissor Case 1 lstbox.Items.Add("Rock" & Rock) Case 2 lstbox.Items.Add("Paper" & Paper) Case 3 lstbox.Items.Add("Scissor" & Scissor) End Select End Select End Select End Select End Select End Select End Sub End Class[/PHP] |
This is untested, but it's the way I would do it:
:
Dim P1 As Integer, P2 As Integer |
My program can only have start and a listbox. The program it self picks rock paper scissor and shows it in the list box and I need to show it 100 times. What can I add to it to make it work like that. Not even sure if I have the randomiz part right.
|
I'm confused, is all you want this....
[php] Randomize Dim rand as integer For I = 1 to 100 rand = Int((Rnd * 3) + 1) If rand = 1 then listbox.Items.Add("Rock") else if rand = 2 then listbox.Items.Add("Paper") else listobx.Items.Add("Scissors") end if Next I [/php] |
Looks like that will work. Do I need to add it three times for rock paper and scissor? Again thanks for all the help.
|
When I try to use this section of the program it gives me a break error
[PHP]RPS(0) = "Rock" RPS(1) = "Paper" RPS(2) = "Scissors"[/PHP] Is there a way I can fix this |
Yea, VB arrays start at 1 not 0.
[php] RPS(1) = "Rock" RPS(2) = "Paper" RPS(3) = "Scissors" [/php] |
| All times are GMT -5. The time now is 7:46 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC