-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
38 lines (33 loc) · 916 Bytes
/
app.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
const readline = require('readline');
const BreathOfFantasy = require('./classes/BreathOfFantasy.js');
const game = new BreathOfFantasy();
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function addPlayer(playerNumber){
return new Promise((res,rej)=>{
this.question = function(){
rl.question(game.getPlayerQuestion(playerNumber), entry => {
let p = game.setPlayer(playerNumber, entry)
if(p.status){
res(entry)
} else {
console.log(p.errorMessage);
this.question();
}
})
};
this.question();
});
}
function initApp() {
addPlayer(1)
.then( _ => addPlayer(2) )
.then(_ => {
game.startBattle( attackResult => {
rl.close();
});
});
}
initApp();