This repository was archived by the owner on May 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSnail.js
More file actions
510 lines (486 loc) · 17 KB
/
Copy pathSnail.js
File metadata and controls
510 lines (486 loc) · 17 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
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
const readline = require("readline");
var ta;
var rl;
// Переменные цветов
var green = "\x1b[32m";
var white = "\x1b[37m";
var red = "\x1b[31m";
var cyan = "\x1b[36m";
var yellow = "\x1b[33m";
// Переменные для игры (small change)
var day = 7;
var night = -2;
var count = 0;
var gamecount = 0;
var depth;
var answer;
var wasanswer = false;
let way = 0;
var zombieChance = 0;
var alreadyZombie = false;
var dead = false;
var coin = 0;
var min = 1;
var max = 100;
let life = 72;
console.info(white, "🎮 Игра начата 'улитка'");
console.info("\n\n❔ О чём игра: \n");
console.info(
"◼️ Маленькая улитка упала на дно колодца, и пытается выбраться наверх \n"
);
console.info(
"◼️ Улитки долго не живут, всего то 72 дня, так что ей стоит поторопиться! \n"
);
console.info("\n\n❔ Что делать: \n");
console.info("◼️ Вы указываете глубину колодца \n");
console.info("◼️ А дальше просто смотрите и молитесь за жизнь улитки :) \n");
console.info(green, "\n🎁 Бонусы: \n");
console.info(
"🚀 Джетпак: выталкивает улитку вверх на 25 м [Шанс 30% каждый день]\n"
);
console.info(
"🧟♂️Зомби: Даёт улитке ещё одну жизнь (72 дня) [Шанс 20% в конце жизни улитки]\n"
);
console.info(
"🍬 Конфета: Даёт улитке до 2 дополнительных жизней [Шанс 3% каждый день]\n"
);
console.info(cyan, "\n💠 Нейтральные предметы: \n");
console.info(
"💊 Волшебная таблетка: С некоторым шансом может либо добавить жизни улитке либо убавить. [Шанс найти таблетку 7%]\n"
);
console.info(
"🧿 Дыра в пространстве: Телепортирует улитку либо намного выше по колодцу, либо намного ниже [Шанс 5% каждый день]\n"
);
console.info(
"🐌 Тяга к свободе: В зависимости подавлена улитка или чувствует решительность, меняется ёё количесво пройденого\n пути за день [Шанс 6% каждый день]\n"
);
console.info(red, "\n🪨 Препятствия и ловушки: \n");
console.info(
"🪨 Камень: Может упасть на улитку и сдвинуть её либо немного ниже, либо сбросить на дно колодца. [Шанс 10% каждый день] [Шанс упасть на дно 37%]\n"
);
console.info(
"🕳️ Ямка на стене: Может задержать улитку на одном и том же месте до 8 дней! [Шанс 6% каждый день]\n"
);
console.info(
"💧 Дождь: Из-за него улитка может соскользнуть вниз [Шанс 4% каждый день]\n",
white
);
const timer = (ms) => new Promise((res) => setTimeout(res, ms));
// Глубина колодца
function Depth() {
if (gamecount >= 1) {
rl.close();
ta.close();
}
rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.question("🔽 Введите глубину колодца (м)\n", function (datastore) {
depth = datastore;
depth = parseInt(depth, 10);
console.clear();
console.log("🔽 Глубина колодца: " + depth + " м");
CountWay();
rl.close();
});
}
Depth();
// Сыграть ещё
function TryAgain() {
if (wasanswer == true) {
ta.close();
}
rl.close();
ta = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
wasanswer = true;
ta.question(
"♻️ Хотите попробовать ещё раз?\n[1]/[Да]/[Yes]/[y]\n[2]/[Нет]/[No]/[n]\n",
function (answerread) {
answer = answerread;
if (
answer == 1 ||
answer == "Да" ||
answer == "да" ||
answer == "y" ||
answer == "Yes" ||
answer == "yes"
) {
depth = 0;
life = 72;
way = 0;
day = 7;
night = -2;
count = 0;
zombieChance = 0;
alreadyZombie = false;
dead = false;
min = 1;
max = 100;
console.clear();
Depth();
return;
} else if (
answer == 2 ||
answer == "Нет" ||
answer == "нет" ||
answer == "n" ||
answer == "No" ||
answer == "no"
) {
console.log("🍂 Возвращайтесь ещё!");
ta.close();
} else {
console.clear();
TryAgain();
console.log("❌ Пожалуйста, введите только доступные ответы \n");
return;
}
}
);
}
// Тяга к свободе
function Freedom(freedomChance, freedomDay, freedomNight) {
if (freedomChance > 94) {
day = freedomDay;
night = freedomNight;
console.log(
`\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n`
);
if (freedomDay < 0) {
console.log(
red,
`\n~~ 🐌 Улитка выглядит подавленой. Теперь она ползёт каждый день ${yellow}${freedomDay}${red} м ~~`,
white
);
} else if (freedomDay == 0) {
console.log(
cyan,
`\n~~ 🐌 Улитка задумалась. Её отношение к происходящему не поменялось. ~~`,
white
);
} else {
console.log(
green,
`\n~~ 🐌 Улитка хочет на свободу ещё больше. Теперь она ползёт каждый день ${yellow}${freedomDay}${green} м ~~`,
white
);
}
if (freedomNight == 0) {
console.log(
green,
`~~ 🐌 Улитка задумалась ещё раз. Она всё же хочет на свободу и не будет отдыхать ночью. ~~\n`,
white
);
} else {
console.log(
red,
`~~ 🐌 Улитка подумала, что ей ещё далеко. Она сползает каждую ночь что-бы отдохнуть на ${yellow}${freedomNight}${red} м вниз ~~\n`,
white
);
}
console.log(
`\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n`
);
}
}
// Дождь
function Rain(rainWay, rainWayChance) {
if (rainWayChance > 96) {
way = way - rainWay;
console.log(
`\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n`
);
console.log(red, "\n~~ 💧 Начался дождь ~~");
if (rainWay == 0) {
console.log(
cyan,
`~~ 💧 Улитка пыталась держаться изо всех сил, и у неё это получилось! Она не сползла ни на метр ~~\n`,
white
);
} else {
console.log(
`~~ 💧 Улитка попала под дождь и сползла на ${yellow}${rainWay}${red} м вниз ~~\n`,
white
);
}
console.log(
`\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n`
);
}
}
// Конфета
function Candy(candyLife, candyLifeChance) {
if (candyLifeChance > 97) {
life = life + candyLife;
if (candyLife == 0) {
console.log(
cyan,
`\n~~ 🍬 Конфета была конечно вкусной, но кажется, она ничего не дала... ~~\n`,
white
);
} else {
console.log(
green,
`\n~~ 🍬 Попробовав эту вкусную конфету, улитке захотелось жить на ${yellow}${candyLife}${green} день(дня) больше ~~\n`,
white
);
}
}
}
// Ямка на стене
function WallHole(wallHole, wallHoleChance) {
if (wallHoleChance > 94) {
count = count + wallHole;
if (wallHole > 0) {
console.log(
red,
`\n~~ 🕳️⏬ Вы попали в ямку на стене колодца и задержались там на${yellow}${wallHole}${red} дней ~~\n`,
white
);
} else if (wallHole == 0) {
console.log(
cyan,
`\n~~ 🕳️ Вы попали в ямку на стене колодца, но улитка сумела сразу выбраться от туда ~~\n`,
white
);
}
}
}
// Дыра в пространстве
function TimeHole(timeHole, timeHoleChance) {
if (timeHoleChance > 95) {
console.log(
`\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n`
);
console.log(cyan, `~~ 🧿 Оу.. Улитку засосало в дыру в пространстве... ~~`);
way = way + timeHole;
if (way < 0) {
way = 0;
}
if (timeHole < 0) {
console.log(
red,
`~~ 🧿⏬ Улитку выбросило из дыры на ${yellow}${timeHole}${red} м вниз, и теперь она проползла ${yellow}${way}${red} м ~~`,
white
);
} else if (timeHole == 0) {
console.log(
cyan,
`~~ 🧿 Хех, улитку выбросило назад из той же дыры и она осталась на том же месте ~~`,
white
);
} else {
console.log(
green,
`~~ 🧿⏫ Ого! Улитку выбросило из дыры на ${yellow}${timeHole}${green} м вверх! Теперь она проползла ${yellow}${way}${green} м ~~`,
white
);
}
console.log(
`\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n`
);
}
}
// Волшебная таблетка
function PillBuff(magicPill, magicPillChance) {
if (magicPillChance > 93) {
if (magicPill < 0) {
console.log(
red,
`\n~~ 💊⏬Вы нашли плохую волшебную таблеточку. Вы будете жить на ${yellow}${magicPill}${red} дня меньше ~~\n`,
white
);
} else if (magicPill == 0) {
console.log(
cyan,
`\n~~ 💊Вы нашли таблетку пустышку. Кому вообще пришлов голову выпускать такие таблетки? ~~\n`,
white
);
} else {
console.log(
green,
`\n~~ 💊⏫Вы нашли хорошую волшебную таблеточку. Вы будете жить ещё на ${yellow}${magicPill}${green} дня больше ~~\n`,
white
);
}
life = life + magicPill;
}
}
// Джетпак
function JetPack(chance, boost) {
if (chance > 70) {
way = way + boost;
console.log(
green,
`~~ 🚀 Улитка нашла джетпак и теперь она проползла ${yellow}${way}${green} м ~~\n`,
white
);
}
}
// Камень
function Rock(rockChance, fallChance, depthFall) {
if (rockChance > 90) {
way = way - depthFall;
console.log(
`\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n`
);
console.log(red, "~~ 🪨На Вас упал камень ~~");
if (fallChance > 67) {
console.log("~~ 🐌Улитка свалилась в самый низ ~~", white);
way = 0;
} else {
console.log(
cyan,
"~~ 🧱Вы сумели зацепиться за стену и не упасть в самый низ ~~",
white
);
}
console.log(
`\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n`
);
}
}
// Проверка ленивой улитки
function LazySnail() {
if (day < night * -1) {
night = 0;
day = 0;
}
if (day == 0) {
if (day < night) {
night = 0;
console.log(red, `~~ 🐌 Улитка не хочет никуда ползти... ~~\n`, white);
}
}
if (night == day) {
console.log(red, `~~ 🐌 Улитка не хочет никуда ползти... ~~\n`, white);
}
if ((day == 0 && night == 0) || day == night * -1) {
console.log(red, `~~ 🐌 Улитка не хочет никуда ползти... ~~\n`, white);
}
}
// Обсчёт монет
function Coins() {
if (dead == false) {
coin = Math.floor(coin + way * 0.05 + count * 0.25 + 50);
} else {
coin = Math.floor(coin + way * 0.05 + count * 0.25);
}
}
// Основная функция рассчёта пути улитки и вывода сообщений
async function CountWay() {
while (way < depth) {
await timer(1000);
if (count < life) {
count++;
} else {
dead = true;
break;
}
//
Freedom(
Math.floor(Math.random() * (max - min) + min),
Math.floor(Math.random() * (20 - 0) + 0),
Math.floor(Math.random() * (0 - -10) + -10)
);
LazySnail();
Rain(
Math.floor(Math.random() * (197 - 0) + 0),
Math.floor(Math.random() * (max - min) + min)
);
Candy(
Math.floor(Math.random() * (2 - 0) + 0),
Math.floor(Math.random() * (max - min) + min)
);
WallHole(
Math.floor(Math.random() * (8 - 0) + 0),
Math.floor(Math.random() * (max - min) + min)
);
TimeHole(
Math.floor(Math.random() * (250 - -100) + -100),
Math.floor(Math.random() * (max - min) + min)
);
JetPack(Math.floor(Math.random() * (max - min) + min), 25);
PillBuff(
Math.floor(Math.random() * (10 - -5) + -5),
Math.floor(Math.random() * (max - min) + min)
);
Rock(
Math.floor(Math.random() * (max - min) + min),
Math.floor(Math.random() * (max - min) + min),
Math.floor(Math.random() * (50 - 5) + 5)
);
await timer(1000);
if (way < 0) {
way = 0;
}
way = way + day;
console.log("☀️ День " + count + ": " + way + " м");
if (way < depth) {
way = way + night;
console.log("🌙 Ночь " + count + ": " + way + " м");
} else {
break;
}
}
if (dead == true) {
zombieChance = Math.floor(Math.random() * (min - max + 1) + min) * -1;
if (alreadyZombie == true) {
gamecount++;
Coins();
console.log("\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
console.log(
"☠️🧟♂️ Улитка-зомби умерла на " + yellow + count + white + " дне"
);
console.log(`⏫ Всего улитка проползла ${yellow}${way}${white} м`);
console.log("\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
console.log(
"🎮 Игра окончена\n❌ Вы проиграли!" + ` Всего игр: ${gamecount}`
);
console.log(`🪙 Вы заработали ${coin} монет`);
TryAgain();
} else {
// Зомби
if (zombieChance > 80) {
console.log(
green,
"~~ 🧟♂️ Вам повезло, и после смерти, Вы стали зомби! ~~",
white
);
life = 72 * 2;
alreadyZombie = true;
dead = false;
CountWay();
} else {
Coins();
gamecount++;
console.log("\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
console.log("☠️ Улитка умерла на " + yellow + count + white + " дне");
console.log(`⏫ Всего улитка проползла ${yellow}${way}${white} м`);
console.log("\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
console.log(
"🎮 Игра окончена\n❌ Вы проиграли!" + ` Всего игр: ${gamecount}`
);
console.log(`🪙 Вы заработали ${coin} монет`);
TryAgain();
}
}
} else {
Coins();
gamecount++;
console.log("\n========================================\n");
console.log(
"🛣️ Улитка выползла из колодца на:" + yellow + count + white + " дне"
);
console.log("\n========================================\n");
console.log(
"🎮 Игра окончена\n✔️ Вы выиграли!🎆" + ` Всего игр: ${gamecount}`
);
console.log(`🪙 Вы заработали ${coin} монет`);
TryAgain();
}
}