App Inventor 2
Programming mobile phones with Android
by App Inventor 2 - Juan Antonio Villalpando
- Initiation Tutorial App Inventor 2 -
Return to tutorial index
____________________________
3.- Three equal
ip5_three equal.aia (This is the source code file to be consulted, modified, debug ... in App Inventor 2 )
p5_tres_iguales.apk (This is the definitive installation file. The copy in our mobile and installed)
(By this QR code can also install this application on a mobile. This installation is simpler)
It is pressing the Start button, at that moment three images fresa.gif, limon.gif and pera.gif, they are played randomly in Images (Image1, Image2 and Image3).
When you press the button Stop, the images are static, increases by one the number of attempts and checked if the three images are the same, in this case increases by one the number of hits.
The images you are going to use (fresa.gif, limon.gif and pera.gif ) we added in the section Media.
From here you can download the images of fruit .
_________________
Design
We put the Clock TimerInterval to 200. If we want this value willdecline faster.
Note that the timer Timer1 we have put TimerInterval to 200
_________________
Blocks
_________________
Comments.
We declare numeric variables: x, y, z, hits, successes.
Each timer is activated Clock1.Timer
We created three random numbers x, y and z: 1 to 3
Depending on the number rolled and insert a variable Image.
When Button1.Click (Stop), the timer disables Clock1.Enabled = false, we increase one intents and show them in Label1.Text also we check if the random numbers x, y, z are equal in this case it increases by one the successes and shown in Label2.Text.
The Button2.Click again Enable the timer Clock1.Enabled = true.
The Button3.Click sets the initial values and starts the timer.
_________________________________________________
Proposal:
Create another label where the relationship between successes and attempts to display.
Get the probability of hitting:
There are 3 raised to 3 = 27 possible combinations and 3 hits.
Then the probability of sucess is 3/27 = 1/9
__________________________________
|