Skip to content
Snippets Groups Projects
Commit 224d653a authored by lokesvelland's avatar lokesvelland
Browse files

Merge branch 'master' of gitlab.stud.idi.ntnu.no:magnuswj/prog-1004-2022-group-4

parents b3cdc68d bee57832
Branches
No related tags found
No related merge requests found
...@@ -40,9 +40,9 @@ public: ...@@ -40,9 +40,9 @@ public:
}; };
void writePlayer() const; void writePlayer() const;
void updatePlayer(); void updatePlayer();
int playerWin() { wins = 0; }; void playerWin() {wins = 0;};
int playerDraws() { draws = 0; }; void playerDraws() {draws = 0;};
float playerScore() { score = 0; }; void playerScore() {score = 0;};
void calculateScore(); void calculateScore();
void writeToFilePlayer(ofstream &out); void writeToFilePlayer(ofstream &out);
void readFromFilePlayer(ifstream &in); void readFromFilePlayer(ifstream &in);
...@@ -51,10 +51,9 @@ public: ...@@ -51,10 +51,9 @@ public:
class Tournament class Tournament
{ {
private: private:
int tableNr[gTables]; // these will only work if gTables is a const? vector <int *> tableNr;
string player1[gTables], vector <string *> player1;
player2[gTables]; vector <string *> player2;
public: public:
void writeTournament(); void writeTournament();
void fillTableArray(); void fillTableArray();
...@@ -87,14 +86,18 @@ bool checkPlayers(); ...@@ -87,14 +86,18 @@ bool checkPlayers();
void skrivMeny(); void skrivMeny();
void writeToFile(); void writeToFile();
void readFromFile(); void readFromFile();
void writeToFileTournament();
void readFromFileTournament();
void amntTables();
int main()
{ int main() {
char command; char command;
// readFromFile(); readFromFile();
readFromFileTournament();
// ask for amount of tables amntTables();
skrivMeny(); skrivMeny();
command = lesChar("\nKommando"); command = lesChar("\nKommando");
...@@ -114,7 +117,8 @@ int main() ...@@ -114,7 +117,8 @@ int main()
command = lesChar("\nKommando"); command = lesChar("\nKommando");
} }
// writeToFile(); writeToFileTournament();
writeToFile();
return 0; return 0;
} }
...@@ -272,12 +276,10 @@ void Tournament::fillTableArray() ...@@ -272,12 +276,10 @@ void Tournament::fillTableArray()
* *
* @param out - the file being written to * @param out - the file being written to
*/ */
void Tournament::writeToFileTournament(ofstream &out) void Tournament::writeToFileTournament(ofstream & out){
{
for (int i = 0; i < gTables; i++) for(int i=0; i<gTables; i++){
{ out<< player1[i]
out << setw(STRLEN) << player1[i]
<< setw(STRLEN) <<player2[i] << setw(STRLEN) <<player2[i]
<< setw(STRLEN) <<tableNr[i] << setw(STRLEN) <<tableNr[i]
<< "\n"; << "\n";
...@@ -344,15 +346,33 @@ void enterResults() ...@@ -344,15 +346,33 @@ void enterResults()
* *
* @see - calculateScore() * @see - calculateScore()
*/ */
void viewResults() void viewResults(){
{ int temp[gPlayers.size()];
for (int i = 0; i < gPlayers.size(); i++) for(int i=0; i < gPlayers.size();i++){
{ gPlayers[i]->calculateScore(); //Calculates score for every player
gPlayers[i]->calculateScore();
for(int i=0; i<gPlayers.size(); i++){ //Sorts scores and puts it in an array
for(int j= i+1; j<gPlayers.size();i++){
if(gPlayers[i]->score < gPlayers[j]->score){
temp[i] = gPlayers[j]->score;
}
}
} }
} }
for(int i=0; i<gPlayers.size(); i++){ //For MVP-purposes no scores can be identical
cout<< temp[i] <<"\t";
for(int j=0; j<gPlayers.size(); i++){
if(gPlayers[j]->score == temp[i]){
cout<< gPlayers[j]->name;
}
cout<<"\n";
}
}
}
/** /**
* Create a new tournament, with black and white players and what table they're playing at * Create a new tournament, with black and white players and what table they're playing at
* @see writeTournament() * @see writeTournament()
...@@ -558,6 +578,19 @@ void readFromFileTournament() ...@@ -558,6 +578,19 @@ void readFromFileTournament()
infile.close(); infile.close();
} }
infile.close();
}
else else
cout<<"\nCouldn't find tournamentData.dta!\n"; cout<<"\nCouldn't find tournamentData.dta!\n";
}
/**
* Asks user for number of tables
*
*/
void amntTables(){
cout<<"How many tables do you have?\n";
gTables = lesInt("Tables:",1,200);
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment