-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.js
More file actions
46 lines (28 loc) · 727 Bytes
/
game.js
File metadata and controls
46 lines (28 loc) · 727 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
31
32
33
34
35
36
37
38
const ScoreCard = require('./scoreCard');
const Frame = require('./frame');
const FinalFrame = require('./finalFrame');
class Game {
constructor(rolls) {
this.scoreCard = getScoreCard(rolls);
}
score(){
return this.scoreCard.score();
}
}
module.exports = Game;
function getScoreCard(rolls){
var frames = [];
var ballNo = 0;
while(frames.length< 9){ //gives first 9 frames, deal with 10th separately
if(rolls[ballNo] === 10){
frames.push(new Frame(10,0));
ballNo++;
}
else {
frames.push(new Frame(rolls[ballNo],rolls[ballNo + 1]));
ballNo += 2;
}
}
finalFrame = new FinalFrame(rolls[ballNo], rolls[ballNo + 1], rolls[ballNo + 2]);
return new ScoreCard(frames,finalFrame);
}