-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
70 lines (61 loc) · 1.52 KB
/
main.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
let i = 0
let bclicked = 0
let atimes = 0
function interact(interval: number) {
basic.clearScreen()
i = 1
while (i < interval + 1) {
basic.showString("" + ("" + fibo(i)))
basic.pause(100)
basic.clearScreen()
i += 1
}
}
function fibo(n: number): number {
if (n == 1) {
return 1
} else if (n == 2) {
return 1
} else {
return fibo(n - 1) + fibo(n - 2)
}
}
function numElements() {
while (bclicked < 1) {
if (input.buttonIsPressed(Button.A)) {
basic.showString("A")
basic.clearScreen()
atimes += 1
basic.showString("" + ("" + atimes))
} else if (input.buttonIsPressed(Button.B)) {
basic.showString("B")
bclicked += 1
}
basic.pause(50)
}
basic.clearScreen()
basic.showString("Fibo")
interact(atimes)
}
function showIcon() {
basic.clearScreen()
music.startMelody(music.builtInMelody(Melodies.Entertainer), MelodyOptions.Once)
for (let index = 0; index < 4; index++) {
basic.showIcon(IconNames.SmallDiamond)
basic.pause(100)
basic.showIcon(IconNames.Diamond)
basic.pause(100)
}
basic.clearScreen()
basic.showString("Fibo")
basic.clearScreen()
}
basic.forever(function on_forever() {
music.setBuiltInSpeakerEnabled(true)
atimes = 0
bclicked = 0
showIcon()
basic.showString("A to input B to fibo")
numElements()
basic.pause(500)
})