denmax
You can change this now in User CP.
- Reaction score
- 155
@camelCase & s3rius
I'm not sure if it is required or not, but may I ask for you real names, if it's okay with you? Even if you guys only 'directly' involved yourselves with the scoreboard, your teachings of classes, vectors, fstreams, and more, have been applied to other parts of the program. With that, I wanted to credit you guys for your heavy contribution to the project. Again, if that is okay with you.
Also, it seems my scoreboard causes the console to crash. I'm not sure why, so here are the final codes
SCOREBOARD CLASS
EXECUTION
PS:
hs is a global variable.
I'm not sure if it is required or not, but may I ask for you real names, if it's okay with you? Even if you guys only 'directly' involved yourselves with the scoreboard, your teachings of classes, vectors, fstreams, and more, have been applied to other parts of the program. With that, I wanted to credit you guys for your heavy contribution to the project. Again, if that is okay with you.
Also, it seems my scoreboard causes the console to crash. I'm not sure why, so here are the final codes
SCOREBOARD CLASS
JASS:
class Scoreboard{
public:
//Add player to vector
void AddPlayer(std::string name, int points){
Entry e;
e.name = name;
e.score = points;
m_scoreboard.push_back(e);
}
//Display scoreboard to console
void Print(string x){
int size = m_scoreboard.size();
if( size > 5){
size = 5;
}
cout << "*-------------------------- LEVEL " << x.c_str();
for(int i=0; i < size; ++i){
cout << "\n*----[" << (i+1) << "]-----";
cout << "\n*--Name:\t" << m_scoreboard<i>.name;
cout << "\n*--Score:\t" << m_scoreboard<i>.score;
}
}
//Save vector to text file
void Save(std::string x) {
string output;
output = "scoreboards/level";
output.append(x);
output.append(".txt");
ofstream HighScore(output.c_str(), ios::trunc);
for(int i=0; i < 6; ++i) {
HighScore << m_scoreboard<i>.name << "\n" << m_scoreboard<i>.score << "\n"; //\n acts as a delimiter for getline()
}
HighScore.close();
}
//Set contents of txt file to vector
void Load(std::string x) {
string line, output;
repeat = 0;
output = "scoreboards/level";
output.append(x);
output.append(".txt");
Entry e;
ifstream HighScore(output.c_str());
while ( repeat < 5 ) {
getline (HighScore, line);
e.name = line;
getline (HighScore, line);
e.score = atoi( line.c_str() );
m_scoreboard.push_back(e);
repeat++;
}
HighScore.close();
}
//bubble sort
void Sort() {
for(int x=0; x<m_scoreboard.size(); x++)
{
for(int y=0; y<m_scoreboard.size()-1; y++)
{
if(m_scoreboard[y].score < m_scoreboard[y+1].score)
{
Entry temporary = m_scoreboard[y+1];
m_scoreboard[y+1] = m_scoreboard[y];
m_scoreboard[y] = temporary;
}
}
}
}
//wipes the vector clean
void Wipe(){
for(std::vector<Entry>::iterator i = m_scoreboard.begin(); i != m_scoreboard.end(); ++i){
m_scoreboard.erase(i);
}
}
//checks if a similar name is present in the vector, then print it
//feature removed due to crashes
void Global(){
for(std::vector<Entry>::iterator i = m_scoreboard.begin(); i != m_scoreboard.end(); ++i){
if( i->name == playerName ){
cout << "\n*--Score:\t" << i->score;
}
}
}
private:
std::vector<Entry> m_scoreboard;
int repeat;
};
</i></i></i></i>
EXECUTION
JASS:
switch (menuInput) {
case 1:
hs.Load("1");
hs.Sort();
hs.Print("ONE");
cin.ignore();
break;
case 2:
hs.Load("2");
hs.Sort();
hs.Print("TWO");
cin.ignore();
break;
case 3:
hs.Load("3");
hs.Sort();
hs.Print("THREE");
cin.ignore();
break;
case 4:
hs.Load("4");
hs.Sort();
hs.Print("FOUR");
cin.ignore();
break;
case 5:
hs.Load("5");
hs.Sort();
hs.Print("FIVE");
cin.ignore();
break;
case 6:
hs.Load("6");
hs.Sort();
hs.Print("SIX");
cin.ignore();
break;
PS:
hs is a global variable.