fixed merge conflicts
authorNils Forssén <nilfo359@student.liu.se>
Tue, 28 Nov 2023 12:53:44 +0000 (13:53 +0100)
committerNils Forssén <nilfo359@student.liu.se>
Tue, 28 Nov 2023 12:53:44 +0000 (13:53 +0100)
1  2 
assets/data.json
assets/highscore.csv
src/States.cc

index 8a341b3b11131764c91739257e2435887abea3ff,63de909889547f521bf950ce4611f9b3b6cc93b7..05c496547c14ca17ae1971221966c052870124e2
      "game_constants":
      {
          "bottles_per_second" : 2,
 -        "game_time" : 3,
 +        "game_time" : 20,
          "yf_per_second": 0.125,
-         "bikes_per_second": 0.17
++        "bikes_per_second": 0.17,
+         "scoreboard" : 5
          
      },
      "map":
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391,16aabef13ad3fb9ac1e91cdea70899d077246e55..5d2ef842adfd5db7f2ca3c84df9b02a1852584ea
@@@ -1,0 -1,5 +1,5 @@@
 -Gorilla,0
+ Gorilla,4
+ Gorilla,3
+ Stina,2
+ Gorilla,2
++Gorilla,2
diff --cc src/States.cc
index 861618628c6929b922ada5842629bc2b859eaa1c,364841499708c9bf968b69fd2644fdee626227dc..874c966528d3c39da841941362d4236dcdd04dfe
@@@ -43,7 -42,7 +45,8 @@@ Game_state::Game_state() 
  
      bottle_texture.loadFromFile("assets/kir.png");
      YF_texture.loadFromFile("assets/YF.png");
 +    bike_texture.loadFromFile("assets/cyklist.png");
+     f.close();
  }
  
  void Game_state::update(Context &context)
      int remaining_time {static_cast<int>(data["game_constants"]["game_time"]) - static_cast<int>(game_time)};
      if (remaining_time < 0)
      {
 -        context.next_state = std::make_unique<Start_menu>();
+         // LÄGG ALLT NEDAN I GAME OVER MENYN.
+         std::string current_line{"Gorilla," + std::to_string(points)};
+         std::ifstream highscore_file_r{"assets/highscore.csv"};
+         std::vector<std::string> lines_read;
+         std::vector<std::string> lines_write;
+         for (std::string one_line; std::getline(highscore_file_r, one_line);lines_read.push_back(one_line));
+         bool added {false};
+         for (std::string::size_type line_count{0}; line_count < lines_read.size(); line_count++)
+         {   
+             if (!added && points > std::stoi(lines_read[line_count].substr(lines_read[line_count].find_first_of(',') + 1)))
+             {
+                 std::cout << "i loop" << std::endl;
+                 lines_write.push_back(current_line);
+                 added = true;
+             }
+             lines_write.push_back(lines_read[line_count]);
+         }
+         if (!added) lines_write.push_back(current_line);
+         
+            
+         if (lines_write.size() > data["game_constants"]["scoreboard"]) lines_write.pop_back();
+         highscore_file_r.close();
+         std::ofstream highscore_file_w{"assets/highscore.csv"};
+         for (std::string::size_type line_count{0}; line_count < lines_write.size(); highscore_file_w << lines_write[line_count++] << std::endl);
+         highscore_file_w.close();
 +        context.next_state = std::make_unique<GameOver_menu>();
          return;
      }
   
          time_since_last_yf = 0;
  
      }
 +    if(time_since_last_bike >= 1 / static_cast<float>(data["game_constants"]["bikes_per_second"]))
 +    {
 +        bike = std::make_unique<Bike_enemy>(bike_texture, data["bike_enemy"]);
 +        time_since_last_bike = 0;
 +    }
      enemy->update(context);
-     game_map->update(points, remaining_time);
+     game_map->update(player->get_collected(), points, remaining_time);
 -    if (yf.size()>0)
 +    if (yf != nullptr)
      {
 -        for(unsigned int i {0}; i < yf.size(); ++i)
 -        {
 -            yf[i]->update(context);
 -        }
 +        yf->update(context);
 +    }
 +    if(bike != nullptr)
 +    {
 +        bike->update(context);
      }
      
  }