moving out outdated js docs
This commit is contained in:
174
olddocs/js/lessons/the-hat-game/challenges.md
Normal file
174
olddocs/js/lessons/the-hat-game/challenges.md
Normal file
@ -0,0 +1,174 @@
|
||||
# the hat game challenges
|
||||
|
||||
The all famous Hat Game -- one of 3 hats has the ball, which is revealed at the beginning. The hats then swap with each other. You goal is to chose the hat with the ball after the hats have finished swapping. #docs
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided tutorial:
|
||||
|
||||
* [tutorial](/lessons/the-hat-game/tutorial)
|
||||
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
initializeGame()
|
||||
playLevel()
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
selectHat()
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
chooseHat()
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Modify `play level()` to customize your difficulty levels. Simply increase the `swap speed` to make the game easier, or decrease it to make the game harder.
|
||||
|
||||
```
|
||||
/**
|
||||
* **. . .**
|
||||
*/
|
||||
export function playLevel_() {
|
||||
let swaps = 5 + 10 * level
|
||||
if (level == 1) {
|
||||
swaps = 100 // ***
|
||||
} else if (level == 2) {
|
||||
swapSpeed = 40 // ***
|
||||
}
|
||||
else {
|
||||
swapSpeed = 20 // ***
|
||||
}
|
||||
// **. . .**
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Let's make the game a little more fun and devious! Let's add a `fake swap` function that pretends to swap the hats, but doesn't actually swap them.
|
||||
|
||||
```
|
||||
export function fakeSwap(hat_1: number, hat_2: number, pauseDifficulty: number) {
|
||||
if (hat_1 == 0 && hat_2 == 1) {
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . . # . . . . . # . . . # . . . . . . . . . . . . . .
|
||||
. . . . . # . . . . . . . . . . . . . . . . . . . # . . . . . . . . .
|
||||
# . # . # . . . . # . . . . # . . . . # . . . . # . . . . # # . # . #
|
||||
. . . . . . . # . . . . . . . . . . . . . . . . . . . # . . . . . . .
|
||||
. . . . . . . . . . . . # . . . # . . . . . # . . . . . . . . . . . .
|
||||
`, pauseDifficulty)
|
||||
}
|
||||
if (hat_1 == 1 && hat_2 == 0) {
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . . . . # . . . # . . . . . # . . . . . . . . . . . .
|
||||
. . . . . . . # . . . . . . . . . . . . . . . . . . . # . . . . . . .
|
||||
# . # . # . . . . # . . . . # . . . . # . . . . # . . . . # # . # . #
|
||||
. . . . . # . . . . . . . . . . . . . . . . . . . # . . . . . . . . .
|
||||
. . . . . . . . . . # . . . . . # . . . # . . . . . . . . . . . . . .
|
||||
`, pauseDifficulty)
|
||||
}
|
||||
if (hat_1 == 1 && hat_2 == 2) {
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . . . . # . . . . . # . . . # . . . . . . . . . . . .
|
||||
. . . . . . . # . . . . . . . . . . . . . . . . . . . # . . . . . . .
|
||||
# . # . # # . . . . # . . . . # . . . . # . . . . # . . . . # . # . #
|
||||
. . . . . . . . . # . . . . . . . . . . . . . . . . . . . # . . . . .
|
||||
. . . . . . . . . . . . . . # . . . # . . . . . # . . . . . . . . . .
|
||||
`, pauseDifficulty)
|
||||
}
|
||||
if (hat_1 == 2 && hat_2 == 1) {
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . . . . . . # . . . # . . . . . # . . . . . . . . . .
|
||||
. . . . . . . . . # . . . . . . . . . . . . . . . . . . . # . . . . .
|
||||
# . # . # # . . . . # . . . . # . . . . # . . . . # . . . . # . # . #
|
||||
. . . . . . . # . . . . . . . . . . . . . . . . . . . # . . . . . . .
|
||||
. . . . . . . . . . . . # . . . . . # . . . # . . . . . . . . . . . .
|
||||
`, pauseDifficulty)
|
||||
}
|
||||
if (hat_1 == 0 && hat_2 == 2) {
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . . # . . . . . # . . . . . # . . . # . . . # . . . . . . . . . . . . . .
|
||||
. . . . . # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . . . . . .
|
||||
# . # . # . . # . . . . # . . . . # . . . . # . . . . # . . . . # . . . . # . . # . # . #
|
||||
. . . . . . . . . # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . .
|
||||
. . . . . . . . . . . . . . # . . . # . . . # . . . . . # . . . . . # . . . . . . . . . .
|
||||
`, pauseDifficulty)
|
||||
}
|
||||
if (hat_1 == 2 && hat_2 == 0) {
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . . . . . . # . . . # . . . # . . . . . # . . . . . # . . . . . . . . . .
|
||||
. . . . . . . . . # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . .
|
||||
# . # . # . . # . . . . # . . . . # . . . . # . . . . # . . . . # . . . . # . . # . # . #
|
||||
. . . . . # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . . . . . .
|
||||
. . . . . . . . . . # . . . . . # . . . . . # . . . # . . . # . . . . . . . . . . . . . .
|
||||
`, pauseDifficulty)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Now let's implement our `fake swap` function inside `play level`. Let's make a third of the swaps fake. This can be most efficiently accomplished through mod.
|
||||
|
||||
```
|
||||
/**
|
||||
* **. . .**
|
||||
*/
|
||||
export function playLevel_1() {
|
||||
let swaps = 5 + 10 * level
|
||||
// **. . .**
|
||||
for (let i = 0; i < swaps; i++) {
|
||||
let swapType = Math.random(3) // ***
|
||||
let not = Math.random(3)
|
||||
if (swapType < 2) {
|
||||
swapHats(math.mod(not + 1, 3), math.mod(not + 2, 3), swapSpeed) // ***
|
||||
} else {
|
||||
fakeSwap(math.mod(not + 1, 3), math.mod(not + 2, 3), swapSpeed) // ***
|
||||
}
|
||||
}
|
||||
index = -1
|
||||
choosingHat = true
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 4
|
||||
|
||||
For a swap of two given hats, one of the hats will always go up while the other goes down. For example, if the first and third hats are swapping, the first hat will always go down and the third will go up. Let's randomize the orientation of each swap by switching the parameters of each swap function half the time.
|
||||
|
||||
```
|
||||
/**
|
||||
* **. . .**
|
||||
*/
|
||||
export function playLevel_2() {
|
||||
let swaps = 5 + 10 * level
|
||||
// **. . .**
|
||||
for (let i = 0; i < swaps; i++) {
|
||||
let swapType = Math.random(3)
|
||||
let not = Math.random(3)
|
||||
let swapOrientation = Math.random(2) // ***
|
||||
if (swapType < 2) {
|
||||
if (swapOrientation == 0) {
|
||||
swapHats(math.mod(not + 1, 3), math.mod(not + 2, 3), swapSpeed) // ***
|
||||
} else {
|
||||
swapHats(math.mod(not + 2, 3), math.mod(not + 1, 3), swapSpeed) // ***
|
||||
}
|
||||
}
|
||||
else {
|
||||
swapOrientation = Math.random(2) // ***
|
||||
if (swapOrientation == 0) {
|
||||
fakeSwap(math.mod(not + 1, 3), math.mod(not + 2, 3), swapSpeed) // ***
|
||||
}
|
||||
else {
|
||||
fakeSwap(math.mod(not + 2, 3), math.mod(not + 1, 3), swapSpeed) // ***
|
||||
}
|
||||
}
|
||||
}
|
||||
index = -1
|
||||
choosingHat = true
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 5
|
||||
|
||||
Create your own swap animation. See if you can get all three hats to move at the same time!
|
||||
|
87
olddocs/js/lessons/the-hat-game/quiz-answers.md
Normal file
87
olddocs/js/lessons/the-hat-game/quiz-answers.md
Normal file
@ -0,0 +1,87 @@
|
||||
# the hat game quiz answers
|
||||
|
||||
The all famous Hat Game -- one of 3 hats has the ball, which is revealed at the beginning. The hats then swap with each other. You goal is to chose the hat with the ball after the hats have finished swapping.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [the hat game tutorial](/lessons/the-hat-game/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What is the name of the first function you created? What does it do?
|
||||
|
||||
<br/>
|
||||
|
||||
Initialize game() is the name of the first function. It helps set up the game state.
|
||||
|
||||
## 2. Write a for loop that plots the points (0, 2), (2, 2), and (4, 2).
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
for (let i = 0; i < 3; i++) {
|
||||
led.plot(i * 2, 2)
|
||||
}
|
||||
```
|
||||
|
||||
## 3. How can you increase the difficulty of the game?
|
||||
|
||||
<br/>
|
||||
|
||||
Decrease the swap speed value. This will reduce the pause between each frame, and will thus make the game run faster.
|
||||
|
||||
## 4. Consider the following code
|
||||
|
||||
```
|
||||
cupSelect = "LMR"
|
||||
index = -1
|
||||
```
|
||||
|
||||
Write the code that displays the next letter of the string in "cup select" when button A is pressed.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
index = index + 1
|
||||
if (index > 2) {
|
||||
index = 0
|
||||
}
|
||||
basic.showString(cupSelect[index], 150)
|
||||
})
|
||||
```
|
||||
|
||||
## 5. Write the line of code that shows the swapping animation of two hats swapping if hat 1 = 0 and hat 2 = 2.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . . # . . . . . # . . . . . # . . . . . # . . . . . # . . . . . . . . . .
|
||||
. . . . . # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . .
|
||||
# . # . # . . # . . . . # . . . . # . . . . # . . . . # . . . . # . . . . # . . # . # . #
|
||||
. . . . . . . . . # . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . . . . . .
|
||||
. . . . . . . . . . . . . . # . . . # . . . # . . . # . . . # . . . . . . . . . . . . . .
|
||||
`, 400)
|
||||
```
|
||||
|
||||
## 6. Consider the following code
|
||||
|
||||
```
|
||||
let not = Math.random(3)
|
||||
```
|
||||
|
||||
Given the hat we are not going to swap, how can we calculate the other two hats that we are going to swap? Use these two values to call "swap hats()" with a swap speed of 50.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
swapHats(math.mod(not + 1, 3), math.mod(not + 2, 3), 50)
|
||||
```
|
||||
|
||||
<br/>
|
||||
|
59
olddocs/js/lessons/the-hat-game/quiz.md
Normal file
59
olddocs/js/lessons/the-hat-game/quiz.md
Normal file
@ -0,0 +1,59 @@
|
||||
# the hat game quiz
|
||||
|
||||
The all famous Hat Game -- one of 3 hats has the ball, which is revealed at the beginning. The hats then swap with each other. You goal is to choose the hat with the ball after the hats have finished swapping.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [the hat game tutorial](/lessons/the-hat-game/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What is the name of the first function you created? What does it do?
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write a for loop that plots the points (0, 2), (2, 2), and (4, 2).
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. How can you increase the difficulty of the game?
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Consider the following code
|
||||
|
||||
```
|
||||
cupSelect = "LMR"
|
||||
index = -1
|
||||
```
|
||||
|
||||
Write the code that displays the next letter of the string in "cup select" when button A is pressed.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 5. Write the line of code that shows the swapping animation of two hats swapping if hat 1 = 0 and hat 2 = 2.
|
||||
|
||||
<br/>
|
||||
|
||||
## 6. Consider the following code
|
||||
|
||||
```
|
||||
let not = Math.random(3)
|
||||
```
|
||||
|
||||
Given the hat we are not going to swap, how can we calculate the other two hats that we are going to swap? Use these two values to call "swap hats()" with a swap speed of 50.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
Reference in New Issue
Block a user