How To Make A Slot Machine In Visual Basic

[Lesson 32] << [Contents] >> [Lesson 34]

33.3 Creating a Slot Machine. In this program, we add three picture boxes, a timer, a button and a label. Set the timer interval to 10, which means the images will refresh every 0.01 second. This simple slot machine was created using Visual Basic 6. While it does not exactly resemble the real machines played in casinos, it does demonstrate the concept of randomness and probability in an actual slot machine. Slot machine is a game of chance; many different outcomes will appear when the player presses the play button.

Although Visual Basic 2015 is a programming language designed for creating business and other industrial applications, it can be used to create animation. In the preceding lesson, we have actually learned how to create animation using the timer. In fact, the programs we have created in the previous lesson such as the stopwatch and the digital dice are animated programs.

We can create a continuously moving object using the timer. The motion can be from left to right or from top to bottom motion or diagonal.

33.1 Creating Motion

First, insert a picture box into the form. In the picture box properties window, select the image property and click to import an image file from your storage devices such as your hard drive, your pen drive or DVD drive. We have inserted an image of a bunch of grapes.Next, insert a Timer control into the form and set its Interval property to 100, which is equivalent to 0.1 seconds. Finally, add two buttons to the form, name one of them as AnimateBtn and the other one as StopBtn, and change to caption to Animate and Stop respectively.


We make use of the Left property of the picture box to create the motion. PictureBox.Left means the distance of the PictureBox from the left border of the Form. Now click on the Timer control and type in the following code:

In the code above, Me.Width represents the width of the Form. If the distance of the PictureBox from the left is less than the width of the Form, a value of 10 is added to the distance of the PictureBox from the left border each time the Timer tick, or every 0.1 seconds in this example. When the distance of the PictureBox from the left border is equal to the width of the form, the distance from the left border is set to 0, which move the PictureBox object to the left border and then move left again, thus creates an oscillating motion from left to right. We need to insert a button to stop motion. The code is:

To animate the PictureBox object, we insert a button and enter the following code:

The runtime interface

Figure 33.1


33.2 Creating a Graphical Dice

In preceding lessons, we have learned how to create graphics and draw objects on the form. Now we shall use the previous knowledge to create an animated graphical dice using the timer.

In this program, we need to insert a timer and set its interval to 100, which means the drawings will refresh every 0.1 seconds. Next, insert a picture box which is used as the surface of a dice. Finally, add a button and change its text to Roll. Under the Timer sub procedure, we create the Graphics object and the Pen object following the procedures we have learned in preceding lessons. Next, we use a Do loop and the Select Case structure to cycle through all six surfaces of the dice. To create six random cases, we use the syntax n = Int(6 * Rnd()) + 1. We can stop the loop by introducing a variable t and the loop until condition. The condition we set here is t>1000, you can use any figure you wish.

The code

The runtime interface is as shown in Figure 33.2

Figure 33.2

The Video Demo


33.3 Creating a Slot Machine

In this program, we add three picture boxes, a timer, a button and a label. Set the timer interval to 10, which means the images will refresh every 0.01 second. In the code, we shall introduce four variables m, a, b and c, where m is used to stop the timer and a,b,c are used to generate random images using the syntax Int(1 + Rnd() * 3). To load the images, we use the following syntax:

PictureBox.Image = Image.FromFile(Path of the image file)

We employ the If…Then structure to control the timer and the Select Case…..End Select structure to generate the random images. The label is used to display the message of the outcomes.

The Code

How To Make A Slot Machine In Visual Basic C++

The run-time interface is shown in Figure 33.3

Figure 33.3

View the slot machine in action on the following video clip.


[Lesson 32] << [Contents] >> [Lesson 34]

How To Make A Slot Machine In Visual Basic Java

Slot
  • Shared Tutorials

How To Make A Slot Machine In Visual Basic Powerpoint

  • White Papers
  • Website Development
  • 2D & 3D Graphics
  • Audio & Video Editing
  • Databases
  • Data Science
  • Desktop Programming
  • Digital Marketing
  • Operating Systems
  • Business Applications
  • Miscellaneous

Synopsis

Create a fun and interactive slot machine using visual studio windows form application.
Make

Statistics

  • Total Hits - 6833

  • Total Votes - 1 votes

  • Vote Up - 1 votes

  • Vote Down - 0 votes

  • Domain - www.mooict.com

  • Category - Visual Basic/Visual Basic Misc

  • Submitted By - Anhar Ali

  • Submitted on - 2016-05-13 16:21:04

Description

Source Website

How To Make A Slot Machine In Visual Basic Language

Please use the following link to visit the site. There is a possibility that this content has been removed from the given URL or may be this site has been shut down completely.

How To Make A Slot Machine In Visual Basics

http://www.mooict.com/visual-basic-tutorial-make-a-slot-machine/