-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrame.js
40 lines (37 loc) · 947 Bytes
/
Frame.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
"use strict";
const PINS_NUMBER = 10;
class Frame {
constructor() {
this.firstRoll = 0;
this.secondRoll = 0;
this.bonusPins = 0;
this.numRolls = 0;
}
roll(pins) {
if (this.numRolls == 0) {
this.firstRoll = pins;
}
else if (this.numRolls == 1) {
this.secondRoll = pins;
}
this.numRolls++;
}
bonus(pins) {
if (this.isStrike() || this.isSpare()) {
this.bonusPins = pins;
}
}
score() {
return this.firstRoll + this.secondRoll + this.bonusPins;
}
areFrameRollsFinished() {
return (this.numRolls >= 2) || ((this.numRolls == 1) && (this.isStrike()))
}
isStrike() {
return this.firstRoll == PINS_NUMBER;
}
isSpare() {
return (this.firstRoll != PINS_NUMBER) && ((this.firstRoll + this.secondRoll) == PINS_NUMBER);
}
}
module.exports = Frame;