From 3fd7328f66a791179e9d80a43c6751da627eab1d Mon Sep 17 00:00:00 2001 From: rasmus Date: Wed, 19 Mar 2025 11:46:19 +0100 Subject: [PATCH] Add comments --- src/PrintFrames.cpp | 7 +++++-- src/ScoreCalculator.cpp | 14 ++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/PrintFrames.cpp b/src/PrintFrames.cpp index 6afdd39..58edc9b 100644 --- a/src/PrintFrames.cpp +++ b/src/PrintFrames.cpp @@ -10,7 +10,7 @@ void PrintFrames::printHeader(vector rolls){ // Strike if (rolls[frame] == 10) { - // If we're on our last frame, and roll a 10. + // If we're on our last frame, and roll a strike, we're given two bonus rolls. if (frame + 3 == rolls.size() && rolls[frame - 3] == 10) { cout << " f" << i << " |" << endl; break; @@ -22,6 +22,7 @@ void PrintFrames::printHeader(vector rolls){ // Spare else if (rolls[frame] + rolls[frame + 1] == 10) { + // If we're on our last frame, and roll a spare, we're given a bonus roll. if (frame + 3 == rolls.size() && rolls[frame] + rolls[frame + 1] == 10) { cout << " f" << i << " |" << endl; @@ -40,6 +41,7 @@ void PrintFrames::printHeader(vector rolls){ ++i; + // No more frames if (frame == rolls.size()) { cout << "|" << endl; break; @@ -55,7 +57,7 @@ void PrintFrames::printValue(vector rolls){ // Strike if (rolls[frame] == 10) { - // If we're on our last frame, and roll a 10. + // If we're on our last frame, and roll a strike, we're given two bonus rolls. if (frame + 3 == rolls.size() && rolls[frame - 3] == 10) { if (rolls[frame + 1] == 10 && rolls[frame + 2] == 10) { cout << "X, X, X|" << endl; @@ -82,6 +84,7 @@ void PrintFrames::printValue(vector rolls){ // Spare else if (rolls[frame] + rolls[frame + 1] == 10) { + // If we're on our last frame, and roll a spare, we're given a bonus roll. if (frame + 3 == rolls.size() && rolls[frame] + rolls[frame + 1] == 10) { cout << rolls[frame] << ", /" << ", " << rolls[frame + 1] << "|" << endl; diff --git a/src/ScoreCalculator.cpp b/src/ScoreCalculator.cpp index 79b92c3..5b5e147 100644 --- a/src/ScoreCalculator.cpp +++ b/src/ScoreCalculator.cpp @@ -7,7 +7,7 @@ int ScoreCalculator::getScore(vector rolls) { while (true) { // Strike if (rolls[frame] == 10) { - // If we're on our last frame, and roll a 10. + // If we're on our last frame, and roll a strike, we're given two bonus rolls. if (frame + 3 == rolls.size() && rolls[frame - 3] == 10) { score += 10 + rolls[frame + 1] + rolls[frame + 2]; break; @@ -15,11 +15,11 @@ int ScoreCalculator::getScore(vector rolls) { score += 10 + rolls[frame + 1] + rolls[frame + 2]; frame += 1; - continue; } // Spare - if (rolls[frame] + rolls[frame + 1] == 10) { + else if (rolls[frame] + rolls[frame + 1] == 10) { + // If we're on our last frame, and roll a spare, we're given a bonus roll. if (frame + 3 == rolls.size() && rolls[frame] + rolls[frame + 1] == 10) { score += 10 + rolls[frame + 1]; @@ -28,13 +28,15 @@ int ScoreCalculator::getScore(vector rolls) { score += 10 + rolls[frame + 2]; frame += 2; - continue; } // Open Frame - score += rolls[frame] + rolls[frame + 1]; - frame += 2; + else { + score += rolls[frame] + rolls[frame + 1]; + frame += 2; + } + // No more frames if (frame == rolls.size()) { break; }