-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dice.js
45 lines (39 loc) · 1.43 KB
/
Dice.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
const c = require("chalk");
module.exports = class Dice {
value;
selected = false;
constructor(value) {
this.value = value || 1;
}
roll() {
this.value = Math.floor(Math.random() * 6 + 1);
}
pipIf(...numbers) {
return numbers.includes(this.value) ? "●" : " ";
}
toggle() {
this.selected = !this.selected;
}
// prettier-ignore
printRaw(row, number) {
switch (row) {
case 1:
process.stdout.write(c[['white', 'greenBright'][+this.selected]](`╭${'─'.repeat(7)}╮`));
break;
case 2:
process.stdout.write(`${c[['white', 'greenBright'][+this.selected]]('│')} ${this.pipIf(4,5,6)} ${this.pipIf(2,3,4,5,6)} ${c[['white', 'greenBright'][+this.selected]]('│')}`);
break;
case 3:
process.stdout.write(`${c[['white', 'greenBright'][+this.selected]]('│')} ${this.pipIf(6)} ${this.pipIf(1,3,5)} ${this.pipIf(6)} ${c[['white', 'greenBright'][+this.selected]]('│')}`);
break;
case 4:
process.stdout.write(`${c[['white', 'greenBright'][+this.selected]]('│')} ${this.pipIf(2,3,4,5,6)} ${this.pipIf(4,5,6)} ${c[['white', 'greenBright'][+this.selected]]('│')}`);
break;
case 5:
process.stdout.write(c[['white', 'greenBright'][+this.selected]](`╰${'─'.repeat(7)}╯`));
break;
case 6:
process.stdout.write(` ${number} ${this.selected ? c.greenBright('✔') : ' '} `);
}
}
};