Hi Guys!

Lately starting to make a project which involving calculations in it, Unfortunately I got some trouble because the calculation which is displayed out is wrong.

The main idea is that I set a event where you pay 5 "Gcoins" to play the "paper scissors stone" game against the computer. In the beginning you start off with 50 "Gcoins", and the initial score is 100; Each time if you win, add 20 to the initial score and add 10 "GCoins"; if it's a draw then add 10 to the initial score and 5 "GCoins"; if you lose then its add 0 to the initial score and add 0 "Gcoins", so every time after the result, the score is added up and the new amount of "GCoins" is added up(if you win of draw).So the Score and the "GCoins" accumulates each time playing. In the end there would be a score board which displays the score and a label which displays the amount of "GCoins".

The problems are
1.the result showing in label2 and richtextbox1 are wrong, the "GCoins" amount doesn't seem to go down or just increasing in large amount.
2.Is there anyway to set a limit to the amount of scores and "GCoins"?
3.When running the program, the result shows that it is more likely to draw. So is my situation set in the code equal chance?

here is my code.

Public Class Form1
    Dim timercount1 As Integer = 80
    Dim scorepoint As Integer
    Dim scorepointconstant As Integer = 100
    Dim GcoinPoints As Integer
    Dim gcoinpoints2 As Integer
    Dim Gcoinconstant As Integer = 50
    Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label2.Text = Gcoinconstant.ToString
        RichTextBox1.Text = scorepointconstant.ToString
    End Sub
    
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        r1 = Rnd()
        r2 = Rnd()
        Gcoinspoints += Gcoinconstant - 5
        If r1 < r2 Then
            Label1.Text = "You win"
            MessageBox.Show("You win")
            scorepoint += scorepointconstant + 20
            RichTextBox1.Text = scorepoint.ToString
            GcoinPoints += 10 + Gcoinconstant
            gcoinpoints2 = GcoinPoints
            Label2.Text = gcoinpoints2.ToString()
        End If

        If r1 = r2 Then
            Label1.Text = "Draw"
            MessageBox.Show("Draw")
            scorepoint += scorepointconstant + 10
            RichTextBox1.Text = scorepoint.ToString
            GcoinPoints += 5 + Gcoinconstant
            gcoinpoints2 = GcoinPoints
            Label2.Text = gcoinpoints2.ToString()
        End If

        If r1 > r2 Then
            Label1.Text = "You lose"
            MessageBox.Show("You lose")
            scorepoint += scorepointconstant + 0
            RichTextBox1.Text = scorepoint
            GcoinPoints += 0 + Gcoinconstant
            gcoinpoints2 = GcoinPoints
            Label2.Text = gcoinpoints2.ToString()
        End If
    End Sub

Any Help would be appreciated. Thank you

Why do you add 45 to GcoinPoints every time you click the button, regardless if you win or lose?

This is three losing rounds:
First round: GcoinPoints = 45
Second round GcoinPoints = 90
Third round GcoinPoints = 135

That could be the reason for problem 1, that the score is increasing in large chunks.
For problem 3, try to limit the random generator to choose between a set number of integers, like 1-10.
That would probably increase the odds.

Dim rnd As New Random
Dim value1 As Integer = rnd.Next(1, 10)
Dim value2 As Integer = rnd.Next(1, 10)

So this part of the code is wrong?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
        Gcoinspoints += Gcoinconstant - 5

Then how is it to code it so Every time before u play, you have to pay 5 GCoins then?

Change it to this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click      
   If Gcoinspoint <= 0 Then
      'Here you can choose to reset Gcoinspoints to 50
   End If
   Gcoinspoint -= 5

Sorry, the part where u can limit the random generator part with the code. It gives me an error when I coded in the form.

Dim rnd As New RandomDim value1 As Integer = rnd.Next(1, 10)Dim value2 As Integer = rnd.Next(1, 10)Dim rnd As New Random
Dim value1 As Integer = rnd.Next(1, 10)
Dim value2 As Integer = rnd.Next(1, 10)

The errors says the "the class 'System.Random' cannot be indexed because it has no default property"

Did I do something wrong?

According to the snippet you just posted, I'd have to say yes.
Change line 1 to simply say: Dim rnd As New Random().
And keep lines 2 and 3.

However when I put in the code it still gave me the same errors but it happens to occur at

r1 = Rnd()
        r2 = Rnd()

And then I deleted that part and my code now is

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim rnd As New Random()
        Dim value1 As Integer = rnd.Next(1, 10)
        Dim value2 As Integer = rnd.Next(1, 10)
        
        timercount1 = 80 'Reset to 80 seconds
        lblOutput.Text = timercount1.ToString() 'Reset the output display to 80
        Timer2.Enabled = True
        GcoinPoints = gcoinpoints2 - 5

        If value1 < value2 Then
            Label1.Text = "You win"
            MessageBox.Show("You win")
            scorepoint += scorepointconstant + 20
            RichTextBox1.Text = scorepoint.ToString
            GcoinPoints += 10 + Gcoinconstant
            gcoinpoints2 = GcoinPoints
            Label2.Text = gcoinpoints2.ToString()
        End If

        If value1 = r2 Then
            Label1.Text = "Draw"
            MessageBox.Show("Draw")
            scorepoint += scorepointconstant + 10
            RichTextBox1.Text = scorepoint.ToString
            GcoinPoints += 5 + Gcoinconstant
            gcoinpoints2 = GcoinPoints
            Label2.Text = gcoinpoints2.ToString()
        End If

        If value1 > value2 Then
            Label1.Text = "You lose"
            MessageBox.Show("You lose")
            scorepoint += scorepointconstant + 0
            RichTextBox1.Text = scorepoint
            GcoinPoints += Gcoinconstant
            gcoinpoints2 = GcoinPoints
            Label2.Text = gcoinpoints2.ToString()
        End If
    End Sub

When I Tested it, I found out that the draw result doesn't seem to come out anymore, Is it suppose to be like this?

I'm not surprised.

'Change this line
If value1 = r2 Then
' to this
If value1 = value2 Then
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.