Skip to content
Snippets Groups Projects
Commit 7b18cbb2 authored by TheHresvelgian's avatar TheHresvelgian
Browse files

fixed bug with printing menu and adding new players id as well as printing incorrect table number

parent a0dcf355
Branches
No related tags found
No related merge requests found
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
*/ */
char lesChar(const char* t) { char lesChar(const char* t) {
char tegn; char tegn;
std::cout << t << ": "; std::cout << t;
std::cin >> tegn; std::cin.ignore(MAXCHAR, '\n'); std::cin >> tegn; std::cin.ignore(MAXCHAR, '\n');
return (toupper(tegn)); return (toupper(tegn));
} }
......
...@@ -25,7 +25,7 @@ void Tournament::enterResults() ...@@ -25,7 +25,7 @@ void Tournament::enterResults()
for (int i = 0; i < nrOfTables; ++i) for (int i = 0; i < nrOfTables; ++i)
{ {
int answer; 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 << playerList[searchByID(white[i],1)]->lastName
<< " as white and " << " as white and "
<< playerList[searchByID(black[i],1)]->lastName << playerList[searchByID(black[i],1)]->lastName
...@@ -57,6 +57,7 @@ void Tournament::enterResults() ...@@ -57,6 +57,7 @@ void Tournament::enterResults()
if(currentRound == nrOfRounds) if(currentRound == nrOfRounds)
{ {
finished=true;
endTournament(); endTournament();
} }
else else
...@@ -78,7 +79,7 @@ void Tournament::printTables() ...@@ -78,7 +79,7 @@ void Tournament::printTables()
currentRound++; currentRound++;
if (currentRound == 0) if (currentRound == 1)
{ {
vector<Player*> playersPlaying = playerList; vector<Player*> playersPlaying = playerList;
for (int i = 0; i < nrOfTables; ++i) for (int i = 0; i < nrOfTables; ++i)
......
...@@ -27,6 +27,7 @@ class Tournament ...@@ -27,6 +27,7 @@ class Tournament
int nrOfRounds; //amount of rounds the tournament has total 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>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 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 //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 virtual void enterResults(); //Enters the results after a round, goes through each table and asks the result before allowing the next round to start
......
...@@ -28,8 +28,8 @@ int main() ...@@ -28,8 +28,8 @@ int main()
{ {
char command; char command;
readFromFile(); // readFromFile();
readFromFileTournament(); // readFromFileTournament();
do do
{ {
...@@ -41,7 +41,7 @@ int main() ...@@ -41,7 +41,7 @@ int main()
{ {
menuToPrint=menuSetUp; menuToPrint=menuSetUp;
} }
else if (gTournaments[0]->nrOfRounds==gTournaments[0]->white.size()) else if (gTournaments[0]->finished)
{ {
menuToPrint=menuEnd; menuToPrint=menuEnd;
} }
...@@ -52,7 +52,7 @@ int main() ...@@ -52,7 +52,7 @@ int main()
cout << endl << menuToPrint; cout << endl << menuToPrint;
command = lesChar("\nCommand: "); command = lesChar("\nCommand: ");
cout << command; // cout << command;
switch (command) switch (command)
{ {
case 'S': case 'S':
...@@ -91,8 +91,8 @@ int main() ...@@ -91,8 +91,8 @@ int main()
}while (command != 'Q'); }while (command != 'Q');
writeToFileTournament(); // writeToFileTournament();
writeToFile(); // writeToFile();
return 0; return 0;
} }
......
...@@ -16,11 +16,14 @@ extern vector<Player*>playerList; ...@@ -16,11 +16,14 @@ extern vector<Player*>playerList;
void newPlayer(int id) void newPlayer(int id)
{ {
Player* newPlayer; Player* newPlayer;
if (searchByID(id,1)!=-1)
{
do do
{ {
cout << endl << "A player with this ID already exists, please try again!" << endl; cout << endl << "A player with this ID already exists, please try again!" << endl;
id = lesInt("Please offer a valid ID\n",0,10000); id = lesInt("Please offer a valid ID\n",0,10000);
}while(searchByID(id,1)!=-1); }while(searchByID(id,1)!=-1);
}
newPlayer = new Player; newPlayer = new Player;
newPlayer->playerID = id; newPlayer->playerID = id;
cout << endl << "Last name of player " << id << endl; cout << endl << "Last name of player " << id << endl;
......
...@@ -41,5 +41,6 @@ void startNewTournament() ...@@ -41,5 +41,6 @@ void startNewTournament()
newTournament->nrOfTables = lesInt("\nHow many tables should the tournament have?\n",1,1000); newTournament->nrOfTables = lesInt("\nHow many tables should the tournament have?\n",1,1000);
newTournament->currentRound = 0; newTournament->currentRound = 0;
newTournament->nrOfRounds = lesInt("\nHow many rounds should the tournament have?\n",1,20); newTournament->nrOfRounds = lesInt("\nHow many rounds should the tournament have?\n",1,20);
newTournament->finished=false;
gTournaments.push_back(newTournament); gTournaments.push_back(newTournament);
} }
\ 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