added dice (#1196)
This commit is contained in:
parent
b4cb424ec4
commit
af1de79d06
@ -10,14 +10,7 @@ Here are some fun programs for your @boardname@!
|
||||
"description": "A blinking pattern of LEDs",
|
||||
"url": "/examples/blinky",
|
||||
"cardType": "example"
|
||||
},
|
||||
{
|
||||
"name": "Name Tag",
|
||||
"description": "Scroll your name on the screen",
|
||||
"url": "/examples/name-tag",
|
||||
"cardType": "example"
|
||||
},
|
||||
{
|
||||
}{
|
||||
"name": "Rando",
|
||||
"description": "Randomly blinking LEDs",
|
||||
"url": "/examples/rando",
|
||||
|
56
docs/projects/dice.md
Normal file
56
docs/projects/dice.md
Normal file
@ -0,0 +1,56 @@
|
||||
# Dice
|
||||
|
||||
## Introduction
|
||||
|
||||
![A microbit dice](/static/mb/projects/dice.png)
|
||||
|
||||
Let's turn the @boardname@ into a dice! To do so, we need 3 pieces of code: detect a throw (shake),
|
||||
pick a random number, show the number.
|
||||
|
||||
## Step 1 @fullscreen
|
||||
|
||||
Place the ``||input:on shake||`` block. It runs code when you shake the @boardname@.
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
## Step 2 @fullscreen
|
||||
|
||||
Place the ``||basic:show number||`` block in the ``||input:on shake||`` block to display a number.
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.showNumber(0)
|
||||
})
|
||||
```
|
||||
|
||||
## Step 3 @fullscreen
|
||||
|
||||
Place the ``||Math:pick random||`` block in an ``||input:on shake||`` block to pick a random number.
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.showNumber(Math.randomRange(0, 10))
|
||||
})
|
||||
```
|
||||
|
||||
## Step 4 @fullscreen
|
||||
|
||||
A typical dice shows values from `1` to `6`. So, in ``||Math:pick random||``, don't forget to choose the right minimum and maximum values!
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.showNumber(Math.randomRange(1, 6))
|
||||
})
|
||||
```
|
||||
|
||||
## Step 5
|
||||
|
||||
Use the simulator to try out your code. Does it show the number you expected?
|
||||
|
||||
## Step 6
|
||||
|
||||
If you have a @boardname@ connected, click ``|Download|`` and transfer your code to the @boardname@!
|
BIN
docs/static/mb/projects/dice.png
vendored
Normal file
BIN
docs/static/mb/projects/dice.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
@ -22,14 +22,19 @@ Here are some cool tutorials to get you started with your @boardname@!
|
||||
"imageUrl": "/static/mb/projects/a2-buttons.png",
|
||||
"cardType": "tutorial"
|
||||
}, {
|
||||
"name": "Coin Flipper",
|
||||
"url":"/projects/coin-flipper",
|
||||
"imageUrl": "/static/mb/projects/coin-flipper.png",
|
||||
"name": "Dice",
|
||||
"url":"/projects/dice",
|
||||
"imageUrl": "/static/mb/projects/dice.png",
|
||||
"cardType": "tutorial"
|
||||
}, {
|
||||
"name": "Love Meter",
|
||||
"url":"/projects/love-meter",
|
||||
"imageUrl":"/static/mb/projects/a3-pins.png",
|
||||
"cardType": "tutorial"
|
||||
}, {
|
||||
"name": "Coin Flipper",
|
||||
"url":"/projects/coin-flipper",
|
||||
"imageUrl": "/static/mb/projects/coin-flipper.png",
|
||||
"cardType": "tutorial"
|
||||
}]
|
||||
```
|
Loading…
Reference in New Issue
Block a user