/
puyo.js
52 lines (43 loc) · 1006 Bytes
/
puyo.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
const color = col => str => `\u001b[${col}m${str}\u001b[0m`
const colors = {
red: color('31'),
green: color('32'),
blue: color('34'),
magenta: color('35')
}
const puyoTypes =
process.platform === 'darwin'
? [' ', '🦄', '🐢', '🐬', '🐱']
: [' ', colors.red('●'), colors.green('▲'), colors.blue('■'), colors.magenta('★')]
class Puyo {
static isValidPuyoType (type) {
return Number.isInteger(type) && type > 0 && type < puyoTypes.length
}
constructor (type) {
this.type = Puyo.isValidPuyoType(type) ? type : 0
// 消せるかどうか確認済みなら true
this.checked = true
}
output () {
process.stdout.write(puyoTypes[this.type])
}
clear () {
this.type = 0
}
isSpace () {
return this.type === 0
}
needToCheck () {
return !this.isSpace() && !this.checked
}
check () {
this.checked = true
}
uncheck () {
this.checked = false
}
}
module.exports = {
Puyo: Puyo,
puyoTypes: puyoTypes
}