-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathapp.js
94 lines (79 loc) · 3.33 KB
/
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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const readlineSync = require('readline-sync');
const Repository = require('./repository.js');
console.log('Welcome to Bowling Scorecard!');
console.log('Enter the score for each frame (roll 1 and roll 2). Press enter after each frame.');
console.log('Enter 10 for a strike.');
function play_game() {
const repository = new Repository();
for (let frame_number = 0; frame_number < 10; frame_number++) {
if (frame_number <= 8) {
process.stdout.write(`Frame ${frame_number + 1} - Roll 1: `);
let roll1 = parseInt(readlineSync.question(''));
while (roll1 > 10) {
console.log('VALUE INVALID');
console.log('---------------------------------------------------------------------------');
console.log('ENTER VALID SCORE');
process.stdout.write(`Frame ${frame_number + 1} - Roll 1: `);
roll1 = parseInt(readlineSync.question(''));
}
if (roll1 === 10) {
repository.add_frame(roll1, 0, 0);
continue;
}
process.stdout.write('Roll 2: ');
let roll2 = parseInt(readlineSync.question(''));
while (roll1 + roll2 > 10) {
console.log('VALUE INVALID');
console.log('---------------------------------------------------------------------------');
console.log('ENTER VALID SCORE');
process.stdout.write('Roll 2: ');
roll2 = parseInt(readlineSync.question(''));
}
repository.add_frame(roll1, roll2, 0);
} else if (frame_number === 9) {
process.stdout.write(`Frame ${frame_number + 1} - Roll 1: `);
let roll1 = parseInt(readlineSync.question(''));
while (roll1 > 10) {
console.log('VALUE INVALID');
console.log('---------------------------------------------------------------------------');
console.log('ENTER VALID SCORE');
process.stdout.write(`Frame ${frame_number + 1} - Roll 1: `);
roll1 = parseInt(readlineSync.question(''));
}
process.stdout.write('Roll 2: ');
let roll2 = parseInt(readlineSync.question(''));
if (roll1 !== 10) {
while (roll1 + roll2 > 10) {
console.log('VALUE INVALID');
console.log('---------------------------------------------------------------------------');
console.log('ENTER VALID SCORE');
process.stdout.write('Roll 2: ');
roll2 = parseInt(readlineSync.question(''));
}
} else if (roll1 === 10) {
while (roll2 > 10) {
console.log('VALUE INVALID');
console.log('---------------------------------------------------------------------------');
console.log('ENTER VALID SCORE');
process.stdout.write('Roll 2: ');
roll2 = parseInt(readlineSync.question(''));
}
}
if (roll1 + roll2 >= 10) {
process.stdout.write('Roll 3: ');
const roll3 = parseInt(readlineSync.question(''));
while (roll3 > 10) {
console.log('VALUE INVALID');
console.log('---------------------------------------------------------------------------');
console.log('ENTER VALID SCORE');
process.stdout.write('Roll 3: ');
roll3 = parseInt(readlineSync.question(''));
}
repository.add_frame(roll1, roll2, roll3);
} else {
repository.add_frame(roll1, roll2, 0);
}
}
}
}
play_game();