Advertisement
markthema3

awful high score parser

Dec 10th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1.         std::string line;
  2.         std::ifstream infile("highscore.txt");
  3.         if (infile.is_open())
  4.         {
  5.             for (int i = 0; i < 10; i++)
  6.             {
  7.                 getline(infile, line);
  8.                 highscores[i] = line;
  9.             }
  10.             infile.close();
  11.         }
  12.         int k = 0;
  13.         for (int i = 0; i < 5; i++)
  14.         {
  15.             names[i] = highscores[k];
  16.             k++;
  17.             scores[i] = std::stof(highscores[k]);
  18.             k++;
  19.         }
  20.  
  21.         if (distance > scores[4]){
  22.             // prompt for name
  23.             std::string name = "Mark";
  24.             scores[4] = distance;
  25.             names[4] = name;
  26.             if (distance > scores[3]){
  27.                 scores[4] = scores[3];
  28.                 names[4] = names[3];
  29.                 scores[3] = distance;
  30.                 names[3] = name;
  31.                 if (distance > scores[2]){
  32.                     scores[3] = scores[2];
  33.                     names[3] = names[2];
  34.                     scores[2] = distance;
  35.                     names[2] = name;
  36.                     if (distance > scores[1]){
  37.                         scores[2] = scores[1];
  38.                         names[2] = names[1];
  39.                         scores[1] = distance;
  40.                         names[1] = name;
  41.                         if (distance > scores[0]){
  42.                             scores[1] = scores[0];
  43.                             names[1] = names[0];
  44.                             scores[0] = distance;
  45.                             names[0] = name;
  46.                         }
  47.                     }
  48.                 }
  49.             }
  50.         }
  51.         k = 0;
  52.         for (int i = 0; i < 5; i++)
  53.         {
  54.             highscores[k] = names[i];
  55.             k++;
  56.             highscores[k] = std::to_string(scores[i]);
  57.             k++;
  58.         };
  59.  
  60.         std::ofstream outfile("highscore.txt");
  61.         if (outfile.is_open())
  62.         {
  63.             for (int i = 0; i < 10; i++){
  64.                 outfile << highscores[i] << "\n";
  65.             }
  66.             outfile.close();
  67.         }
  68.  
  69.         score = std::to_string(distance);
  70.  
  71.         const char *s = score.c_str();
  72.  
  73.         const char *hsdisplay[10] = { highscores[0].c_str(), highscores[1].c_str(), highscores[2].c_str(), highscores[3].c_str(), highscores[4].c_str(), highscores[5].c_str(), highscores[6].c_str(), highscores[7].c_str(), highscores[8].c_str(), highscores[9].c_str() };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement