forked from CorndelWithSoftwire/TableTennisTable-JS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (42 loc) · 1.04 KB
/
index.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
const app = require('./src/app');
const gameState = require('./src/league');
const readline = require('readline-sync');
const league = gameState.createLeague();
const game = app.startGame(league);
console.log(`Welcome to the table tennis table
=================================
Commands:
- add player <name>
Example:
add player Alice
- record win <winner> <loser>
Example:
record win Alice Bob
- print
Prints the current league
- winner
Prints the name of the player at the top of the league
- save <filepath>
Save the current league to a JSON file
Examples:
save my_league.json
save ~/some/directory/my_league.json
- load <filepath>
Load a saved league from a JSON file
Examples:
load my_league.json
load ~/some/directory/my_league.json
- quit
`);
let isGameActive = true;
while (isGameActive) {
const command = readline.prompt();
if (command === 'quit') {
isGameActive = false;
} else {
const response = game.sendCommand(command);
if (response) {
console.log(response);
}
}
}