![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2005
Posts: 9
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Mar 2005
Posts: 9
Rep Power: 0
![]() |
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 Last edited by Batalia2; Mar 17th, 2005 at 9:28 PM. |
|
|
|
|
|
#3 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Please, put code tags around this - need tabbing!
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: Mar 2005
Posts: 9
Rep Power: 0
![]() |
[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] |
|
|
|
|
|
#5 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
This is untested, but it's the way I would do it:
Dim P1 As Integer, P2 As Integer Dim RPS(3) As Integer Dim Winner As Integer Dim x As Integer Enum RPS Rock = 0, Paper, Scissors End Enum RPS(0) = "Rock" RPS(1) = "Paper" RPS(2) = "Scissors" Randomize For x = 1 To 100 P1 = Int(3 * Rnd) P2 = Int(3 * Rnd) Select Case P1 Case Rock Select Case P2 Case Rock Winner = 0 Case Paper Winner = 2 Case Scissors Winner = 1 End Select Case Paper Select Case P2 Case Rock Winner = 1 Case Paper Winner = 0 Case Scissors Winner = 2 End Select Case Scissors Select Case P2 Case Rock Winner = 2 Case Paper Winner = 1 Case Scissors Winner = 0 End Select End Select lstP1.Items.Add RPS(P1) lstP2.Items.Add RPS(P2) lstWinner.Items.Add "Player " & Winner Next x |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Mar 2005
Posts: 9
Rep Power: 0
![]() |
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.
|
|
|
|
|
|
#7 |
|
Programming Guru
![]() |
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]
__________________
|
|
|
|
|
|
#8 |
|
Newbie
Join Date: Mar 2005
Posts: 9
Rep Power: 0
![]() |
Looks like that will work. Do I need to add it three times for rock paper and scissor? Again thanks for all the help.
|
|
|
|
|
|
#9 |
|
Newbie
Join Date: Mar 2005
Posts: 9
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#10 |
|
Programming Guru
![]() |
Yea, VB arrays start at 1 not 0.
[php] RPS(1) = "Rock" RPS(2) = "Paper" RPS(3) = "Scissors" [/php]
__________________
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|