Results 1 to 3 of 3

Thread: Need some help with a Rock Paper Scissors Lizard Spock game

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2013
    Posts
    2

    Need some 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

  2. #2
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Need some help with a Rock Paper Scissors Lizard Spock game

    randomNum will probably need to be an Integer, and where you have bold, needs to be converted to string. So where ever you see "Your string here" & randomNum you will need "Your string here" & Convert.ToString(randomNum)

    Also you can create a function like so and have randomNum = GetRandom(0,2):

    vb.net Code:
    1. Public Function GetRandom(ByVal Min As Integer, ByVal Max As Integer) As Integer
    2.     Dim Generator As System.Random = New System.Random()
    3.     Return Generator.Next(Min, Max)
    4. End Function

    Or you could do the old VB6 way in VB.Net and use Rnd(), but to make Rnd truely random, you would need to use Randomize in your Form_Load

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Need some help with a Rock Paper Scissors Lizard Spock game

    Quote Originally Posted by Jacob Roman View Post
    randomNum will probably need to be an Integer, and where you have bold, needs to be converted to string. So where ever you see "Your string here" & randomNum you will need "Your string here" & Convert.ToString(randomNum)
    That's not true. It would be true if the OP was using the + operator but the & operator is defined for types String and Integer, so the code as is has no issues there.

    The issue here starts with the terrible variable names in the original code. Firstly, 'randomNum' for a variable that doesn't hold a random number. Um, no. Something like 'randomNumGen' maybe, given that it generates random numbers. Secondly, 'computer' does hold a random number, albeit in String form, so it should have a name that indicates as much. It doesn't store a computer but a number that represents the computers turn, so a better name is in order there too. Also, Next generates an Integer so that should be the type of your variable. You would then use the actual numeric variable in those bold lines rather than the Random variable.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width