#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    15
    Rep Power
    0

    Slot machine program


    i'm creating a slot machine program. i already have my layout and the coding for the program to spin and everything. But, my problem is, i have a section where the user can increase of decrease their bet, and when the user loses/wins, i want their balance to be adjusted. for example, if the user bets $20, and loses, i would like the $20 to be subtracted from their balance. this is the coding i have so far

    Code:
    
    ' Project name:         Slot Machine Project
    ' Project purpose:      Simulates a slot machine
    ' Created/revised by:   <your name> on <current date>
    
    Option Explicit On
    Option Strict On
    Option Infer Off
    
    Public Class MainForm
    
        Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
            Me.Close()
        End Sub
    
        Private Sub clickHereButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clickHereButton.Click
            Dim randGen As New Random
            Dim leftIndex As Integer
            Dim centerIndex As Integer
            Dim rightIndex As Integer
            Dim lost As Integer
    
            clickHereButton.Enabled = False
            For spins As Integer = 1 To 10
                leftIndex = randGen.Next(0, 6)
                leftPictureBox.Image =
                    ImageList1.Images.Item(leftIndex)
                Me.Refresh()
                System.Threading.Thread.Sleep(50)
    
                centerIndex = randGen.Next(0, 6)
                centerPictureBox.Image =
                    ImageList1.Images.Item(centerIndex)
                Me.Refresh()
                System.Threading.Thread.Sleep(50)
    
                rightIndex = randGen.Next(0, 6)
                rightPictureBox.Image =
                    ImageList1.Images.Item(rightIndex)
                Me.Refresh()
                System.Threading.Thread.Sleep(50)
    
            Next spins
    
            If leftIndex = centerIndex AndAlso
                leftIndex = rightIndex Then
                MessageBox.Show("Congratulations!", "Winner",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information)
    
            End If
            If leftIndex <> centerIndex AndAlso
                leftIndex <> rightIndex Then
                MessageBox.Show("Sorry, you lost! Please play again", "Loser",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information)
                lblBal.Text = lblBet - lost
            End If
            clickHereButton.Enabled = True
    
    
    
    
        End Sub
    
        
        Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
            Static amount As Integer
    
            amount = amount + 5
            lblBet.Text = "$" & amount
        End Sub
    
        Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
            Static amount As Integer
    
            amount = amount - 5
            lblBet.Text = "$" & amount
        End Sub
    
        Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim balance As Integer
    
            balance = CInt(InputBox("Enter playing balance"))
            lblBal.Text = "$" & balance
        End Sub
    End Class
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,448
    Rep Power
    4539
    Does something not work with your code?
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    15
    Rep Power
    0
    everything worked fine in my code. but i was having problems coding my balance label. but i actually just finished working all the kinks out, so i have my program running the way it should be. it took me a while to figure it out, but i finally did.

IMN logo majestic logo threadwatch logo seochat tools logo