This is a simple slot machine which does not resemble the real machines played in a casino. However, it does demonstrate the concept of randomness and probability in an actual slot machine. Slot machines is a game of chance , many different outcomes will appear when the player press the play button.
|
|
|
Randomness can be achieved by using the RND function. We also insert a timer to create the animated effect of a slot machine. The time interval is set to 10 so that the shapes change at a fast rate thus creates the illusion of animation. The program also using a variable x to control the timer so that it can be stopped when x achieve certain value, otherwise the program will loop forever.
The purpose of this program is just to show how different shapes can appear randomly, therefore many advanced features of a slot machine such as the amount of bet are not programmed here. Those features are available in the professional slot machine.
|
The Design Interface
|
|
|
The Runtime Interface
|
|
The Code
Private Sub Command1_Click()'To start the timer
Timer1.Enabled = True
x = 0End Sub
Private Sub Timer1_Timer()
x = x + 10
Dim a, i As Integer
Randomize Timer
For i = 0 To 8' To generate random integers 0,1 and 2
a = Int(Rnd * 3)
Shape1(i).Shape = a
If a = 0 Then
Shape1(i).FillColor = vbRed
ElseIf a = 1 Then
Shape1(i).FillColor = vbGreen
Else
Shape1(i).FillColor = vbBlue
End If
Next i'To stop the timer
If x > 500 Then
Timer1.Enabled = False
End If
End Sub