Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic .NET (http://www.programmingforums.org/forum19.html)
-   -   Help with rock paper scissor program (http://www.programmingforums.org/showthread.php?t=2810)

Batalia2 Mar 17th, 2005 5:01 PM

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

Batalia2 Mar 17th, 2005 10:23 PM

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

Ooble Mar 18th, 2005 11:58 AM

Please, put code tags around this - need tabbing!

Batalia2 Mar 18th, 2005 1:40 PM

[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]

Ooble Mar 18th, 2005 1:55 PM

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

You need three list boxes: Player 1, Player 2 and Winner.

Batalia2 Mar 18th, 2005 7:47 PM

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.

tempest Mar 18th, 2005 8:39 PM

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]

Batalia2 Mar 18th, 2005 11:35 PM

Looks like that will work. Do I need to add it three times for rock paper and scissor? Again thanks for all the help.

Batalia2 Mar 20th, 2005 8:42 PM

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

tempest Mar 20th, 2005 8:45 PM

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