Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 17th, 2005, 4:01 PM   #1
Batalia2
Newbie
 
Join Date: Mar 2005
Posts: 9
Rep Power: 0 Batalia2 is on a distinguished road
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 is offline   Reply With Quote
Old Mar 17th, 2005, 9:23 PM   #2
Batalia2
Newbie
 
Join Date: Mar 2005
Posts: 9
Rep Power: 0 Batalia2 is on a distinguished road
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.
Batalia2 is offline   Reply With Quote
Old Mar 18th, 2005, 10:58 AM   #3
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Please, put code tags around this - need tabbing!
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 18th, 2005, 12:40 PM   #4
Batalia2
Newbie
 
Join Date: Mar 2005
Posts: 9
Rep Power: 0 Batalia2 is on a distinguished road
[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]
Batalia2 is offline   Reply With Quote
Old Mar 18th, 2005, 12:55 PM   #5
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 18th, 2005, 6:47 PM   #6
Batalia2
Newbie
 
Join Date: Mar 2005
Posts: 9
Rep Power: 0 Batalia2 is on a distinguished road
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.
Batalia2 is offline   Reply With Quote
Old Mar 18th, 2005, 7:39 PM   #7
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
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]
__________________

tempest is offline   Reply With Quote
Old Mar 18th, 2005, 10:35 PM   #8
Batalia2
Newbie
 
Join Date: Mar 2005
Posts: 9
Rep Power: 0 Batalia2 is on a distinguished road
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 is offline   Reply With Quote
Old Mar 20th, 2005, 7:42 PM   #9
Batalia2
Newbie
 
Join Date: Mar 2005
Posts: 9
Rep Power: 0 Batalia2 is on a distinguished road
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
Batalia2 is offline   Reply With Quote
Old Mar 21st, 2005, 3:36 PM   #10
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
You need that array. It should work as I've typed it, if you haven't set the Option Base to 1.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:51 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC