-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (37 loc) · 985 Bytes
/
index.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
const consoleScreen = require('console-screen');
const screen = new consoleScreen();
let player1 = { space: '' };
let player2 = { space: '' };
let index = 0;
let message = 'ready..';
let won;
function getRandom(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
setInterval(() => {
screen.rendering(
` [${index} / ${screen.$.screenX}] ${message} won : ${won}\n\n\n${player1.space}*\n${player2.space}*`
);
index += 1;
if (index >= 25) {
message = 'start!';
if (player1.space.length <= screen.$.screenX - 4) {
player1.space += ' ';
if (getRandom(1, 2) === 1) {
player1.space += ' ';
}
} else {
if (!won) won = 'player1';
}
if (player2.space.length <= screen.$.screenX - 4) {
player2.space += ' ';
if (getRandom(1, 2) === 1) {
player2.space += ' ';
}
} else {
if (!won) won = 'player2';
}
}
}, 40);