la till s.a gameover får json data
authorLukel495 <lukas.eliasson@live.se>
Wed, 6 Dec 2023 11:26:21 +0000 (12:26 +0100)
committerLukel495 <lukas.eliasson@live.se>
Wed, 6 Dec 2023 11:26:21 +0000 (12:26 +0100)
assets/data.json
src/GameOver_menu.cc
src/States.cc

index 26006097548f801a33a7d0eebeb2b792129f6270..7044c14b0c7bf158a03f5830ddb5e1aa0d1a05cc 100644 (file)
     },
     "gameover_menu":
     {
+        "scoreboard" : 5,
         "texture": "assets/game_over.png",
-        "font" : "assets/fonts/Philosopher-Regular.ttf"
+        "font" : "assets/fonts/Philosopher-Regular.ttf",
+        "highscore_file": "assets/highscore.csv"
+
     },
     "pause_menu":
     {
index c19186cf4b529373a5f8cb1c57dc16bc19991c20..d034a8fc5f165a80793d0e8dd04d8a3f625681e3 100644 (file)
@@ -16,15 +16,17 @@ using json = nlohmann::json;
 GameOver_menu::GameOver_menu(int const points, json& params) : texture{}, texture2{}, sprite{}, rectangle{},  mouse_l{}, mouse_r{}, linetext{}, funfacttext{}, entertext{}, pointstext{}, 
                                                  playerInput{}, data{}, playerText{}, savetext{}, quittext{},  font{}, exit_game{false}, menu{false}, menu_index{1}, points{points}
 {
-    texture.loadFromFile("assets/game_over.png");
-    sprite.setTexture(texture);;
+    std::cout << params["texture"] << "hejsan" << std::endl;
+
+    texture.loadFromFile(params["texture"]);
+    sprite.setTexture(texture);
 
     sprite.setScale(S_SCALE_KOEFF, S_SCALE_KOEFF);
     sf::FloatRect gb {sprite.getGlobalBounds()};
     sprite.setPosition(0, 0);
 
     // load textfont
-    if ( !font.loadFromFile ("assets/fonts/Philosopher-Regular.ttf") )
+    if ( !font.loadFromFile (params["font"]) )
         throw std::invalid_argument ("Unable to load font");
 
 
@@ -240,7 +242,10 @@ void GameOver_menu::handle_input(sf::Event& event)
 
 //spara namn till fil
 void GameOver_menu::load_to_csv(sf::Text playertext)
-{
+{   
+    std::cout << data["highscore_file"] << "hej" << std::endl;
+    std::cout << data["game_constants"]["scoreboard"] << "hejdå" << std::endl;
+
     std::string current_line{playerText.getString() + ", " + std::to_string(points)};
 
     std::ifstream highscore_file_r{"assets/highscore.csv"};
@@ -265,7 +270,7 @@ void GameOver_menu::load_to_csv(sf::Text playertext)
     }
     
 
-    if (lines_write.size() > data["game_constants"]["scoreboard"]) lines_write.pop_back();
+    if (lines_write.size() > data["scoreboard"]) lines_write.pop_back();
 
     highscore_file_r.close();
 
index 10c375d305b4d595758e3ba41ac70f71c4eacdf5..5fabb60235051abf18b9dd05e8da76a161fc1b67 100644 (file)
@@ -65,7 +65,7 @@ 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<GameOver_menu>(points, data["game_constants"]);
+        context.next_state = std::make_unique<GameOver_menu>(points, data["gameover_menu"]);
         return;
     }