-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.cpp
More file actions
43 lines (38 loc) · 1012 Bytes
/
Copy pathGame.cpp
File metadata and controls
43 lines (38 loc) · 1012 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
39
40
41
42
43
#include "Game.h"
class Game {
/// <summary>
/// Simulates the roll
/// </summary>
/// <param name="pins">Number of thrown pins</param>
public:void roll(int pins) {
rolls.at(currentRoll) = pins;
currentRoll++;
}
/// <summary>
/// Sum up the score of the throw.
/// </summary>
/// <returns>The score of the game</returns>
public:int score() {
int score = 0;
int roll = 0;
//Max 10 frames allowed
for (int i = 0; i < 10; i++) {
//Checks if the roll was a strike
if (rolls[roll] == 10) {
score += SumStrike(roll);
roll++;
}
//Checks if the roll was a spare
if (rolls[roll] + rolls[roll + 1] == 10) {
score += SumSpare(roll);
roll += 2;
}
else
{
score += SumTurn(roll);
roll += 2;
}
}
return score;
}
};