Migrate docs from the other repo

This commit is contained in:
Michal Moskal
2016-03-25 16:47:20 -07:00
parent 38d2cf06d2
commit a08eb53f92
895 changed files with 36888 additions and 0 deletions

View File

@ -0,0 +1,56 @@
# rock paper scissors activity
a game against the BBC micro:bit. #docs
### ~avatar avatar
### @video td/videos/rock-paper-scissors-0
Welcome! This tutorial will help you create a game of rock paper scissors with the BBC micro:bit. Let's get started!
### ~
To create a new script, go to the [Create Code](/microbit/create-code) page and tap *New Project* under **Touch Develop**.
We want the BBC micro:bit to choose rock, paper, or scissors when it is shaken. Let's begin by creating an `input->on shake` condition so the micro:bit will run code when it is shaken.
```
input.onGesture(Gesture.Shake, () => {
})
```
Next, create an image that contains 3 frames: rock, paper, and scissors. We will control which image is shown with `offset`.
```
input.onGesture(Gesture.Shake, () => {
let img = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
})
```
The BBC micro:bit will look like it's showing 1 frame of the image by displaying the whole image with plot frame and math random. We can help the BBC micro:bit randomly decide which offset to using plot image by math random. The BBC micro:bit will randomly pick the image to display with plot image and the `math->random(3)` function.
```
input.onGesture(Gesture.Shake, () => {
let img1 = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
img1.plotFrame(Math.random(3))
})
```
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/microbit/lessons/rock-paper-scissors/challenges)!
### ~

View File

@ -0,0 +1,70 @@
# rock paper scissors challenges
Coding challenges for the rock paper scissors tutorial. #docs
## Before we get started
Complete the following [guided activity](/microbit/lessons/rock-paper-scissors/activity) , your code should look like this:
```
input.onGesture(Gesture.Shake, () => {
let img = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . . # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
img.plotFrame(Math.random(3))
})
```
### Challenge 1
When the `A` button is pressed, increment the **score** by ``1``. You can use the `game->add score` function for that.
```
input.onGesture(Gesture.Shake, () => {
let img1 = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . . # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
img1.plotFrame(Math.random(3))
})
input.onButtonPressed("A", () => {
game.addScore(1) // ***
}) // ***
```
### Challenge 2
After incrementing the score, display the total number of wins you have.
```
input.onGesture(Gesture.Shake, () => {
let img2 = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . . # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
img2.plotFrame(Math.random(3))
})
input.onButtonPressed("A", () => {
game.addScore(1)
basic.showString("WINS: ", 150) // ***
basic.showNumber(game.score(), 150) // ***
})
```
* Run and compile the code to see if it works as expected.
### Challenge 3
You have successfully tracked and displayed the number of wins on the BBC micro:bit! However, what about losses? Use `game->remove life` when button `B` is pressed.
* Run and compile the code to see if it works as expected.

View File

@ -0,0 +1,74 @@
# rock paper scissors quiz
shift an image horizontally across the display with offset #offset #screen #variables #docs
## Name
## Directions
Use this activity document to guide your work in the [rock paper scissors tutorial](/microbit/lessons/rock-paper-scissors/tutorial).
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Describe what `offset` does?
<br/>
## 2. Draw which LEDs are ON after running this code and the random number returned is 0
```
let img = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
let offset = Math.random(3) * 5
img.showImage(offset)
```
![](/static/mb/lessons/night-light-2.png)
<br/>
<br/>
## 3. Draw which LEDs are ON after running this code with an offset of 5. This would occur if the random number returned is 1.
```
let img_ = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
let offset_ = Math.random(3) * 5
img.showImage(offset)
```
![](/static/mb/lessons/night-light-2.png)
<br/>
<br/>
## 4. Draw which LEDs are ON after running this code with an offset of 10. This would occur if the random number returned is 2.
```
let img_1 = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
let offset_1 = Math.random(3) * 5
img.showImage(offset)
```
![](/static/mb/lessons/night-light-2.png)
<br/>