-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.js
More file actions
30 lines (28 loc) · 940 Bytes
/
Copy pathgame.js
File metadata and controls
30 lines (28 loc) · 940 Bytes
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
#!/usr/bin/env node
let draw = require('./lib/draw.js'),
stateMod = require('./lib/state.js'),
inputHandler = require('./lib/input.js');
stateMod.loadState()
.then((state) => {
//set in raw mode and capture key strokes
process.stdin.setRawMode(true);
// for each data event from the standard input
process.stdin.on('data', (data) => {
// use the input handler
inputHandler(state, data.toString().trim(), {
onPlayerDead: (state) => {
let player = state.player;
if (player.hp === 0) {
let newState = stateMod.newState();
state = Object.assign(state, newState);
draw.newScreen(state);
}
},
onTurnOver: (state) => {
draw.updateScreen(state);
stateMod.saveState(state);
}
});
});
draw.newScreen(state);
});