Adding Sizzle to a Video Slot Game with VB.NET

Introduction

In the previous two installments of this series we have concentrated on how things work, and making the logic work. With this final part, we will build in a way to win or lose, as well as add some effects when a win takes place. We will also polish off this article, so that everything works as it should, and that it is a real working game.

Design

Not much to do here. We just need to add a place where we can notify the user that he / she has won or lost and a way to add credits. Let us add the following to the form :

ControlPropertySetting
Button Name btnAddMoreCredits
  Location 554, 175
  Text Add Credits
Button Name btnPayOut
  Location 554, 204
  Text Pay Out
PictureBox Name picScore
  Location 24, 470
  Size 372, 50

Code

As usual, let us add all the necessary objects to our General Declarations section :

    Private arrAnimImages(9) As Image 'Array for GIF Animatd images
    Private Winnings As Integer 'Total winnings
    Private MaxBet As Boolean 'Max Bet / Normal Bet
    Private ColCounter As Integer 'Column match counter
    Private LineWinnings As Integer 'How much won per line
    Private ColWinnings As Integer 'How much won per column
    Private MainLineWinnings As Integer 'How much won for MAIN lines
    Private MainLineWinnings2 As Integer 'How much won for part of MAIN line
    Private MainLineCounter2 As Integer 'Part of MAIN line match counter

The bulk of our work now is to get our animations to work. These files were downloaded from the internet, I did not create them. I chose to make use of GIF files here, to show you how easy it is to add tiny animations to your projects. You do not always need additional libraries or long pieces of code to do it - the PictureBox in VS 2010 is extremely capable of handling animations. All you need to do is to set its Image property to the appropriate image, and voila, the animation will start! Be careful though, some GIF files might not be saved correctly, so then, and only then, the PictureBox will have issues displaying them. Initialize them inside Form_Load, under the arrImages array :

        'Load GIF files for animation purposes
        arrAnimImages(0) = My.Resources.applesmall
        arrAnimImages(1) = My.Resources.bananasmall
        arrAnimImages(2) = My.Resources.cherry2
        arrAnimImages(3) = My.Resources.fruitbowlz
        arrAnimImages(4) = My.Resources.grapesmall
        arrAnimImages(5) = My.Resources.lemonsmall
        arrAnimImages(6) = My.Resources.orangesmall
        arrAnimImages(7) = My.Resources.strawberrysmall
        arrAnimImages(8) = My.Resources.Kiwi
        arrAnimImages(9) = My.Resources.Pineapple_jumps

These files were also added to the project's Resources, but feel free to use your own.

Because these animations should play once a winning combination has been struck, we need to edit our existing subs to accommodate this feature. Change your CheckMainLines and CheckRows as follows :

    Private Sub CheckMainLines()

        For i As Integer = 0 To 9
            'Line 1
            '0	0	0	0	0
            If Column1(0).Image Is arrImages(i) And Column2(0).Image Is arrImages(i) And Column3(0).Image Is arrImages(i) And Column4(0).Image Is arrImages(i) And Column5(0).Image Is arrImages(i) Then
                ' Line 1 Match
                Column1(0).Image = arrAnimImages(i)
                Column2(0).Image = arrAnimImages(i)
                Column3(0).Image = arrAnimImages(i)
                Column4(0).Image = arrAnimImages(i)
                Column5(0).Image = arrAnimImages(i)
                MainLineCounter += 1 'Increment counter

                'Line 2
                '1	1	1	1	1
            ElseIf Column1(1).Image Is arrImages(i) And Column2(1).Image Is arrImages(i) And Column3(1).Image Is arrImages(i) And Column4(1).Image Is arrImages(i) And Column5(1).Image Is arrImages(i) Then
                ' Line 2 Match
                Column1(1).Image = arrAnimImages(i)
                Column2(1).Image = arrAnimImages(i)
                Column3(1).Image = arrAnimImages(i)
                Column4(1).Image = arrAnimImages(i)
                Column5(1).Image = arrAnimImages(i)
                MainLineCounter += 1

                'Line 3
                '2	2	2	2	2
            ElseIf Column1(2).Image Is arrImages(i) And Column2(2).Image Is arrImages(i) And Column3(2).Image Is arrImages(i) And Column4(2).Image Is arrImages(i) And Column5(2).Image Is arrImages(i) Then
                ' Line 3 Match
                Column1(2).Image = arrAnimImages(i)
                Column2(2).Image = arrAnimImages(i)
                Column3(2).Image = arrAnimImages(i)
                Column4(2).Image = arrAnimImages(i)
                Column5(2).Image = arrAnimImages(i)
                MainLineCounter += 1

                'Line 4
                '3	3	3	3	3
            ElseIf Column1(3).Image Is arrImages(i) And Column2(3).Image Is arrImages(i) And Column3(3).Image Is arrImages(i) And Column4(3).Image Is arrImages(i) And Column5(3).Image Is arrImages(i) Then
                ' Line 4 Match
                Column1(3).Image = arrAnimImages(i)
                Column2(3).Image = arrAnimImages(i)
                Column3(3).Image = arrAnimImages(i)
                Column4(3).Image = arrAnimImages(i)
                Column5(3).Image = arrAnimImages(i)
                MainLineCounter += 1

                'Line 5
                '3	2	1	2	3
            ElseIf Column1(3).Image Is arrImages(i) And Column2(2).Image Is arrImages(i) And Column3(1).Image Is arrImages(i) And Column4(2).Image Is arrImages(i) And Column5(3).Image Is arrImages(i) Then
                ' Line 5 Match
                Column1(3).Image = arrAnimImages(i)
                Column2(2).Image = arrAnimImages(i)
                Column3(1).Image = arrAnimImages(i)
                Column4(2).Image = arrAnimImages(i)
                Column5(3).Image = arrAnimImages(i)
                MainLineCounter += 1

                'Line 6
                '0	1	2	1	0
            ElseIf Column1(0).Image Is arrImages(i) And Column2(1).Image Is arrImages(i) And Column3(2).Image Is arrImages(i) And Column4(1).Image Is arrImages(i) And Column5(0).Image Is arrImages(i) Then
                ' Line 6 Match
                Column1(0).Image = arrAnimImages(i)
                Column2(1).Image = arrAnimImages(i)
                Column3(2).Image = arrAnimImages(i)
                Column4(1).Image = arrAnimImages(i)
                Column5(0).Image = arrAnimImages(i)
                MainLineCounter += 1

                'Line 7
                '1	0	1	0	1
            ElseIf Column1(1).Image Is arrImages(i) And Column2(0).Image Is arrImages(i) And Column3(1).Image Is arrImages(i) And Column4(0).Image Is arrImages(i) And Column5(1).Image Is arrImages(i) Then
                ' Line 7 Match
                Column1(1).Image = arrAnimImages(i)
                Column2(0).Image = arrAnimImages(i)
                Column3(1).Image = arrAnimImages(i)
                Column4(0).Image = arrAnimImages(i)
                Column5(1).Image = arrAnimImages(i)
                MainLineCounter += 1

                'Line 8
                '2	3	2	3	2
            ElseIf Column1(2).Image Is arrImages(i) And Column2(3).Image Is arrImages(i) And Column3(2).Image Is arrImages(i) And Column4(3).Image Is arrImages(i) And Column5(2).Image Is arrImages(i) Then
                ' Line 8 Match
                Column1(2).Image = arrAnimImages(i)
                Column2(3).Image = arrAnimImages(i)
                Column3(2).Image = arrAnimImages(i)
                Column4(3).Image = arrAnimImages(i)
                Column5(2).Image = arrAnimImages(i)
                MainLineCounter += 1

                'Line 9
                '2	1	1	1	2
            ElseIf Column1(2).Image Is arrImages(i) And Column2(1).Image Is arrImages(i) And Column3(1).Image Is arrImages(i) And Column4(1).Image Is arrImages(i) And Column5(2).Image Is arrImages(i) Then
                ' Line 9 Match
                Column1(2).Image = arrAnimImages(i)
                Column2(1).Image = arrAnimImages(i)
                Column3(1).Image = arrAnimImages(i)
                Column4(1).Image = arrAnimImages(i)
                Column5(2).Image = arrAnimImages(i)
                MainLineCounter += 1


            End If
        Next

        If MainLineCounter > SelLines Then MainLineCounter = SelLines

        If MainLineCounter > 0 And MainLineCounter < 10 Then
            If Not MaxBet Then
                MainLineWinnings = MainLineCounter * 15 + Bet
            Else
                MainLineWinnings = MainLineCounter * 30 + (Bet * 2)
            End If
        Else
            MainLineCounter = 0
            MainLineWinnings = 0
            Winnings = 0
        End If
    End Sub
    
    Private Sub CheckRows()

        For i As Integer = 0 To 9
            If Column1(0).Image Is arrImages(i) And Column2(0).Image Is arrImages(i) And Column3(0).Image Is arrImages(i) Then
                ' Row 1 Match 1
                ' Three possible matches
                Column1(0).Image = arrAnimImages(i)
                Column2(0).Image = arrAnimImages(i)
                Column3(0).Image = arrAnimImages(i)
                LineCounter += 1
            ElseIf Column2(0).Image Is arrImages(i) And Column3(0).Image Is arrImages(i) And Column4(0).Image Is arrImages(i) Then
                ' Row 1 Match 2
                Column2(0).Image = arrAnimImages(i)
                Column3(0).Image = arrAnimImages(i)
                Column4(0).Image = arrAnimImages(i)
                LineCounter += 1
            ElseIf Column3(0).Image Is arrImages(i) And Column4(0).Image Is arrImages(i) And Column5(0).Image Is arrImages(i) Then
                ' Row 1 Match 3
                Column3(0).Image = arrAnimImages(i)
                Column4(0).Image = arrAnimImages(i)
                Column5(0).Image = arrAnimImages(i)
                LineCounter += 1

            ElseIf Column1(1).Image Is arrImages(i) And Column2(1).Image Is arrImages(i) And Column3(1).Image Is arrImages(i) Then
                ' Row 2 Match 1
                Column1(1).Image = arrAnimImages(i)
                Column2(1).Image = arrAnimImages(i)
                Column3(1).Image = arrAnimImages(i)
                LineCounter += 1
            ElseIf Column2(1).Image Is arrImages(i) And Column3(1).Image Is arrImages(i) And Column4(1).Image Is arrImages(i) Then
                ' Row 2 Match 2
                Column2(1).Image = arrAnimImages(i)
                Column3(1).Image = arrAnimImages(i)
                Column4(1).Image = arrAnimImages(i)
                LineCounter += 1
            ElseIf Column3(1).Image Is arrImages(i) And Column4(1).Image Is arrImages(i) And Column5(1).Image Is arrImages(i) Then
                ' Row 2 Match 3
                Column3(1).Image = arrAnimImages(i)
                Column4(1).Image = arrAnimImages(i)
                Column5(1).Image = arrAnimImages(i)
                LineCounter += 1

            ElseIf Column1(2).Image Is arrImages(i) And Column2(2).Image Is arrImages(i) And Column3(2).Image Is arrImages(i) Then
                ' Row 3 Match 1
                Column1(2).Image = arrAnimImages(i)
                Column2(2).Image = arrAnimImages(i)
                Column3(2).Image = arrAnimImages(i)
                LineCounter += 1
            ElseIf Column2(2).Image Is arrImages(i) And Column3(2).Image Is arrImages(i) And Column4(2).Image Is arrImages(i) Then
                ' Row 3 Match 2
                Column2(2).Image = arrAnimImages(i)
                Column3(2).Image = arrAnimImages(i)
                Column4(2).Image = arrAnimImages(i)
                LineCounter += 1
            ElseIf Column3(2).Image Is arrImages(i) And Column4(2).Image Is arrImages(i) And Column5(2).Image Is arrImages(i) Then
                ' Row 3 Match 3
                Column3(2).Image = arrAnimImages(i)
                Column4(2).Image = arrAnimImages(i)
                Column5(2).Image = arrAnimImages(i)
                LineCounter += 1

            ElseIf Column1(3).Image Is arrImages(i) And Column2(3).Image Is arrImages(i) And Column3(3).Image Is arrImages(i) Then
                ' Row 4 Match 1
                Column1(3).Image = arrAnimImages(i)
                Column2(3).Image = arrAnimImages(i)
                Column3(3).Image = arrAnimImages(i)
                LineCounter += 1
            ElseIf Column2(3).Image Is arrImages(i) And Column3(3).Image Is arrImages(i) And Column4(3).Image Is arrImages(i) Then
                ' Row 4 Match 2
                Column2(3).Image = arrAnimImages(i)
                Column3(3).Image = arrAnimImages(i)
                Column4(3).Image = arrAnimImages(i)
                LineCounter += 1
            ElseIf Column3(3).Image Is arrImages(i) And Column4(3).Image Is arrImages(i) And Column5(3).Image Is arrImages(i) Then
                ' Row 4 Match 3
                Column3(3).Image = arrAnimImages(i)
                Column4(3).Image = arrAnimImages(i)
                Column5(3).Image = arrAnimImages(i)
                LineCounter += 1
            End If
        Next
        '''''''''''''''''''''''''''''''''''''''

        If LineCounter > SelLines Then LineCounter = SelLines

        If LineCounter > 0 And LineCounter < 10 Then
            If Not MaxBet Then
                LineWinnings = LineCounter * 2 + Bet
            Else
                LineWinnings = LineCounter * 4 + (Bet * 2)
            End If
        Else
            LineCounter = 0
            LineWinnings = 0
            Winnings = 0
        End If
    End Sub

Adding Sizzle to a Video Slot Game with VB.NET - Page 2

Now, edit your CheckCols sub, and yes, I remembered to add the ColCount counter. :) :

    Private Sub CheckCols()

        For i As Integer = 0 To 9
            If Column1(0).Image Is arrImages(i) And Column1(1).Image Is arrImages(i) And Column1(2).Image Is arrImages(i) Then
                ' Column 1 Match 1
                Column1(0).Image = arrAnimImages(i)
                Column1(1).Image = arrAnimImages(i)
                Column1(2).Image = arrAnimImages(i)
                ColCounter += 1 'Increment column counter
            ElseIf Column1(1).Image Is arrImages(i) And Column1(2).Image Is arrImages(i) And Column1(3).Image Is arrImages(i) Then
                ' Column 1 Match 2
                'Two possible matches
                Column1(1).Image = arrAnimImages(i)
                Column1(2).Image = arrAnimImages(i)
                Column1(3).Image = arrAnimImages(i)
                ColCounter += 1

            ElseIf Column2(0).Image Is arrImages(i) And Column2(1).Image Is arrImages(i) And Column2(2).Image Is arrImages(i) Then
                ' Column 2 Match 1
                Column2(0).Image = arrAnimImages(i)
                Column2(1).Image = arrAnimImages(i)
                Column2(2).Image = arrAnimImages(i)
                ColCounter += 1
            ElseIf Column2(1).Image Is arrImages(i) And Column2(2).Image Is arrImages(i) And Column2(3).Image Is arrImages(i) Then
                ' Column 2 Match 2
                Column2(1).Image = arrAnimImages(i)
                Column2(2).Image = arrAnimImages(i)
                Column2(3).Image = arrAnimImages(i)
                ColCounter += 1

            ElseIf Column3(0).Image Is arrImages(i) And Column3(1).Image Is arrImages(i) And Column3(2).Image Is arrImages(i) Then
                ' Column 3 Match 1
                Column3(0).Image = arrAnimImages(i)
                Column3(1).Image = arrAnimImages(i)
                Column3(2).Image = arrAnimImages(i)
                ColCounter += 1
            ElseIf Column3(1).Image Is arrImages(i) And Column3(2).Image Is arrImages(i) And Column3(3).Image Is arrImages(i) Then
                ' Column 3 Match 2
                Column3(1).Image = arrAnimImages(i)
                Column3(2).Image = arrAnimImages(i)
                Column3(3).Image = arrAnimImages(i)
                ColCounter += 1

            ElseIf Column4(0).Image Is arrImages(i) And Column4(1).Image Is arrImages(i) And Column4(2).Image Is arrImages(i) Then
                ' Column 4 Match 1
                Column4(0).Image = arrAnimImages(i)
                Column4(1).Image = arrAnimImages(i)
                Column4(2).Image = arrAnimImages(i)
                ColCounter += 1
            ElseIf Column4(1).Image Is arrImages(i) And Column4(2).Image Is arrImages(i) And Column4(3).Image Is arrImages(i) Then
                ' Column 4 Match 2
                Column4(1).Image = arrAnimImages(i)
                Column4(2).Image = arrAnimImages(i)
                Column4(3).Image = arrAnimImages(i)
                ColCounter += 1

            ElseIf Column5(0).Image Is arrImages(i) And Column5(1).Image Is arrImages(i) And Column5(2).Image Is arrImages(i) Then
                ' Column 5 Match 1
                Column5(0).Image = arrAnimImages(i)
                Column5(1).Image = arrAnimImages(i)
                Column5(2).Image = arrAnimImages(i)
                ColCounter += 1
            ElseIf Column5(1).Image Is arrImages(i) And Column5(2).Image Is arrImages(i) And Column5(3).Image Is arrImages(i) Then
                ' Column 5 Match 2
                Column5(1).Image = arrAnimImages(i)
                Column5(2).Image = arrAnimImages(i)
                Column5(3).Image = arrAnimImages(i)
                ColCounter += 1
            End If
        Next

        If ColCounter > 0 And ColCounter < 6 Then
            If Not MaxBet Then
                ColWinnings = ColCounter * 5 + Bet
            Else
                ColWinnings = ColCounter * 10 + (Bet * 2)
            End If
        Else
            ColCounter = 0
            ColWinnings = 0
            Winnings = 0
        End If
    End Sub

Lastly, add this new sub :

    Private Sub CheckMainLines2() 'Determine match in part of MAIN line
        For i As Integer = 0 To 9
            'Line 1 to 4 alrady done with checklines

            'Line 5
            '3	2	1	2	3
            If Column1(3).Image Is arrImages(i) And Column2(2).Image Is arrImages(i) _
                And Column3(1).Image Is arrImages(i) Then
                ' If match was found, replace matched imaged with animated gifs - to give more visual appeal when something was won
                ' Deleted MessageBoxes
                ' Match 1
                Column1(3).Image = arrAnimImages(i)
                Column2(2).Image = arrAnimImages(i)
                Column3(1).Image = arrAnimImages(i)
                MainLineCounter2 += 1 'Increment counter
            ElseIf Column3(1).Image Is arrImages(i) And Column4(2).Image Is arrImages(i) _
                And Column5(3).Image Is arrImages(i) Then
                'Match 2
                Column3(1).Image = arrAnimImages(i)
                Column4(2).Image = arrAnimImages(i)
                Column5(3).Image = arrAnimImages(i)
                MainLineCounter2 += 1

                'Line 6
                '0	1	2	1	0
            ElseIf Column1(0).Image Is arrImages(i) And Column2(1).Image Is arrImages(i) _
                And Column3(2).Image Is arrImages(i) Then
                'Line 6 Match 1
                Column1(0).Image = arrAnimImages(i)
                Column2(1).Image = arrAnimImages(i)
                Column3(2).Image = arrAnimImages(i)
                MainLineCounter2 += 1
            ElseIf Column3(2).Image Is arrImages(i) And Column4(1).Image Is arrImages(i) _
                And Column5(0).Image Is arrImages(i) Then
                ' Line 6 Match 2
                Column3(2).Image = arrAnimImages(i)
                Column4(1).Image = arrAnimImages(i)
                Column5(0).Image = arrAnimImages(i)
                MainLineCounter2 += 1

                'Line 7
                '1	0	1	0	1
            ElseIf Column1(1).Image Is arrImages(i) And Column2(0).Image Is arrImages(i) _
                And Column3(1).Image Is arrImages(i) Then
                ' Line 7 Match 1
                Column1(1).Image = arrAnimImages(i)
                Column2(0).Image = arrAnimImages(i)
                Column3(1).Image = arrAnimImages(i)
                MainLineCounter2 += 1
            ElseIf Column3(1).Image Is arrImages(i) And Column4(0).Image Is arrImages(i) _
                And Column5(1).Image Is arrImages(i) Then
                ' Line 7 Match 2
                Column3(1).Image = arrAnimImages(i)
                Column4(0).Image = arrAnimImages(i)
                Column5(1).Image = arrAnimImages(i)
                MainLineCounter2 += 1

                'Line 8
                '2	3	2	3	2
            ElseIf Column1(2).Image Is arrImages(i) And Column2(3).Image Is arrImages(i) _
                And Column3(2).Image Is arrImages(i) Then
                ' Line 8 Match 1
                Column1(2).Image = arrAnimImages(i)
                Column2(3).Image = arrAnimImages(i)
                Column3(2).Image = arrAnimImages(i)
                MainLineCounter2 += 1
            ElseIf Column3(2).Image Is arrImages(i) And Column4(3).Image Is arrImages(i) _
                And Column5(2).Image Is arrImages(i) Then
                ' Line 8 Match 2
                Column3(2).Image = arrAnimImages(i)
                Column4(3).Image = arrAnimImages(i)
                Column5(2).Image = arrAnimImages(i)
                MainLineCounter2 += 1

                'Line 9
                '2	1	1	1	2
            ElseIf Column1(2).Image Is arrImages(i) And Column2(1).Image Is arrImages(i) _
                And Column3(1).Image Is arrImages(i) Then
                ' Line 9 Match 1
                Column1(2).Image = arrAnimImages(i)
                Column2(1).Image = arrAnimImages(i)
                Column3(1).Image = arrAnimImages(i)
                MainLineCounter2 += 1

            ElseIf Column3(1).Image Is arrImages(i) And Column4(1).Image Is arrImages(i) _
                And Column5(2).Image Is arrImages(i) Then
                ' Line 9 Match 2
                Column3(1).Image = arrAnimImages(i)
                Column4(1).Image = arrAnimImages(i)
                Column5(2).Image = arrAnimImages(i)
                MainLineCounter2 += 1
            End If
        Next

        'Ensure that winning lines cannot be more than what was chosen
        If MainLineCounter2 > SelLines Then MainLineCounter2 = SelLines

        'Ensure Counter is between 0 and 9
        If MainLineCounter2 > 0 And MainLineCounter2 < 10 Then
            If Not MaxBet Then 'If normal bet
                MainLineWinnings2 = MainLineCounter2 * 15 + Bet 'Calculate winnings
            Else
                MainLineWinnings2 = MainLineCounter2 * 30 + (Bet * 2) 'Max bet is much more
            End If
        Else
            MainLineCounter2 = 0 'Reset all counters
            MainLineWinnings2 = 0
            Winnings = 0
        End If
    End Sub

OK, I have some explaining to do!

You will notice in each of these four subs, I have a similar IF statement at the bottom. This ensures that the winning lines cannot exceed the number of lines chosen. We also calculate our winnings according to what type of bet has taken place, then we simply reset all the necessary counters - to be able to start afresh every time.

The new sub that I have added checks part of the MAIN lines, which is only fair because with the columns and the normal lines, I do the same. I compensate for each possible match, according to this program.

Edit the tmrPause_Tick event to call the WinningsInfo sub as well, it should resemble the following:

            ''''''''''''''''''''''''''
            ''Part 2
            CheckMainLines()
            CheckCols()
            CheckRows()
            '''''''''''''''''''''''''''''

            WinningsInfo() 'Display winnings

Let us create the WinningsInfo sub :

    Private Sub WinningsInfo() 'Determine winnings and display it
        Dim strWinnings As String

        Winnings = LineWinnings + ColWinnings + MainLineWinnings + MainLineWinnings2 'Calculate from all sources

        Credits += Winnings 'Update credits
        lblCredits.Text = Credits

        If Winnings > 0 Then 'Won something?
            strWinnings = "You WON " & Winnings.ToString & "!!!" 'Display amount

            'reset all counters to 0
            Winnings = 0
            MainLineWinnings = 0
            MainLineWinnings2 = 0
            ColWinnings = 0
            LineWinnings = 0
            LineCounter = 0
            ColCounter = 0
            MainLineCounter = 0
            MainLineCounter2 = 0
        Else
            strWinnings = "You LOSE! Hahaha!" 'Nothing won
        End If


        Dim brHTGSlots As Brush = Brushes.Red 'Display Winnings Information

        Dim fntHTGSlots As New Font("Comic Sans MS", 12, FontStyle.Bold)
        Dim x_Location, y_Location As Single

        x_Location = 10
        y_Location = 20

        picScore.Refresh()
        picScore.CreateGraphics().DrawString(strWinnings, fntHTGSlots, brHTGSlots, _
        x_Location, _
        y_Location)

    End Sub

The above sub calculates all the winnings and displays the result inside picScore.

We should reset all the counters inside picSpin_Click, to make sure there are no irregularities in our needed results. Your picSpin_Click should resemble:

    Private Sub picSpin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picSpin.Click

        ''''''''''''''''''''''''''''
        ''Part 1
        RandGen = New Random(Now.Millisecond)

        tmrSlots.Enabled = True
        picSpin.Enabled = False
        picSpin.Image = My.Resources.SPIN2
        '''''''''''''''''''''''''''''''

        ''''''''''''''''''''''''''
        ''Part 2
        LineCounter = 0
        MainLineCounter = 0

        Credits -= Bet
        lblCredits.Text = Credits
        ''''''''''''''''''''''''

        'Reset all counters
        Winnings = 0
        MainLineWinnings = 0
        MainLineWinnings2 = 0
        ColWinnings = 0
        LineWinnings = 0

    End Sub

Adding Sizzle to a Video Slot Game with VB.NET - Page 3

We can almost run our project at this stage. Before we forget, we need to set the MaxBet variable to True or False depending on whether or not the Max Bet or Line button was selected. Change these events to:

    Private Sub picLineBet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picLineBet.Click

        '''''''''''''''''''
        ''Part 2
        If LineBetCounter < 5 Then
            LineBetCounter += 1
            Bet = LineBetCounter * SelLines
            lblBet.Text = Bet
            strBetSummary = SelLines.ToString & " Line(s) for " & LineBetCounter.ToString()
            BetInfo()
            '''''''''''''''''''''

            MaxBet = False 'Normal bet

            '''''''''''''''''''''''
            ''Part 2
        Else
            LineBetCounter = 1

        End If
        '''''''''''''''''''''''

    End Sub

    Private Sub picMaxBet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picMaxBet.Click

        MaxBet = True 'Maximum bet

        '''''''''''''''''
        ''Part 2
        Bet = 100
        lblBet.Text = Bet
        strBetSummary = SelLines.ToString & " Line(s) for " & Bet.ToString()
        BetInfo()
        '''''''''''''
    End Sub

Phew! Almost done. In the meantime, wipe the sweat from your forehead...

Done? Did you take a break? OK, let us finish up quickly!

Finishing Up

In case you didn't notice in the second part, upon selection of your amount of Lines, the pictures didn't update nicely. Let us change that. Edit the next events to include the changes:

    Private Sub pic1Line_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pic1Line.Click
        ''''''''''''''''''''''''
        ''Part 2
        SelLines = 1
        strBetSummary = SelLines.ToString & " Line(s) for " & LineBetCounter.ToString()
        BetInfo()
        ''''''''''''''''''''''''''''''

        pic1Line.Image = My.Resources._1_Line_s 'Reset all "Lines" pictures according to selection
        pic3Lines.Image = My.Resources._3_Lines
        pic5Lines.Image = My.Resources._5_Lines
        pic7Lines.Image = My.Resources._7_Lines
        pic9Lines.Image = My.Resources._9_Lines

    End Sub

    Private Sub pic3Lines_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pic3Lines.Click
        ''''''''''''''''''''''''
        ''Part 2
        SelLines = 3
        strBetSummary = SelLines.ToString & " Line(s) for " & LineBetCounter.ToString()
        BetInfo()
        '''''''''''''''''''''''''''''''

        pic3Lines.Image = My.Resources._3_Lines_s 'Reset all "Lines" pictures according to selection
        pic1Line.Image = My.Resources._1_Line
        pic5Lines.Image = My.Resources._5_Lines
        pic7Lines.Image = My.Resources._7_Lines
        pic9Lines.Image = My.Resources._9_Lines
    End Sub

    Private Sub pic5Lines_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pic5Lines.Click
        ''''''''''''''''''''''''
        ''Part 2
        SelLines = 5
        strBetSummary = SelLines.ToString & " Line(s) for " & LineBetCounter.ToString()
        BetInfo()
        ''''''''''''''''''''''''''''

        pic5Lines.Image = My.Resources._5_Lines_s 'Reset all "Lines" pictures according to selection
        pic1Line.Image = My.Resources._1_Line
        pic3Lines.Image = My.Resources._3_Lines
        pic7Lines.Image = My.Resources._7_Lines
        pic9Lines.Image = My.Resources._9_Lines
    End Sub

    Private Sub pic7Lines_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pic7Lines.Click
        ''''''''''''''''''''''''
        ''Part 2
        SelLines = 7
        strBetSummary = SelLines.ToString & " Line(s) for " & LineBetCounter.ToString()
        BetInfo()
        ''''''''''''''''''''''''''''

        pic7Lines.Image = My.Resources._7_Lines_s 'Reset all "Lines" pictures according to selection
        pic1Line.Image = My.Resources._1_Line
        pic3Lines.Image = My.Resources._3_Lines
        pic5Lines.Image = My.Resources._5_Lines
        pic9Lines.Image = My.Resources._9_Lines
    End Sub

    Private Sub pic9Lines_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pic9Lines.Click
        ''''''''''''''''''''''''
        ''Part 2
        SelLines = 9
        strBetSummary = SelLines.ToString & " Line(s) for " & LineBetCounter.ToString()
        BetInfo()
        '''''''''''''''''''''''''''''

        pic9Lines.Image = My.Resources._9_Lines_s 'Reset all "Lines" pictures according to selection
        pic1Line.Image = My.Resources._1_Line
        pic3Lines.Image = My.Resources._3_Lines
        pic5Lines.Image = My.Resources._5_Lines
        pic7Lines.Image = My.Resources._7_Lines

    End Sub

Here we ensure that only one chosen Line option can be selected at a time and the GUI knows about it as well.

All we need to do now is to include the events for the Add Credits button, and Pay Out button:

    Private Sub btnAddMoreCredits_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddMoreCredits.Click
        Credits += InputBox("Please enter Credits") 'Allow addition of more credits
        lblCredits.Text = Credits
    End Sub

    Private Sub btnPayOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPayOut.Click
        'Display total winnings
        MessageBox.Show("You have a total of " & Credits.ToString & Environment.NewLine & "Thanks for Playing!")
    End Sub

We are done! When this project is run, your screen would look similar to Figure 1 or Figure 2

Losing screen
Figure 1 - Losing screen

Winning screen
Figure 2 - Winning screen

Further Development Ideas

This project is by no means perfect, but it is very very close to perfect! My aim with this whole project was to help you figure out the logic behind these types of games, and explain to you how they work. From here on, you can do so many things with it. The following list gives some hints and suggestions:

  1. Enable the facility to indicate what value a credit can be, 10 cents, 1 cent, 1 Rand / Dollar / Yen /Your Currency
  2. Nicer interface
  3. A secret code when credits are loaded and taken
  4. A bonus game feature depending on which sequence of objects was struck
  5. Free Spins facility

Conclusion

Wow, this was much more work than I anticipated, but I am happy with the final project. I sincerely hope you are too, and that you have enjoyed and benefited from this article series. It was really fun explaining everything to you. I'm off to find new stuff to write about. Hopefully I come back with something just as fun as this one! Until then, cheers and happy coding!



Related Articles

Downloads

Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds