2017-09-11 19:49:40 +02:00
|
|
|
# Coin Flipper
|
2016-06-24 08:52:24 +02:00
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## ~avatar avatar
|
2016-06-24 08:52:24 +02:00
|
|
|
|
|
|
|
Are you trying to choose whether to play soccer or go to the movies
|
|
|
|
instead, or which toppings to have on your pizza? Build a coin
|
2016-11-01 18:42:42 +01:00
|
|
|
flipping machine with the @boardname@ to choose for you!
|
2016-06-24 08:52:24 +02:00
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## ~
|
2016-06-24 08:52:24 +02:00
|
|
|
|
2017-09-11 19:49:40 +02:00
|
|
|
## Step 1
|
|
|
|
|
|
|
|
Place a ``||input:on button pressed||`` block to run code
|
|
|
|
when button **A** is pressed.
|
2016-06-24 08:52:24 +02:00
|
|
|
|
|
|
|
```blocks
|
2017-09-11 19:49:40 +02:00
|
|
|
input.onButtonPressed(Button.A, () => {
|
|
|
|
})
|
2016-06-24 08:52:24 +02:00
|
|
|
```
|
|
|
|
|
2017-09-11 19:49:40 +02:00
|
|
|
## Step 2
|
2016-06-24 08:52:24 +02:00
|
|
|
|
2017-09-11 19:49:40 +02:00
|
|
|
Place a **if** block and check the value returned by the ``||Math:pick random true or false||`` block.
|
2016-06-24 08:52:24 +02:00
|
|
|
|
2017-09-11 19:49:40 +02:00
|
|
|
``||Math:pick random true or false||`` returns ``true`` or ``false`` randomly.
|
2016-06-24 08:52:24 +02:00
|
|
|
|
2017-09-11 19:49:40 +02:00
|
|
|
```blocks
|
|
|
|
input.onButtonPressed(Button.A, () => {
|
|
|
|
if (Math.randomBoolean()) {
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
2016-06-24 08:52:24 +02:00
|
|
|
|
2017-09-11 19:49:40 +02:00
|
|
|
## Step 3
|
2016-06-24 08:52:24 +02:00
|
|
|
|
2017-09-11 19:49:40 +02:00
|
|
|
Place a ``||basic:show icon||`` block under the **if** and pick one of the images.
|
2016-06-24 08:52:24 +02:00
|
|
|
|
|
|
|
```blocks
|
|
|
|
input.onButtonPressed(Button.A, () => {
|
2017-09-11 19:49:40 +02:00
|
|
|
if (Math.randomBoolean()) {
|
|
|
|
basic.showIcon(IconNames.Skull)
|
|
|
|
} else {
|
|
|
|
basic.showIcon(IconNames.Square)
|
|
|
|
}
|
2016-06-24 08:52:24 +02:00
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2017-09-11 19:49:40 +02:00
|
|
|
## Step 4
|
|
|
|
|
|
|
|
Click ``|Download|`` to transfer your code in your @boardname@ and press button **A** to try it out.
|
|
|
|
|
|
|
|
## Step 5
|
2016-06-24 08:52:24 +02:00
|
|
|
|
2017-09-11 19:49:40 +02:00
|
|
|
Place multiple ``||basic:show icon||`` blocks before the **if** to create a coin flipping animation.
|
2016-06-24 08:52:24 +02:00
|
|
|
|
|
|
|
```blocks
|
2017-09-11 19:49:40 +02:00
|
|
|
input.onButtonPressed(Button.A, () => {
|
|
|
|
basic.showIcon(IconNames.Diamond)
|
|
|
|
basic.showIcon(IconNames.SmallDiamond)
|
|
|
|
basic.showIcon(IconNames.Diamond)
|
|
|
|
basic.showIcon(IconNames.SmallDiamond)
|
2016-06-24 08:52:24 +02:00
|
|
|
if (Math.randomBoolean()) {
|
2017-09-11 19:49:40 +02:00
|
|
|
basic.showIcon(IconNames.Skull)
|
2016-06-24 08:52:24 +02:00
|
|
|
} else {
|
2017-09-11 19:49:40 +02:00
|
|
|
basic.showIcon(IconNames.Square)
|
2016-06-24 08:52:24 +02:00
|
|
|
}
|
2017-09-11 19:49:40 +02:00
|
|
|
})
|
2016-06-24 08:52:24 +02:00
|
|
|
```
|
|
|
|
|
2017-09-11 19:49:40 +02:00
|
|
|
## Step 6
|
|
|
|
|
|
|
|
Click ``|Download|`` to transfer your code in your @boardname@ and press button **A** to try it out!
|