Hey everyone,
Just trying to add to a scoreboard from a different class. The problem is that i'm not sure how to add to a scoreboard that has been previously defined in a different class. As i've instantiatied i'm assuming that has made a whole new Game (with a new scoreboard) so i'm guessing that i need to use the keyword this... Anyhelp will be appreciated
Game {
struct PlayerScore {
string name;
int score;
} noah, bam;
vector<PlayerScore> scores;
void Game::setup()
{
noah.name = "Noah";
noah.score = 300;
bam.name = "Bam";
bam.score = 1000;
scores.push_back(noah);
scores.push_back(bam);
}
void Game::HallofFame()
{
int temp = 1;
sort(scores.begin(), scores.end(), &Game::sortbyScore);
for (vector<PlayerScore>::iterator it = scores.begin(); it != scores.end(); ++it)
{
cout << temp << ". " << it->name << " - " << it->score << "\n";
temp++;
}
cout << "\n";
}
void Game::addtoHallofFame(Adventure a)
{
string playerName;
int adventureScore = a.getScore();
cout << "\nPlease enter you name: ";
cin >> playerName;
PlayerScore Player;
Player.name = playerName;
Player.score = adventureScore;
cout << Player.name << " ";
cout << Player.score;
cout << "\n\n";
scores.push_back(Player);
HallofFame();
}
}
Adventure {
int score = 0;
void Adventure::update(string arr[])
{
if ((arr[0] == "quit"))
{
Game g;
g.addtoHallofFame(*this);
}
}
}