-
Notifications
You must be signed in to change notification settings - Fork 423
Expand file tree
/
Copy pathFrame.java
More file actions
64 lines (50 loc) · 1.57 KB
/
Frame.java
File metadata and controls
64 lines (50 loc) · 1.57 KB
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
package bowling;
import java.util.List;
public class Frame {
protected static final int HIT_TWICE = 2;
protected static final int HIT_TRIPLE = 3;
protected BowlingPin bowlingPin;
protected final HitRecords hitRecords;
public Frame() {
this.bowlingPin = new BowlingPin(BowlingPin.MAX_PIN_NUMBER);
this.hitRecords = new HitRecords();
}
public BowilingTerm hitBowlingPin(int count) {
bowlingPin = bowlingPin.hitPins(new BowlingPin(count));
if (hitRecords.hitOnce() && bowlingPin.isZero()) {
hitRecords.addSpare();
return BowilingTerm.SPARE;
}
if (strikeCondition()) {
hitRecords.addStrike();
return BowilingTerm.STRIKE;
}
if (count == BowlingPin.ZERO) {
hitRecords.addGutter();
return BowilingTerm.GUTTER;
}
hitRecords.addMiss(count);
return BowilingTerm.MISS;
}
protected boolean strikeCondition() {
return bowlingPin.isZero();
}
protected boolean finishFrame() {
return clearAllFrame() || hitRecords.hitTimes(HIT_TWICE);
}
public void chargeBowlingPin() {
bowlingPin = new BowlingPin(BowlingPin.MAX_PIN_NUMBER);
}
public List<HitRecord> getHitRecords() {
return hitRecords.getHitRecords();
}
public boolean clearAllFrame() {
return bowlingPin.isZero();
}
public void calculateBonus(int hitCount) {
hitRecords.calculateBonus(hitCount);
}
public HitRecords hitRecords() {
return hitRecords;
}
}