LAB 6. SLOT MACHINE Design

App Inventor Laboratory
Technologies Department
LAB 6. SLOT MACHINE

Push Start Button, and you will see how three boxes will show different images as the slot
machines do.

Push Stop Button and the images will be stopped. The number of chances will be increased and
the App check whether the images are equals or not. In this case the number of hits will be
increased.

Take into account that the timer “Timer1” has been set at 200.

The images we are going to use are added from the Media area. Three images: Strawberry, pear,
and banana.
Look up in the Internet the images. For
example you can use this criteria: “slot
machine strawberry”.
Design
We set the Horizontal arrange, and put the three images
inside. They can be found in the user interface area.
Set the Horizontal arrange to a Width of “Fill parent”
Put the size of the images to a Height = Width of 100 pixels.
The START and STOP buttons must be placed in a Horizontal
arrange. Set the size in such a way the buttons take up all the
space.
Put a clock, that is in the Sensors area.
Set the Time interval to 200.
1
App Inventor Laboratory
Technologies Department
Here we can see how to set some components:
2
App Inventor Laboratory
Technologies Department
Programming
Here you can see the blocks we have to use:
3
App Inventor Laboratory
Technologies Department
Explanation:

We declare the variables x, y, z, hits, and attempts.

When a timer event happens we will create three random numbers from 1 to 4. Depending on
the number we will insert a picture.

The Stop button. When click, we disable the timer, increase the attempts variable and show the
information in the labels. (labelAttempts) We strongly recommend to change the name of the
objects to names with meaning. For example the button1 must be called buttonStop. We also
check if the random numbers are equal, and in this case we will increase the number of hits,
showing the result in the proper label. (labelHits)

The Start button enabled the timer again.

The NewGame button restart the game and put the values again as at the beginning.
4
App Inventor Laboratory
Technologies Department
Improve your App:
We can improve the App changing the interface, the frequency of the timer or even adding new fruits to
the slot machine. We also can add a new feature to our machine by which the App give the user points
depending on the combination that he/she gets.
Another way to improve the App is stopping only one fruit and letting the rest of fruits changing.
It is up to you to make all the enhancements you want.
Enjoy !!!!!
5