-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScorer.cpp
60 lines (50 loc) · 1020 Bytes
/
Scorer.cpp
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
//
// Created by knip on 11/08/19.
//
#include "Scorer.h"
void Scorer::AddThrow (int pins)
{
throws[currentThrow++] = pins;
}
bool Scorer::IsStrike (void)
{
return (10 == throws[ball]);
}
bool Scorer::IsSpare (void)
{
return (10 == (throws[ball]+throws[ball+1]));
}
int Scorer::NextTwoBallsForStrike (void)
{
return (throws[ball+1] + throws[ball+2]);
}
int Scorer::NextBallForSpare (void)
{
return throws[ball+2];
}
int Scorer::TwoBallsInFrame (void)
{
return (throws[ball] + throws[ball+1]);
}
int Scorer::ScoreForFrame (int frame)
{
int score = 0;
ball = 0;
for (int currentFrame = 0;
currentFrame < frame;
currentFrame++)
{
if (IsStrike())
{
score += 10 + NextTwoBallsForStrike();
ball += 1;
} else if (IsSpare()) {
score += 10 + NextBallForSpare();
ball += 2;
} else {
score += TwoBallsInFrame();
ball += 2;
}
}
return score;
}