Click here to Skip to main content
16,019,263 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am scrolling sequentially through the images like a physical wheel in an analog machine would. I have no idea how, but I know the physical machines are designed to make it more difficult to match up the higher-winning symbols.
How can I accomplish this in my code?
VB
<pre>#Region "Variables"
    Private P1, P2, P3 As Integer
    Private R1, R2, R3 As Integer
    Private Rand As New Random
    Private SW1, SW2, SW3 As New Stopwatch
    Private Cash As Integer = 100
#End Region

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ImageList1.Images.Add(My.Resources.Penny)
        ImageList1.Images.Add(My.Resources.Nickle)
        ImageList1.Images.Add(My.Resources.Dime)
        ImageList1.Images.Add(My.Resources.Quarter)
        ImageList1.Images.Add(My.Resources.Half_Dollar)
        ImageList1.Images.Add(My.Resources.Dollar)
        P1 = Rand.Next(0, 6)
        P2 = Rand.Next(0, 6)
        P3 = Rand.Next(0, 6)
        PictureBox1.Image = ImageList1.Images(P1)
        PictureBox2.Image = ImageList1.Images(P2)
        PictureBox3.Image = ImageList1.Images(P3)
        ScoreLbl.Text = "$" & Cash.ToString
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Label1.Text = ""
        Cash -= 1
        ScoreLbl.Text = "$" & Cash.ToString
        R1 = Rand.Next(1500, 2000)
        R2 = Rand.Next(2000, 2500)
        R3 = Rand.Next(2500, 3000)
        Timer1.Interval = 100
        Timer1.Start()
        Timer2.Interval = 100
        Timer2.Start()
        Timer3.Interval = 100
        Timer3.Start()
        Timer4.Start()
        SW1.Start()
        SW2.Start()
        SW3.Start()
        Button1.Enabled = False
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        P1 += 1
        If P1 > 5 Then
            P1 = 0
        End If
        PictureBox1.Image = ImageList1.Images(P1)
        PictureBox1.Image.Tag = P1
        Timer1.Interval += 20
        If SW1.ElapsedMilliseconds >= R1 Then
            SW1.Stop()
            SW1.Reset()
            Timer1.Stop()
        End If
    End Sub

    Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
        P2 += 1
        If P2 > 5 Then
            P2 = 0
        End If
        PictureBox2.Image = ImageList1.Images(P2)
        PictureBox2.Image.Tag = P2
        Timer2.Interval += 20
        If SW2.ElapsedMilliseconds >= R2 Then
            SW2.Stop()
            SW2.Reset()
            Timer2.Stop()
        End If
    End Sub

    Private Sub Timer3_Tick(sender As Object, e As EventArgs) Handles Timer3.Tick
        P3 += 1
        If P3 > 5 Then
            P3 = 0
        End If
        PictureBox3.Image = ImageList1.Images(P3)
        PictureBox3.Image.Tag = P3
        Timer3.Interval += 20
        If SW3.ElapsedMilliseconds >= R3 Then
            SW3.Stop()
            SW3.Reset()
            Timer3.Stop()
        End If
    End Sub

    Private Sub Timer4_Tick(sender As Object, e As EventArgs) Handles Timer4.Tick
        If SW1.IsRunning = False AndAlso SW2.IsRunning = False AndAlso SW3.IsRunning = False Then
            Timer1.Stop()
            Timer1.Enabled = False
            Timer2.Stop()
            Timer2.Enabled = False
            Timer3.Stop()
            Timer3.Enabled = False
            Timer4.Stop()
            Timer4.Enabled = False
            Score()
            Button1.Enabled = True
        End If

    End Sub

    Private Sub Score()
        Select Case True
            Case P1 = 0 And P2 = 0 And P3 = 0
                Label1.ForeColor = Color.Green
                Label1.Text = "You won $10!"
                Cash += 10
            Case P1 = 0 And P2 = 0 Or P2 = 0 And P3 = 0
                Label1.ForeColor = Color.Green
                Label1.Text = "You won $1!"
                Cash += 1

            Case P1 = 1 And P2 = 1 And P3 = 1
                Label1.ForeColor = Color.Green
                Label1.Text = "You won $20!"
                Cash += 20
            Case P1 = 1 And P2 = 1 Or P2 = 1 And P3 = 1
                Label1.ForeColor = Color.Green
                Label1.Text = "You won $2!"
                Cash += 2

            Case P1 = 2 And P2 = 2 And P3 = 2
                Label1.ForeColor = Color.Green
                Label1.Text = "You won $40!"
                Cash += 40
            Case P1 = 2 And P2 = 2 Or P2 = 2 And P3 = 2
                Label1.ForeColor = Color.Green
                Label1.Text = "You won $4!"
                Cash += 4

            Case P1 = 3 And P2 = 3 And P3 = 3
                Label1.ForeColor = Color.Green
                Label1.Text = "You won $80!"
                Cash += 80
            Case P1 = 3 And P2 = 3 Or P2 = 0 And P3 = 3
                Label1.ForeColor = Color.Green
                Label1.Text = "You won $8!"
                Cash += 8

            Case P1 = 4 And P2 = 4 And P3 = 4
                Label1.ForeColor = Color.Green
                Label1.Text = "You won $160!"
                Cash += 160
            Case P1 = 4 And P2 = 4 Or P2 = 4 And P3 = 4
                Label1.ForeColor = Color.Green
                Label1.Text = "You won $16!"
                Cash += 16

            Case P1 = 5 And P2 = 5 And P3 = 5
                Label1.ForeColor = Color.Green
                Label1.Text = "Jackpot! You won $10,000!"
                Cash += 10000
            Case P1 = 5 And P2 = 5 Or P2 = 5 And P3 = 5
                Label1.ForeColor = Color.Green
                Label1.Text = "You won $1000!"
                Cash += 1000

            Case Else
                Label1.ForeColor = Color.Red
                Label1.Text = "You lose!"
        End Select
        ScoreLbl.Text = "$" & Cash.ToString

    End Sub


What I have tried:

I have no idea what to try other than maybe preventing a match in Timer2 based on a random percentage or something.
Posted

If I had to rig the odds, I'd assign each symbol on the reel a percentage, with higher value items having a higher percentage.

Then when I span the reel, I'd generate a random number between 0 and 100 and make a collection of the reel symbols that failed to match or exceeded that percentage. Generate a second random number to select a symbol from that collection, and stop the reel on that. Because the collection would mostly exclude the higher value symbols, the chances of a "GOOD WIN" are reduced.

Tweaking the percentages alters the "rigging factor".
 
Share this answer
 
v2
This is what I came up with. Maybe I had a clue after all. :)
VB.NET
<pre>Public Class Form1
#Region "Variables"
    Private P1, P2, P3 As Integer
    Private R1, R2, R3 As Integer
    Private Rand As New Random
    Private SW1, SW2, SW3 As New Stopwatch
    Private Cash As Integer = 100
    Private Chance As Integer
#End Region

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ImageList1.Images.Add(My.Resources.Penny)
        ImageList1.Images.Add(My.Resources.Nickle)
        ImageList1.Images.Add(My.Resources.Dime)
        ImageList1.Images.Add(My.Resources.Quarter)
        ImageList1.Images.Add(My.Resources.Half_Dollar)
        ImageList1.Images.Add(My.Resources.Dollar)
        P1 = Rand.Next(0, 6)
        P2 = Rand.Next(0, 6)
        P3 = Rand.Next(0, 6)
        PictureBox1.Image = ImageList1.Images(P1)
        PictureBox2.Image = ImageList1.Images(P2)
        PictureBox3.Image = ImageList1.Images(P3)
        ScoreLbl.Text = "$" & Cash.ToString
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Label1.Text = ""
        Cash -= 1
        ScoreLbl.Text = "$" & Cash.ToString
        Chance = Rand.Next(0, 101)
        R1 = Rand.Next(1500, 2000)
        R2 = Rand.Next(2000, 2500)
        R3 = Rand.Next(2500, 3000)
        Timer1.Interval = 100
        Timer1.Start()
        Timer2.Interval = 100
        Timer2.Start()
        Timer3.Interval = 100
        Timer3.Start()
        Timer4.Start()
        SW1.Start()
        SW2.Start()
        SW3.Start()
        Button1.Enabled = False
    End Sub

#Region "Timers"
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        P1 += 1
        If P1 > 5 Then
            P1 = 0
        End If
        PictureBox1.Image = ImageList1.Images(P1)
        PictureBox1.Image.Tag = P1
        Timer1.Interval += 10
        If SW1.ElapsedMilliseconds >= R1 Then
            SW1.Stop()
            SW1.Reset()
            Timer1.Stop()
        End If
    End Sub

    Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
        P2 += 1
        If P2 > 5 Then
            P2 = 0
        End If
        PictureBox2.Image = ImageList1.Images(P2)
        PictureBox2.Image.Tag = P2
        Timer2.Interval += 10
        If SW2.ElapsedMilliseconds >= R2 Then
            If P2 = P1 Then
                'Chance = Rand.Next(0, 101)
                Select Case P1
                    Case 0
                        Allow2()
                    Case 1
                        If Chance < 80 Then
                            Allow2()
                        Else
                            R2 += 100
                            Exit Select
                        End If
                    Case 2
                        If Chance < 60 Then
                            Allow2()
                        Else
                            R2 += 100
                            Exit Select
                        End If
                    Case 3
                        If Chance < 40 Then
                            Allow2()
                        Else
                            R2 += 100
                            Exit Select
                        End If
                    Case 4
                        If Chance < 20 Then
                            Allow2()
                        Else
                            R2 += 100
                            Exit Select
                        End If
                    Case 5
                        If Chance < 10 Then
                            Allow2()
                        Else
                            R2 += 100
                            Exit Select
                        End If
                End Select
            Else
                Allow2()
            End If

        End If
    End Sub
    Private Sub Allow2()
        SW2.Stop()
        SW2.Reset()
        Timer2.Stop()
    End Sub

    Private Sub Timer3_Tick(sender As Object, e As EventArgs) Handles Timer3.Tick
        P3 += 1
        If P3 > 5 Then
            P3 = 0
        End If
        PictureBox3.Image = ImageList1.Images(P3)
        PictureBox3.Image.Tag = P3
        Timer3.Interval += 10
        If SW3.ElapsedMilliseconds >= R3 Then
            If P3 = P2 Then
                'Chance = Rand.Next(0, 101)
                Select Case P2
                    Case 0
                        Allow3()
                    Case 1
                        If Chance < 80 Then
                            Allow3()
                        Else
                            R3 += 100
                            Exit Select
                        End If
                    Case 2
                        If Chance < 60 Then
                            Allow3()
                        Else
                            R3 += 100
                            Exit Select
                        End If
                    Case 3
                        If Chance < 40 Then
                            Allow3()
                        Else
                            R3 += 100
                            Exit Select
                        End If
                    Case 4
                        If Chance < 20 Then
                            Allow3()
                        Else
                            R3 += 100
                            Exit Select
                        End If
                    Case 5
                        If Chance < 10 Then
                            Allow3()
                        Else
                            R3 += 100
                            Exit Select
                        End If
                End Select
            Else
                Allow3()
            End If
        End If
    End Sub
    Private Sub Allow3()
        SW3.Stop()
        SW3.Reset()
        Timer3.Stop()
    End Sub

    Private Sub Timer4_Tick(sender As Object, e As EventArgs) Handles Timer4.Tick
        If SW1.IsRunning = False AndAlso SW2.IsRunning = False AndAlso SW3.IsRunning = False Then
            Timer1.Stop()
            Timer1.Enabled = False
            Timer2.Stop()
            Timer2.Enabled = False
            Timer3.Stop()
            Timer3.Enabled = False
            Timer4.Stop()
            Timer4.Enabled = False
            Score()
            Button1.Enabled = True
        End If

    End Sub

#End Region

    Private Sub Score()
        Select Case True
            Case P1 = 0 And P2 = 0 And P3 = 0
                Label1.ForeColor = Color.Green
                Label1.Text = "You won $10!"
                Cash += 10
            Case P1 = 0 And P2 = 0 Or P2 = 0 And P3 = 0
                Label1.ForeColor = Color.Green
                Label1.Text = "You won $1!"
                Cash += 1

            Case P1 = 1 And P2 = 1 And P3 = 1
                Label1.ForeColor = Color.Green
                Label1.Text = "You won $20!"
                Cash += 20
            Case P1 = 1 And P2 = 1 Or P2 = 1 And P3 = 1
                Label1.ForeColor = Color.Green
                Label1.Text = "You won $2!"
                Cash += 2

            Case P1 = 2 And P2 = 2 And P3 = 2
                Label1.ForeColor = Color.Green
                Label1.Text = "You won $40!"
                Cash += 40
            Case P1 = 2 And P2 = 2 Or P2 = 2 And P3 = 2
                Label1.ForeColor = Color.Green
                Label1.Text = "You won $4!"
                Cash += 4

            Case P1 = 3 And P2 = 3 And P3 = 3
                Label1.ForeColor = Color.Green
                Label1.Text = "You won $80!"
                Cash += 80
            Case P1 = 3 And P2 = 3 Or P2 = 3 And P3 = 3
                Label1.ForeColor = Color.Green
                Label1.Text = "You won $8!"
                Cash += 8

            Case P1 = 4 And P2 = 4 And P3 = 4
                Label1.ForeColor = Color.Green
                Label1.Text = "You won $160!"
                Cash += 160
            Case P1 = 4 And P2 = 4 Or P2 = 4 And P3 = 4
                Label1.ForeColor = Color.Green
                Label1.Text = "You won $16!"
                Cash += 16

            Case P1 = 5 And P2 = 5 And P3 = 5
                Label1.ForeColor = Color.Green
                Label1.Text = "Jackpot! You won $10,000!"
                Cash += 10000
            Case P1 = 5 And P2 = 5 Or P2 = 5 And P3 = 5
                Label1.ForeColor = Color.Green
                Label1.Text = "You won $1000!"
                Cash += 1000

            Case Else
                Label1.ForeColor = Color.Red
                Label1.Text = "You lose!"
        End Select
        ScoreLbl.Text = "$" & Cash.ToString
    End Sub

End Class
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900