Print formated output with the frames and rolls now works
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
#include "../Include/PrintFrames.h"
|
||||
#include <iostream>
|
||||
|
||||
PrintFrames::PrintFrames() {};
|
||||
PrintFrames::~PrintFrames() {};
|
||||
|
||||
void PrintFrames::PrintHeader(vector<int> rolls){
|
||||
int frame = 0;
|
||||
int i = 1;
|
||||
|
||||
while (true) {
|
||||
cout << "|";
|
||||
|
||||
// Strike
|
||||
if (rolls[frame] == 10) {
|
||||
// If we're on our last frame, and roll a 10.
|
||||
if (frame + 3 == rolls.size() && rolls[frame - 3] == 10) {
|
||||
cout << " f" << i << " |" << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
cout << " f" << i << " ";
|
||||
|
||||
frame += 1;
|
||||
}
|
||||
|
||||
// Spare
|
||||
else if (rolls[frame] + rolls[frame + 1] == 10) {
|
||||
if (frame + 3 == rolls.size() && rolls[frame] + rolls[frame + 1] == 10)
|
||||
{
|
||||
cout << " f" << i << " |" << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
cout << " f" << i << " ";
|
||||
|
||||
frame += 2;
|
||||
}
|
||||
|
||||
// Open Frame
|
||||
else {
|
||||
cout << " f" << i << " ";
|
||||
frame += 2;
|
||||
}
|
||||
|
||||
++i;
|
||||
|
||||
if (frame == rolls.size()) {
|
||||
cout << "|" << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PrintFrames::PrintValue(vector<int> rolls){
|
||||
int frame = 0;
|
||||
|
||||
while (true) {
|
||||
cout << "|";
|
||||
|
||||
// Strike
|
||||
if (rolls[frame] == 10) {
|
||||
// If we're on our last frame, and roll a 10.
|
||||
if (frame + 3 == rolls.size() && rolls[frame - 3] == 10) {
|
||||
if (rolls[frame + 1] == 10 && rolls[frame + 2] == 10) {
|
||||
cout << "X, X, X|" << endl;
|
||||
}
|
||||
else if (rolls[frame + 1] == 0 && rolls[frame + 2] == 0) {
|
||||
cout << "X, -, -|" << endl;
|
||||
}
|
||||
else if (rolls[frame + 1] == 0) {
|
||||
cout << "X, -, " << rolls[frame + 2] << "|" << endl;
|
||||
}
|
||||
else if (rolls[frame + 2] == 0) {
|
||||
cout << "X, " << rolls[frame + 1] << ", -|" << endl;
|
||||
}
|
||||
else {
|
||||
cout << "X, " << rolls[frame + 1] << ", " << rolls[frame + 2] << "|" << endl;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
cout << "X ";
|
||||
|
||||
frame += 1;
|
||||
}
|
||||
|
||||
// Spare
|
||||
else if (rolls[frame] + rolls[frame + 1] == 10) {
|
||||
if (frame + 3 == rolls.size() && rolls[frame] + rolls[frame + 1] == 10)
|
||||
{
|
||||
cout << rolls[frame] << ", /" << ", " << rolls[frame + 1] << "|" << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
cout << rolls[frame] << ", /";
|
||||
|
||||
frame += 2;
|
||||
}
|
||||
|
||||
// Open Frame
|
||||
else {
|
||||
if (rolls[frame] == 0) {
|
||||
cout << "-" << ", " << rolls[frame + 1];
|
||||
}
|
||||
else if (rolls[frame + 1] == 0) {
|
||||
cout << rolls[frame] << ", -";
|
||||
}
|
||||
cout << "" << rolls[frame] << ", " << rolls[frame + 1];
|
||||
frame += 2;
|
||||
}
|
||||
|
||||
if (frame == rolls.size()) {
|
||||
cout << " |" << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,11 @@ ScoreCalculator::ScoreCalculator() {};
|
||||
ScoreCalculator::~ScoreCalculator() {};
|
||||
|
||||
int ScoreCalculator::GetScore(vector<int> rolls) {
|
||||
// Calculate score
|
||||
int score = 0;
|
||||
int frame = 0;
|
||||
|
||||
while (true) {
|
||||
// Strike
|
||||
if (rolls[frame] == 10) {
|
||||
// If we're on our last frame, and roll a 10.
|
||||
if (frame + 3 == rolls.size() && rolls[frame - 3] == 10) {
|
||||
|
||||
+5
-5
@@ -4,6 +4,7 @@
|
||||
#include "../Include/FileHelper.h"
|
||||
#include "../Include/NumberHelper.h"
|
||||
#include "../Include/ScoreCalculator.h"
|
||||
#include "../Include/PrintFrames.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -19,14 +20,13 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
string file = FileReader::GetFile(argv[1]);
|
||||
|
||||
vector<int> rolls = NumberHelper::GetNumbers(file);
|
||||
|
||||
PrintFrames::PrintHeader(rolls);
|
||||
PrintFrames::PrintValue(rolls);
|
||||
|
||||
int score = ScoreCalculator::GetScore(rolls);
|
||||
|
||||
|
||||
|
||||
cout << "Score: " << score << std::endl;
|
||||
cout << "Score: " << score << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user