16 changed files with 245 additions and 19 deletions
+2
View File
@@ -86,3 +86,5 @@ dkms.conf
*.out
*.app
# Custom
bin/*
+6 -2
View File
@@ -2,6 +2,10 @@ FROM gcc:latest
WORKDIR /app
COPY bin/Bowling /app/
COPY rolls.txt /app/
COPY include/* /app/include/
COPY src/* /app/src/
CMD ["./Bowling"]
RUN g++ src/*.cpp -o Bowling
CMD ["./Bowling", "rolls.txt"]
+18
View File
@@ -0,0 +1,18 @@
#ifndef PRINTFRAMES_H
#define PRINTFRAMES_H
#include <vector>
using namespace std;
class PrintFrames {
public:
PrintFrames();
~PrintFrames();
static void PrintHeader(vector<int> rolls);
static void PrintValue(vector<int> rolls);
};
#endif
+6 -1
View File
@@ -1,3 +1,8 @@
# Bowling
If you want to try out the project, please use git clone with the HTTPS link to the repo, and not the SSH link, as only the owner can pull and push via SSH.
To run the project, simply follow these steps:
1. `git clone https://git.rbwr.dk/owner/Bowling.git`
2. `docker build -t bowling .`
3. `docker run --rm bowling`
To change bowling score, simply edit the `rolls.txt` file, and build the docker image again.
+13
View File
@@ -0,0 +1,13 @@
#ifndef FILEHELPER_H
#define FILEHELPER_H
class FileHelper {
public:
FileHelper();
~FileHelper();
static bool FileExists(char *path);
};
#endif
+16
View File
@@ -0,0 +1,16 @@
#ifndef FILEREADER_H
#define FILEREADER_H
#include <string>
#include <vector>
class FileReader {
public:
FileReader();
~FileReader();
static std::string GetFile(char *path);
};
#endif
+18
View File
@@ -0,0 +1,18 @@
#ifndef NUMBERHELPER_H
#define NUMBERHELPER_H
#include <string>
#include <vector>
using namespace std;
class NumberHelper {
public:
NumberHelper();
~NumberHelper();
static vector<int> GetNumbers(string csv);
};
#endif
+18
View File
@@ -0,0 +1,18 @@
#ifndef PRINTFRAMES_H
#define PRINTFRAMES_H
#include <vector>
using namespace std;
class PrintFrames {
public:
PrintFrames();
~PrintFrames();
static void PrintHeader(vector<int> rolls);
static void PrintValue(vector<int> rolls);
};
#endif
+18
View File
@@ -0,0 +1,18 @@
#ifndef SCORECALCULATOR_H
#define SCORECALCULATOR_H
#include <string>
#include <vector>
using namespace std;
class ScoreCalculator {
public:
ScoreCalculator();
~ScoreCalculator();
static int GetScore(vector<int> rolls);
};
#endif
-2
View File
@@ -1,3 +1 @@
2, 3, 5, 4, 9, 1, 2, 5, 3, 2, 4, 2, 3, 3, 4, 6, 10, 3, 2
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10
+1 -1
View File
@@ -1,4 +1,4 @@
#include "../Include/FileHelper.h"
#include "../include/FileHelper.h"
#include <sys/stat.h>
FileHelper::FileHelper() {};
+1 -1
View File
@@ -1,4 +1,4 @@
#include "../Include/FileReader.h"
#include "../include/FileReader.h"
#include <string>
#include <fstream>
+1 -1
View File
@@ -1,4 +1,4 @@
#include "../Include/NumberHelper.h"
#include "../include/NumberHelper.h"
#include <string>
#include <sstream>
#include <vector>
+116
View File
@@ -0,0 +1,116 @@
#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;
}
}
}
+2 -2
View File
@@ -1,14 +1,14 @@
#include "../Include/ScoreCalculator.h"
#include "../include/ScoreCalculator.h"
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) {
+9 -9
View File
@@ -1,9 +1,10 @@
#include <iostream>
#include <string>
#include "../Include/FileReader.h"
#include "../Include/FileHelper.h"
#include "../Include/NumberHelper.h"
#include "../Include/ScoreCalculator.h"
#include "../include/FileReader.h"
#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;
}