From 7b18cbb2f88ff82e8fcfbd94680aeaf2d9b7bac7 Mon Sep 17 00:00:00 2001 From: TheHresvelgian <sigrunhog@hotmail.com> Date: Thu, 28 Apr 2022 22:21:41 +0200 Subject: [PATCH] fixed bug with printing menu and adding new players id as well as printing incorrect table number --- src/kode/LesData3.cpp | 2 +- src/kode/Tournament.cpp | 5 +++-- src/kode/Tournament.h | 1 + src/kode/checkmate.cpp | 12 ++++++------ src/kode/newPlayer.cpp | 11 +++++++---- src/kode/startNewTournament.cpp | 1 + 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/kode/LesData3.cpp b/src/kode/LesData3.cpp index aa1655a..777b819 100644 --- a/src/kode/LesData3.cpp +++ b/src/kode/LesData3.cpp @@ -25,7 +25,7 @@ */ char lesChar(const char* t) { char tegn; - std::cout << t << ": "; + std::cout << t; std::cin >> tegn; std::cin.ignore(MAXCHAR, '\n'); return (toupper(tegn)); } diff --git a/src/kode/Tournament.cpp b/src/kode/Tournament.cpp index ed098c0..a5b1d95 100644 --- a/src/kode/Tournament.cpp +++ b/src/kode/Tournament.cpp @@ -25,7 +25,7 @@ void Tournament::enterResults() for (int i = 0; i < nrOfTables; ++i) { int answer; - cout << endl << "Enter results for table " << i << "with " + cout << endl << "Enter results for table " << i+1 << "with " << playerList[searchByID(white[i],1)]->lastName << " as white and " << playerList[searchByID(black[i],1)]->lastName @@ -57,6 +57,7 @@ void Tournament::enterResults() if(currentRound == nrOfRounds) { + finished=true; endTournament(); } else @@ -78,7 +79,7 @@ void Tournament::printTables() currentRound++; - if (currentRound == 0) + if (currentRound == 1) { vector<Player*> playersPlaying = playerList; for (int i = 0; i < nrOfTables; ++i) diff --git a/src/kode/Tournament.h b/src/kode/Tournament.h index eea16fd..7c333da 100644 --- a/src/kode/Tournament.h +++ b/src/kode/Tournament.h @@ -27,6 +27,7 @@ class Tournament int nrOfRounds; //amount of rounds the tournament has total vector<int>white; //id of the players with white pieces in the current round, so white[0] is the id of the player with white pieces on table 1 vector<int>black; //id of the players with black pieces in the current round, so black[0] is the id of the player with black pieces on table 1 + bool finished; //white and black are reset each round, but still needs to be saved virtual void enterResults(); //Enters the results after a round, goes through each table and asks the result before allowing the next round to start diff --git a/src/kode/checkmate.cpp b/src/kode/checkmate.cpp index 045802b..b77e484 100644 --- a/src/kode/checkmate.cpp +++ b/src/kode/checkmate.cpp @@ -28,8 +28,8 @@ int main() { char command; - readFromFile(); - readFromFileTournament(); +// readFromFile(); + // readFromFileTournament(); do { @@ -41,7 +41,7 @@ int main() { menuToPrint=menuSetUp; } - else if (gTournaments[0]->nrOfRounds==gTournaments[0]->white.size()) + else if (gTournaments[0]->finished) { menuToPrint=menuEnd; } @@ -52,7 +52,7 @@ int main() cout << endl << menuToPrint; command = lesChar("\nCommand: "); - cout << command; + // cout << command; switch (command) { case 'S': @@ -91,8 +91,8 @@ int main() }while (command != 'Q'); - writeToFileTournament(); - writeToFile(); + // writeToFileTournament(); + // writeToFile(); return 0; } diff --git a/src/kode/newPlayer.cpp b/src/kode/newPlayer.cpp index 340fbe1..9f11032 100644 --- a/src/kode/newPlayer.cpp +++ b/src/kode/newPlayer.cpp @@ -16,11 +16,14 @@ extern vector<Player*>playerList; void newPlayer(int id) { Player* newPlayer; - do + if (searchByID(id,1)!=-1) { - cout << endl << "A player with this ID already exists, please try again!" << endl; - id = lesInt("Please offer a valid ID\n",0,10000); - }while(searchByID(id,1)!=-1); + do + { + cout << endl << "A player with this ID already exists, please try again!" << endl; + id = lesInt("Please offer a valid ID\n",0,10000); + }while(searchByID(id,1)!=-1); + } newPlayer = new Player; newPlayer->playerID = id; cout << endl << "Last name of player " << id << endl; diff --git a/src/kode/startNewTournament.cpp b/src/kode/startNewTournament.cpp index 26e90d2..c3c7ae3 100644 --- a/src/kode/startNewTournament.cpp +++ b/src/kode/startNewTournament.cpp @@ -41,5 +41,6 @@ void startNewTournament() newTournament->nrOfTables = lesInt("\nHow many tables should the tournament have?\n",1,1000); newTournament->currentRound = 0; newTournament->nrOfRounds = lesInt("\nHow many rounds should the tournament have?\n",1,20); + newTournament->finished=false; gTournaments.push_back(newTournament); } \ No newline at end of file -- GitLab