Update more docs
This commit is contained in:
parent
8719f557aa
commit
014125cf19
@ -1,4 +1,4 @@
|
|||||||
## Unplugged: Two heads are better than one
|
<!-- ## Unplugged: Two heads are better than one
|
||||||
|
|
||||||
Materials: A penny for each student, paper and pencils
|
Materials: A penny for each student, paper and pencils
|
||||||
|
|
||||||
@ -208,4 +208,4 @@ Our basic pseudocode for our 'double coin flipper' could look like this:
|
|||||||
3. Compare the current values of Coin A and Coin B.
|
3. Compare the current values of Coin A and Coin B.
|
||||||
4. If the current true/false values of Coin A and Coin B are the same, add a point to Player A’s score.
|
4. If the current true/false values of Coin A and Coin B are the same, add a point to Player A’s score.
|
||||||
5. Otherwise, the current true/false values of Coin A and Coin B must be different, so add a point to Player B’s score.
|
5. Otherwise, the current true/false values of Coin A and Coin B must be different, so add a point to Player B’s score.
|
||||||
6. When players are done with their double coin flipping, show the final scores for each player.
|
6. When players are done with their double coin flipping, show the final scores for each player. -->
|
||||||
|
@ -96,55 +96,42 @@ Thanks for playing with Karel the LED!
|
|||||||
Copy this code into the JavaScript editor and then download it to the board.
|
Copy this code into the JavaScript editor and then download it to the board.
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const board = new Board();
|
|
||||||
/**
|
/**
|
||||||
* Karel the LED
|
* Karel the LED
|
||||||
*/
|
*/
|
||||||
basic.forever(() => {
|
input.onButtonPressed(Button.B, function () {
|
||||||
if (board.isKarelActive) {
|
|
||||||
led.toggle(board.karelX, board.karelY)
|
|
||||||
basic.pause(500)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
input.onButtonPressed(Button.A, () => {
|
|
||||||
board.pressedA();
|
|
||||||
updateLeds();
|
|
||||||
})
|
|
||||||
input.onButtonPressed(Button.B, () => {
|
|
||||||
board.pressedB();
|
board.pressedB();
|
||||||
updateLeds();
|
updateLeds()
|
||||||
})
|
})
|
||||||
input.onGesture(Gesture.Shake, () => {
|
input.onGesture(Gesture.Shake, function () {
|
||||||
board.shake();
|
board.shake();
|
||||||
updateLeds();
|
updateLeds()
|
||||||
})
|
|
||||||
input.onButtonPressed(Button.AB, () => {
|
|
||||||
board.pressedAB();
|
|
||||||
updateLeds();
|
|
||||||
})
|
})
|
||||||
function updateLeds() {
|
function updateLeds() {
|
||||||
for (let j = 0; j < 5; j++) {
|
for (let j = 0; j <= 5 - 1; j++) {
|
||||||
for (let k = 0; k < 5; k++) {
|
for (let k = 0; k <= 5 - 1; k++) {
|
||||||
if (board.ledState[j][k]) {
|
if (board.ledState[j][k]) {
|
||||||
led.plot(k, j);
|
led.plot(k, j)
|
||||||
} else {
|
} else {
|
||||||
led.unplot(k, j);
|
led.unplot(k, j)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
enum Direction {
|
input.onButtonPressed(Button.A, function () {
|
||||||
UP = 0,
|
board.pressedA();
|
||||||
LEFT,
|
updateLeds()
|
||||||
DOWN,
|
})
|
||||||
RIGHT
|
input.onButtonPressed(Button.AB, function () {
|
||||||
}
|
board.pressedAB();
|
||||||
|
updateLeds()
|
||||||
|
})
|
||||||
class Board {
|
class Board {
|
||||||
public isKarelActive: boolean;
|
public isKarelActive: boolean;
|
||||||
public karelX: number;
|
public karelX: number;
|
||||||
public karelY: number;
|
public karelY: number;
|
||||||
|
|
||||||
public ledState: Array < Array < boolean >>;
|
public ledState: Array<Array<boolean>>;
|
||||||
private karelDirection: Direction;
|
private karelDirection: Direction;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -152,7 +139,7 @@ class Board {
|
|||||||
this.karelX = 2;
|
this.karelX = 2;
|
||||||
this.karelY = 2;
|
this.karelY = 2;
|
||||||
this.karelDirection = Direction.UP;
|
this.karelDirection = Direction.UP;
|
||||||
this.ledState =[];
|
this.ledState = [];
|
||||||
for (let i = 0; i < 5; i++) {
|
for (let i = 0; i < 5; i++) {
|
||||||
this.ledState.push([false, false, false, false, false]);
|
this.ledState.push([false, false, false, false, false]);
|
||||||
}
|
}
|
||||||
@ -212,6 +199,19 @@ class Board {
|
|||||||
this.isKarelActive = !this.isKarelActive;
|
this.isKarelActive = !this.isKarelActive;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const board = new Board();
|
||||||
|
enum Direction {
|
||||||
|
UP = 0,
|
||||||
|
LEFT,
|
||||||
|
DOWN,
|
||||||
|
RIGHT
|
||||||
|
}
|
||||||
|
basic.forever(function () {
|
||||||
|
if (board.isKarelActive) {
|
||||||
|
led.toggle(board.karelX, board.karelY)
|
||||||
|
basic.pause(500)
|
||||||
|
}
|
||||||
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
## About the authors
|
## About the authors
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# micro:coin
|
<!-- # micro:coin
|
||||||
|
|
||||||
## ~ avatar
|
## ~ avatar
|
||||||
|
|
||||||
@ -84,4 +84,4 @@ The [radio-blockchain](https://makecode.microbit.org/pkg/microsoft/pxt-radio-blo
|
|||||||
```package
|
```package
|
||||||
radio
|
radio
|
||||||
radio-blockchain=github:Microsoft/pxt-radio-blockchain#master
|
radio-blockchain=github:Microsoft/pxt-radio-blockchain#master
|
||||||
```
|
``` -->
|
||||||
|
@ -11,6 +11,9 @@ namespace pxsim.visuals {
|
|||||||
-webkit-filter: grayscale(1);
|
-webkit-filter: grayscale(1);
|
||||||
filter: grayscale(1);
|
filter: grayscale(1);
|
||||||
}
|
}
|
||||||
|
.sim-button-group {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
.sim-button {
|
.sim-button {
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user