-
Notifications
You must be signed in to change notification settings - Fork 16
/
test.ts
33 lines (30 loc) · 956 Bytes
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// tests go here; this will not be compiled when this package is used as a library
// shaking is mining...
input.onGesture(Gesture.Shake, () => {
led.stopAnimation()
basic.clearScreen()
basic.pause(200) // display a short pause
if (Math.random(3) == 0) { // 30% chances to add a transaction
// we found a coin!!!
blockchain.addBlock(1);
basic.showIcon(IconNames.Diamond);
} else {
// missed!
basic.showIcon(IconNames.Asleep);
}
})
// show my score
input.onButtonPressed(Button.A, () => {
led.stopAnimation()
let score = blockchain.valuesFrom(blockchain.id()).length;
basic.showNumber(score);
basic.showString("COINS");
})
// show the block chain size
input.onButtonPressed(Button.B, () => {
led.stopAnimation()
basic.showNumber(blockchain.length());
basic.showString("BLOCKS");
})
// ask neighbors for chains
basic.showString("A=SCORE B=CHAIN SHAKE=MINE", 100)