-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathballs.js
More file actions
139 lines (129 loc) · 3.88 KB
/
balls.js
File metadata and controls
139 lines (129 loc) · 3.88 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
var lea_good = [
"lea0.png",
"lea1.png",
"lea2.png",
"lea3.png"
]
var lea_bad = [
"lea4.png",
"lea5.png",
"lea6.png"
]
// Lea isn't ugly
var lea = document.getElementById("lea");
var brackets_message = document.getElementById("brackets_message");
var releaseTheBalls = function (isGood) {
var lea_images = isGood ? lea_good : lea_bad;
lea.src = "res/" + lea_images[Math.floor(Math.random() * lea_images.length)];
brackets_message.setAttribute("style", isGood ? "display: none;" : "display: flex; flex-direction: column-reverse;");
brackets_message.innerHTML = "Unbalanced brackets (wait/meet) !";
}
var yay = function () {
lea.src = "res/lea7.png";
brackets_message.setAttribute("style", "display: flex; flex-direction: column-reverse;");
brackets_message.innerHTML = "For teh lulz!";
}
window.f = document.getElementById('f');
window.b = document.getElementById('b'); // code input
window.d = document.getElementById('d');
window.r = document.getElementById('r');
window.i = document.getElementById('i');
window.o = document.getElementById('o');
window.q = document.getElementById('q');
window.w = document.getElementById('w');
function x(input) {
var yayd = false;
input = input.split(' ');
var c = [];
for (var jj = 0; jj < input.length; jj++) {
var word = input[jj].trim().toLowerCase();
if (word) {
c.push(word);
}
}
var y = f.i,
commandsLength = c.length,
maxInt = 32768,
data = new Array(maxInt),
dataPointer = 0,
k = -1,
e = new Array(commandsLength),
l = new Array(commandsLength),
s = new Array(commandsLength),
m = 127,
n = -128
if (f.q.checked) {
m = Number.MAX_VALUE;
n = -(Number.MAX_VALUE)
}
for (j = 0; j < maxInt; j++) {
data[j] = 0
}
for (j = 0; j < commandsLength && dataPointer >= 0; j++) {
if (c[j].indexOf('wait') != -1 || c[j] == '[') {
l[++dataPointer] = j;
}
if (c[j].indexOf('meet') != -1 || c[j] == ']') {
s[j] = l[dataPointer];
e[l[dataPointer]] = j;
dataPointer--
}
}
if (dataPointer != 0) {
releaseTheBalls(false);
return
}
for (j = 0; j < commandsLength; j++) {
if (c[j].indexOf('how') != -1 || c[j] == '#') {
if (f.d.checked) {
window.alert('Position within code: ' + j + '\nPointer: ' + dataPointer + '\nValue at pointer: ' + data[dataPointer])
};
} else if (c[j].indexOf('bye') != -1 || c[j] == '<') {
dataPointer--;
if (dataPointer < 0) dataPointer = maxInt - 1;
} else if (c[j].indexOf('hi') != -1 || c[j] == '>') {
dataPointer++;
if (dataPointer >= maxInt) dataPointer = 0;
} else if (c[j].indexOf('lea') != -1 || c[j] == '+') {
if ((data[dataPointer] + 1) > m) data[dataPointer] = n;
else {
data[dataPointer]++
}
} else if (c[j].indexOf('nods') != -1 || c[j] == '-') {
if ((data[dataPointer] - 1) < n) data[dataPointer] = m;
else {
data[dataPointer]--
}
} else if (c[j].indexOf('meet') != -1 || c[j] == ']') {
j = s[j] - 1
} else if (c[j].indexOf('wait') != -1 || c[j] == '[') {
if (data[dataPointer] == 0) {
j = e[j];
}
} else if (c[j].indexOf('thanks') != -1 || c[j] == ',') {
if (k + 1 >= y.value.length) {
if (!f.r.checked) {
data[dataPointer] = 0;
continue
}
u = prompt("Input required. Press Cancel to halt program execution.", "")
if (u == '' || u == null) {
j = commandsLength;
continue
} else {
y.value += u
}
}
data[dataPointer] = y.value.charCodeAt(++k);
} else if (c[j].indexOf('sorry') != -1 || c[j] == '.') {
f.o.value += String.fromCharCode(data[dataPointer])
} else if (c[j].indexOf('why') != -1) {
yay();
yayd = true;
}
}
!yayd && releaseTheBalls(true);
if (f.w.checked) {
window.alert("Execution completed.")
}
} //