
March 8th, 2012, 03:54 PM
|
|
Registered User
|
|
Join Date: Feb 2012
Posts: 15
Time spent in forums: 12 h 23 m 8 sec
Reputation 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
|