forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rock_Paper_Scissors.js
372 lines (340 loc) · 8.95 KB
/
Rock_Paper_Scissors.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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/*
@title: Rock, Paper, Scissors!
@author: ezefranca
*/
const player = "p";
const rock = "r";
const paper = "a";
const scissor = "s";
const enemy = "e";
const wall = "w";
const line = "n"
const collum = "c"
const junction = "j"
const positions = [1, 2, 3]
const move = tune`
166.66666666666666,
166.66666666666666: c5-166.66666666666666,
166.66666666666666: b4-166.66666666666666,
4833.333333333333`;
const draw = tune`
167.5977653631285: c4~167.5977653631285,
167.5977653631285: d4~167.5977653631285,
167.5977653631285: e4~167.5977653631285,
167.5977653631285,
167.5977653631285: b5~167.5977653631285,
167.5977653631285: b5~167.5977653631285,
167.5977653631285: a5~167.5977653631285,
167.5977653631285: f5~167.5977653631285,
167.5977653631285: d5~167.5977653631285,
167.5977653631285: b4~167.5977653631285,
167.5977653631285: g4~167.5977653631285,
167.5977653631285: e4~167.5977653631285,
167.5977653631285: d4~167.5977653631285,
167.5977653631285: d4~167.5977653631285,
167.5977653631285: c4~167.5977653631285,
167.5977653631285,
167.5977653631285: c4~167.5977653631285,
167.5977653631285: d4~167.5977653631285,
167.5977653631285: c4~167.5977653631285,
167.5977653631285: c4~167.5977653631285,
167.5977653631285: c4/167.5977653631285,
1843.5754189944134`;
const win = tune`
166.66666666666666: b5/166.66666666666666 + f5^166.66666666666666,
166.66666666666666: c5~166.66666666666666 + c4-166.66666666666666 + a5/166.66666666666666,
166.66666666666666: d5~166.66666666666666 + d4-166.66666666666666 + b5/166.66666666666666 + f5^166.66666666666666,
166.66666666666666: e5~166.66666666666666 + e4-166.66666666666666 + a5/166.66666666666666,
166.66666666666666: b4~166.66666666666666 + b5/166.66666666666666 + f5^166.66666666666666,
166.66666666666666: c5~166.66666666666666 + c4-166.66666666666666 + a5/166.66666666666666,
166.66666666666666: d5~166.66666666666666 + d4-166.66666666666666 + b5/166.66666666666666 + f5^166.66666666666666,
166.66666666666666: e5~166.66666666666666 + e4-166.66666666666666 + a5/166.66666666666666,
166.66666666666666: d5~166.66666666666666 + d4-166.66666666666666 + b5/166.66666666666666 + f5^166.66666666666666,
166.66666666666666: c5~166.66666666666666 + c4-166.66666666666666 + a5/166.66666666666666,
166.66666666666666: b5/166.66666666666666 + f5^166.66666666666666,
166.66666666666666: b4~166.66666666666666 + c4-166.66666666666666 + a5/166.66666666666666,
166.66666666666666: e5~166.66666666666666 + e4-166.66666666666666 + b5/166.66666666666666 + f5^166.66666666666666,
166.66666666666666: c5~166.66666666666666 + d4-166.66666666666666 + a5/166.66666666666666,
166.66666666666666: a5/166.66666666666666 + c5~166.66666666666666 + f5^166.66666666666666,
166.66666666666666: a5/166.66666666666666 + c5~166.66666666666666,
166.66666666666666: a5/166.66666666666666 + c5~166.66666666666666 + b4~166.66666666666666 + a4~166.66666666666666 + g4~166.66666666666666,
166.66666666666666: f4~166.66666666666666 + e4~166.66666666666666 + d4~166.66666666666666 + f5^166.66666666666666,
2333.333333333333`;
const lose = tune`
166.66666666666666: g4~166.66666666666666 + c4/166.66666666666666,
166.66666666666666: g4~166.66666666666666 + c4/166.66666666666666,
166.66666666666666: g4~166.66666666666666,
166.66666666666666: d4~166.66666666666666,
166.66666666666666: d4~166.66666666666666,
166.66666666666666: f4~166.66666666666666 + d4/166.66666666666666,
166.66666666666666: f4~166.66666666666666 + d4/166.66666666666666,
166.66666666666666: f4~166.66666666666666,
166.66666666666666: d4~166.66666666666666,
166.66666666666666: d4~166.66666666666666,
166.66666666666666: g4-166.66666666666666,
166.66666666666666: f4-166.66666666666666,
166.66666666666666: e4-166.66666666666666,
166.66666666666666: d4-166.66666666666666,
166.66666666666666: c4-166.66666666666666,
166.66666666666666,
166.66666666666666: c4-166.66666666666666,
166.66666666666666: c4-166.66666666666666,
2333.333333333333`;
var enemyVictories = 0
var playerVictories = 0
var gameFinished = false;
showScore()
addText("Press j to confirm", { y: 1, color: [255, 255, 255] });
addText("Use w and s to move", { y: 3, color: [255, 255, 255] });
setLegend(
[player, bitmap`
4444444444444444
4444444444444444
4444444466644444
4444444463664444
4444444463366444
4666666663336644
4633333333333664
4633333333333364
4633333333333664
4666666663336644
4444444463366444
4444444463664444
4444444466644444
4444444444444444
4444444444444444
4444444444444444`],
[rock, bitmap`
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444440004444444
4444402200444444
4444002110004444
4440021111100444
44402111111L0444
44401111111L0444
444011111LL04444
44400LLLLLL04444
4444000000004444
4444444444444444
4444444444444444`],
[paper, bitmap`
4444444444444444
4442322222224444
444232LLLLLL2444
4442322222222444
4442321111112444
4442322222222444
4442321111112444
4442322222222444
4442321111122444
4442322222222444
4442321111112444
4442322222222444
4442321111222444
4442322222222444
4442322222222444
4444444444444444`],
[scissor, bitmap`
4444444444444444
4444441441444444
44444L1441L44444
4444LL1441LL4444
4444LL1441LL4444
4444LL1441LL4444
4444LL1441LL4444
4444LL1441LL4444
44444L1441L44444
4444441LL1444444
4444444LL4444444
444433L44L334444
4443443443443444
4443443443443444
4444334444334444
4444444444444444`],
[enemy, bitmap`
4444444444444444
4444444444444444
4444444444444444
4444400000444444
4444022222044444
4440222222204444
4402222222220444
4402002220020444
4402030203020444
4402222222220444
4440222022204444
4444022222044444
4444020202044444
4444000000044444
4444444444444444
4444444444444444`],
[wall, bitmap`
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444`],
[line, bitmap`
4444444444444444
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
[collum, bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
[junction, bitmap`
4444444444444444
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`]
);
setSolids([]);
let level = 0;
const levels = [
map`
nnnnn
wrcrw
pacaw
wscsw`,
];
setMap(levels[level]);
setPushables({
[player]: [],
});
onInput("w", () => {
if (gameFinished == false) {
playTune(move)
addSprite(0, getFirst(player).y, wall);
if (getFirst(player).y > 1) {
getFirst(player).y -= 1;
}
}
});
onInput("s", () => {
if (gameFinished == false) {
playTune(move)
addSprite(0, getFirst(player).y, wall);
if (getFirst(player).y < 4) {
getFirst(player).y += 1;
}
}
});
onInput("d", () => {
if (gameFinished == true) {
restart()
}
});
function restart() {
clearTile(4, 1);
clearTile(4, 2);
clearTile(4, 3);
addSprite(4, 1, wall);
addSprite(4, 2, wall);
addSprite(4, 3, wall);
clearText()
gameFinished = false;
showScore()
}
function showScore() {
addText("GAME" , {
x: 8,
y: 13,
color: [255, 255, 0]
});
addText(playerVictories + " " + enemyVictories , {
x: 8,
y: 15,
color: [255, 255, 255]
});
}
onInput("j", () => {
if (gameFinished == false) {
clearText();
var enemyPosition = positions[Math.floor(Math.random() * positions.length)];
var playerPosition = getFirst(player).y;
addSprite(4, enemyPosition, enemy);
if (enemyPosition == playerPosition) {
addText("Draw Game", {
y: 1,
color: [255, 255, 0]
});
playTune(draw)
} else if (playerPosition == 1 && enemyPosition == 2 ||
playerPosition == 2 && enemyPosition == 3 ||
playerPosition == 3 && enemyPosition == 1) {
addText("You Lose!", {
y: 1,
color: [255, 0, 0]
});
enemyVictories += 1
playTune(lose)
} else {
addText("You Win!", {
y: 1,
color: [0, 255, 0]
});
playerVictories += 1
playTune(win)
}
gameFinished = true;
addText("Press d to restart", {
y: 3,
color: [255, 255, 255]
});
}
});
afterInput(() => {
});