-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.js
84 lines (84 loc) · 1.72 KB
/
calculator.js
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
let imageMultiply: Image = null
let imageAddition: Image = null
let imageMinus: Image = null
let imageDivide: Image = null
let mode: Image = null
let rhs = 0
let lhs = 0
let ans = 0
input.onGesture(Gesture.LogoUp, function () {
if (mode == imageAddition) {
mode = imageMinus
} else {
if (mode == imageMinus) {
mode = imageMultiply
} else {
if (mode == imageMultiply) {
mode = imageDivide
} else {
if (mode == imageDivide) {
mode = imageAddition
}
}
}
}
mode.showImage(0)
})
input.onButtonPressed(Button.AB, function () {
ans = 0
if (mode == imageAddition) {
ans = lhs + rhs
} else {
if (mode == imageMinus) {
ans = lhs - rhs
} else {
if (mode == imageMultiply) {
ans = lhs * rhs
} else {
if (mode == imageDivide) {
ans = lhs / rhs
}
}
}
}
basic.showNumber(ans)
lhs = 0
rhs = 0
})
input.onButtonPressed(Button.A, function () {
lhs += 1
basic.showNumber(lhs)
})
input.onButtonPressed(Button.B, function () {
rhs += 1
basic.showNumber(rhs)
})
imageDivide = images.createImage(`
. . # . .
. . . . .
# # # # #
. . . . .
. . # . .
`)
imageMinus = images.createImage(`
. . . . .
. . . . .
# # # # #
. . . . .
. . . . .
`)
imageAddition = images.createImage(`
. . # . .
. . # . .
# # # # #
. . # . .
. . # . .
`)
imageMultiply = images.createImage(`
# . . . #
. # . # .
. . # . .
. # . # .
# . . . #
`)
mode = imageDivide