-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
44 lines (33 loc) · 1.03 KB
/
app.ts
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
'use strict'
import createGame from './game.js';
const game = createGame();
let continueGame: boolean = true;
let gameResult: number = game.endGame;
let manualOrAuto: number = game.continueManual;
while(continueGame) {
try {
gameResult = await game.runGame(manualOrAuto);
if(gameResult === game.continueManual
|| gameResult === game.continueAuto) {
continueGame = true;
manualOrAuto = gameResult;
}
else if(gameResult === game.endGame) {
console.clear();
console.log(`Final scores\nYou: ${game.userScore}\nOpponent: ${game.computerScore}\n`);
console.log("Thanks for playing!\n");
continueGame = false;
}
}
catch(exception) {
//log exception
if(process.env.NODE_ENV === 'development') {
console.log(exception);
}
else {
console.error("The game has encountered an error and must close\n");
}
continueGame = false;
}
}
process.exit();