-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.js
71 lines (59 loc) · 1.9 KB
/
display.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
const columnify = require('columnify');
const colors = require('colors');
const { DISPLAY, VALUES } = require('./config');
/* returns the console display value from a string */
const getDisplayFor = (value, deducted) => {
switch(value) {
case VALUES.UNKNOWN:
return DISPLAY.UNKNOWN;
case VALUES.MONSTER:
if (deducted) return DISPLAY.MONSTER_DEDUCTED;
return DISPLAY.MONSTER;
case VALUES.SMELL:
return DISPLAY.SMELL;
case VALUES.WIND:
return DISPLAY.WIND;
case VALUES.PORTAL:
return DISPLAY.PORTAL;
case VALUES.RIFT:
if (deducted) return DISPLAY.RIFT_DEDUCTED;
return DISPLAY.RIFT_VALUE;
default:
return value;
}
}
/* METHODS */
module.exports = (obj) => {
/* get pertinent values */
const matrix = obj._knowledge;
const deducted = obj._deducted;
const level = obj._level;
const score = obj._score;
const lastScoreDisplay = (obj._lastScore > 0) ? ('+' + String(obj._lastScore)).green : String(obj._lastScore).red;
/* ATH */
console.clear();
console.log("LEVEL : " + level);
console.log("SCORE : " + score + ' (' + lastScoreDisplay + ')');
if (obj.hasOwnProperty("_actionMessage")) console.log(">", obj._actionMessage);
else console.log(">")
/* GAME BOARD DISPLAY */
const line = new Array(matrix.length + 2);
const horizontalBorders = line.fill(DISPLAY.WALL);
const output = new Array(matrix.length);
// top border
output.unshift(horizontalBorders);
for(let x = 0; x < matrix.length; x++) {
const displayLine = Array();
// left border
displayLine.unshift(DISPLAY.WALL);
for(let y = 0; y < matrix.length; y++) {
displayLine.push(getDisplayFor(matrix[y][x], deducted[y][x]));
}
// right border
displayLine.push(DISPLAY.WALL);
output.push(displayLine);
}
// bottom border
output.push(horizontalBorders);
console.log(columnify(output, { showHeaders: false }));
}