Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Need help with my VB 2012 code for a "Rock, Paper, Scissors, Lizard, Spock" Game

visual basic 2012 rock paper scissors lizard spock

  • Please log in to reply
1 reply to this topic

#1 jlh112586

jlh112586

    CC Lurker

  • New Member
  • Pip
  • 3 posts

Posted 30 November 2013 - 02:56 PM

Okay, for my last project in my class I'm to construct a game that follows these guidelines:
 
http://imageshack.co...1/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:

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)
                [b]lstResults.Items.Add("Computer's choice was " & randomNum)[/b]
            Case Is = chkPaper.Checked
                lstResults.Items.Clear()
                lstResults.Items.Add("The winner of this round is " & winner)
                lstResults.Items.Add("Your chose " & c2)
                [b]lstResults.Items.Add("Computer's choice was " & randomNum)[/b]
            Case Is = chkScissors.Checked
                lstResults.Items.Clear()
                lstResults.Items.Add("The winner of this round is " & winner)
                lstResults.Items.Add("Your chose " & c3)
                [b]lstResults.Items.Add("Computer's choice was " & randomNum)[/b]
            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)
                [b]lstResults.Items.Add("Computer's choice was " & randomNum)[/b]
        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 attach my program for those who want to work with it hands on to help me. Thanks for all help in advance.
 
 

Attached Files


  • 0

#2 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts
  • Location:Argentina
  • Programming Language:C, C++, C#, PHP, JavaScript, Transact-SQL, Bash, Others
  • Learning:Java, Others

Posted 04 December 2013 - 06:46 PM

I don't see the marks on what is not working, could you put it separated?

 

Then I wonder why  always use picuser for the image, even for the computer choice.


  • 0





Also tagged with one or more of these keywords: visual basic 2012, rock, paper, scissors, lizard, spock