Adding score to Rock paper scissor game
Adding score to Rock paper scissor game
Adding score to Rock paper scissor game
Adding score to Rock paper scissor game
Adding score to Rock paper scissor game
Adding score to Rock paper scissor game Adding score to Rock paper scissor game Adding score to Rock paper scissor game Adding score to Rock paper scissor game Adding score to Rock paper scissor game Adding score to Rock paper scissor game Adding score to Rock paper scissor game Adding score to Rock paper scissor game
Adding score to Rock paper scissor game Adding score to Rock paper scissor game
Adding score to Rock paper scissor game
Go Back  Xtreme Visual Basic Talk > > > Adding score to Rock paper scissor game


Reply
 
Thread Tools Display Modes
  #1  
Old 10-03-2011, 04:38 AM
happyg01 happyg01 is offline
Newcomer
 
Join Date: Oct 2011
Posts: 4
Default Adding score to Rock paper scissor game


Im new to VB. how do I get to add the score.
my code is

If Rbscissors.Checked And number = scissor Then
lblanswer.Text = "computer threw scissors. Draw!"
ElseIf Rbscissors.Checked And number = Paper Then
lblanswer.Text = "Computer threw paper. You Win"
CpuScore = CpuScore + 1
ElseIf Rbscissors.Checked And number = Rock Then
lblanswer.Text = "Computer threw Rock. you lose."
YouLoseForm.Show()
Me.Close()
End If


Totalscore = CpuScore
Label1.Text = Totalscore

but wen it I win twice its still 1 point and wen it a draw its 0 points.

What do I need to change to make it work?
Reply With Quote
  #2  
Old 10-03-2011, 07:26 AM
AtmaWeapon's Avatar
AtmaWeaponAdding score to Rock paper scissor game AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

You didn't show enough code for anything but a psychic answer. Here's my psychic guess:

I bet CpuScore and TotalScore are local varibles. So every time the Sub that code is in runs, they start over at 0. If they were class variables they'd retain their value. I'd go into more detail but I need to see more code to see if it's worth it. Please use the [code] tag in the future when posting code.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 10-03-2011, 09:07 AM
happyg01 happyg01 is offline
Newcomer
 
Join Date: Oct 2011
Posts: 4
Default

Code:
Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
        Randomize()

        Dim number As Integer
        Dim CpuScore As Integer
        Dim Totalscore As Integer

        CpuScore = 0

        Const Rock As Integer = 1
        Const Paper As Integer = 2
        Const scissor As Integer = 3

        number = (3 * Rnd())

        If Rbrock.Checked And number = Rock Then
            lblanswer.Text = "Computer threw rock. DRAW!"
        ElseIf Rbrock.Checked And number = scissor Then
            lblanswer.Text = "Computer threw scissor. YOU WIN"
            CpuScore = CpuScore + 1
        ElseIf Rbrock.Checked And number = Paper Then
            lblanswer.Text = "Computer threw paper. You LOSE"
            YouLoseForm.Show()
            Me.Close()
        End If



        If rbpaper.Checked And number = Paper Then
            lblanswer.Text = "Computer threw paper. Draw!"
        ElseIf rbpaper.Checked And number = Rock Then
            lblanswer.Text = "Computer threw rock. You Win"
            CpuScore = CpuScore + 1
        ElseIf rbpaper.Checked And number = scissor Then
            lblanswer.Text = "Computer threw scissors. You lose"
            YouLoseForm.Show()
            Me.Close()
        End If


        If Rbscissors.Checked And number = scissor Then
            lblanswer.Text = "computer threw scissors. Draw!"
        ElseIf Rbscissors.Checked And number = Paper Then
            lblanswer.Text = "Computer threw paper. You Win"
            CpuScore = CpuScore + 1
        ElseIf Rbscissors.Checked And number = Rock Then
            lblanswer.Text = "Computer threw Rock. you lose."
            YouLoseForm.Show()
            Me.Close()
        End If


        Totalscore = CpuScore
        Label1.Text = Totalscore
here the code 4 that form

Last edited by Flyguy; 10-03-2011 at 10:33 AM. Reason: Please use the [code][/code] tags!
Reply With Quote
  #4  
Old 10-03-2011, 10:23 AM
AtmaWeapon's Avatar
AtmaWeaponAdding score to Rock paper scissor game AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Well since you didn't follow the more important suggestion ("use the [code] tag") I'll be a little brief with my answer.

Meditate on this line:
Code:
CpuScore = 0
That line ensures CpuScore can only have the value 0 or 1 by the end of the method. Can you figure out why?
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #5  
Old 10-05-2011, 07:24 AM
happyg01 happyg01 is offline
Newcomer
 
Join Date: Oct 2011
Posts: 4
Default

does that mean the score will stay as 0 because cpuscore will always be 0.
Reply With Quote
  #6  
Old 10-05-2011, 04:04 PM
passel's Avatar
passelAdding score to Rock paper scissor game passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,028
Default

Unfortunately it is very wearying to have to cover the very basic basics of BASIC when dealing with posts. We understand you are new, but you really need to find a book, or tutorials, to start learning any language in a fairly straight forward way, rather than just jump in with coding, most likely copy and paste coding, with little comprehension of what the code does, how it is organized, etc.

There is the matter of the "scope" of the variables. Scope refers to both how long the variables exist and where they can be referenced.
AtmaWeapon gave good suggestions concerning your situation, but without understanding how the language works, the suggestions obviously were incomprehensible to you and simply ignored.
That is one of the frustrating parts for us.

So, in review of and quoting from AtmaWeapons earlier posts:

"I bet CpuScore and TotalScore are local varibles."
...Did you know if the the variables were local or not?
...Do you know what being local means?
...Did you think to yourself, "This means nothing to me, so it means nothing."?

"So every time the Sub that code is in runs, they start over at 0. "
...Did that sentence sound ominous to you?
...Is resetting those values to 0 everytime you press the button desirable?

"If they were class variables they'd retain their value."
...Do you know what "retain their value" means? It means they won't be reset to 0 each time you press the button.
...Do you know how to make the variables "class variables" rather than local variables? Tutorial on variable scope should be helpful.

"CpuScore = 0"
...Even if CpuScore was a "class variable" so retained the value of 1 from the previous round (button press), how would "clobbering" the 1 with a 0 everytime you pressed the button help CpuScore to accumlate a score?

There are other problems, essentially, with the code, such as the use of Randomize every time you press the button. Randomize, if used, should only be called once, in the lifetime of your program.
But, it really shouldn't be used at all in .Net, you should use the Random class and avoid using Randomize and Rnd(). Look it up.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 10-05-2011 at 04:15 PM.
Reply With Quote
  #7  
Old 11-02-2011, 07:37 PM
thillryan's Avatar
thillryan thillryan is offline
Newcomer
 
Join Date: Oct 2011
Location: Kansas
Posts: 15
Default

I used labels to display the score and the code:
Code:
Label1.text = Val(Label1.text) + 1
Reply With Quote
Reply


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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Adding score to Rock paper scissor game
Adding score to Rock paper scissor game
Adding score to Rock paper scissor game Adding score to Rock paper scissor game
Adding score to Rock paper scissor game
Adding score to Rock paper scissor game
Adding score to Rock paper scissor game Adding score to Rock paper scissor game Adding score to Rock paper scissor game Adding score to Rock paper scissor game Adding score to Rock paper scissor game Adding score to Rock paper scissor game Adding score to Rock paper scissor game
Adding score to Rock paper scissor game
Adding score to Rock paper scissor game
 
Adding score to Rock paper scissor game
Adding score to Rock paper scissor game
 
-->