-
December 2nd, 2013, 12:53 AM
#1
[VB 2012] Need help with a Rock Paper Scissors Lizard Spock game
Okay, for my last project in my class I'm to construct a game that follows these guidelines:
http://imageshack.com/a/img811/6125/r6zh.jpg
So now that I've got that out of the way, I'm having some issues with my code. Mainly one issue, here's my code with the bold indicators where my problem is, since it won't go bold faced:
Code:
Public Class frmCapstone
Dim numWinUser As Integer
Dim numWinComp As Integer
Dim numDraws As Integer
Dim userName, roundNum As String
Dim computer As String
Dim c1, c2, c3, c4, c5 As Integer
Private Sub chkGame_CheckedChanged(sender As Object, e As EventArgs) Handles chkGame.CheckedChanged
grpGame.Enabled = False
userName = CStr(txtName.Text)
roundNum = CStr(txtRounds.Text)
If chkGame.Checked Then
grpGame.Enabled = True
Else
grpGame.Enabled = False
End If
End Sub
Private Sub btnPlay_Click(sender As Object, e As EventArgs) Handles btnPlay.Click
Dim randomNum As New Random
Dim winner As String
computer = randomNum.Next(1, 6)
c1 = chkRock.Checked
c2 = chkPaper.Checked
c3 = chkScissors.Checked
c4 = chkLizard.Checked
c5 = chkSpock.Checked
DisplayResults(numWinUser, numWinComp, numDraws)
winner = DetermineWinner(userName, computer)
Select Case grpGame
Case Is = chkRock.Checked
lstResults.Items.Clear()
lstResults.Items.Add("The winner of this round is " & winner)
lstResults.Items.Add("Your chose " & c1)
lstResults.Items.Add("Computer's choice was " & randomNum)
Case Is = chkPaper.Checked
lstResults.Items.Clear()
lstResults.Items.Add("The winner of this round is " & winner)
lstResults.Items.Add("Your chose " & c2)
lstResults.Items.Add("Computer's choice was " & randomNum)
Case Is = chkScissors.Checked
lstResults.Items.Clear()
lstResults.Items.Add("The winner of this round is " & winner)
lstResults.Items.Add("Your chose " & c3)
lstResults.Items.Add("Computer's choice was " & randomNum)
Case Is = chkLizard.Checked
lstResults.Items.Clear()
lstResults.Items.Add("The winner of this round is " & winner)
lstResults.Items.Add("Your chose " & c4)
[b]lstResults.Items.Add("Computer's choice was " & randomNum)[b]
Case Is = chkSpock.Checked
lstResults.Items.Clear()
lstResults.Items.Add("The winner of this round is " & winner)
lstResults.Items.Add("Your chose " & c5)
lstResults.Items.Add("Computer's choice was " & randomNum)
End Select
Select Case winner
Case "user"
numWinUser += 1
Case "comp"
numWinComp += 1
Case "draw"
numDraws += 1
End Select
DisplayResults(numWinUser, numWinComp, numDraws)
End Sub
Function DetermineWinner(ByVal userName As String, ByVal computer As Integer) As String
If userName > computer Then
Return "" & userName
lstResults.Items.Add("Impressive. Most impressive. But you're not a Jedi yet!")
ElseIf userName < computer Then
Return "computer"
lstResults.Items.Add("You really suck at this game. U Mad Bro?")
Else
Return "draw"
lstResults.Items.Add("Epic Fail with a side of Picard Facepalm")
End If
End Function
Sub DisplayResults(ByVal numWinUser As Integer, ByVal numWinComp As Integer, ByVal numDraws As Integer)
txtWin.Text = CStr(numWinUser)
txtLoss.Text = CStr(numWinComp)
txtDraw.Text = CStr(numDraws)
If numWinComp = 2 Then
lstResults.Items.Add("Ha Ha Ha Ha, you lose. Loser! You're a loser! Game Over")
ElseIf numWinUser = 2 Then
lstResults.Items.Add("You win?!? NO FAIR!!! You cheated!!! I always win!!!")
End If
End Sub
Sub DisplayCards(ByVal userName As String, ByVal computer As String)
Select Case userName
Case Is = chkRock.Checked = 1
picUser.Image = Image.FromFile("rock.jpg")
Case Is = chkPaper.Checked = 2
picUser.Image = Image.FromFile("paper.png")
Case Is = chkScissors.Checked = 3
picUser.Image = Image.FromFile("scissors.jpeg")
Case Is = chkLizard.Checked = 4
picUser.Image = Image.FromFile("lizard.jpg")
Case Is = chkSpock.Checked = 5
picUser.Image = Image.FromFile("spock.jpg")
End Select
Select Case computer
Case Is = 1
picUser.Image = Image.FromFile("rock.jpg")
Case Is = 2
picUser.Image = Image.FromFile("paper.png")
Case Is = 3
picUser.Image = Image.FromFile("scissors.jpeg")
Case Is = 4
picUser.Image = Image.FromFile("lizard.jpg")
Case Is = 5
picUser.Image = Image.FromFile("spock.jpg")
End Select
End Sub
End Class
I was wondering how to fix this error. Also I had a couple of questions on how to add a couple of things in and where I should add them.
First, I'm not sure what to use or how to utilize where I need it, but what would I use to determine a number of rounds that are played between the computer and the user. Secondly, how would I put in and where would I put in what each result would me (e.g. rock smashes scissors, Spock disproves paper, ect.) I know I've got some work ahead of me but any help would be appreciated.
I'm going to upload my program to zippyshare for those who want to work with it hands on to help me. Thanks for all help in advance.
http://www67.zippyshare.com/v/44506790/file.html
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|