From: Lukel495 Date: Wed, 6 Dec 2023 11:26:21 +0000 (+0100) Subject: la till s.a gameover får json data X-Git-Url: https://gitweb.forssennils.se/?a=commitdiff_plain;h=a68048c81b1cda50b244261cfe9c7757848d5ac7;p=TDDC76_proj.git la till s.a gameover får json data --- diff --git a/assets/data.json b/assets/data.json index 2600609..7044c14 100644 --- a/assets/data.json +++ b/assets/data.json @@ -62,8 +62,11 @@ }, "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": { diff --git a/src/GameOver_menu.cc b/src/GameOver_menu.cc index c19186c..d034a8f 100644 --- a/src/GameOver_menu.cc +++ b/src/GameOver_menu.cc @@ -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(); diff --git a/src/States.cc b/src/States.cc index 10c375d..5fabb60 100644 --- a/src/States.cc +++ b/src/States.cc @@ -65,7 +65,7 @@ void Game_state::update(Context &context) int remaining_time {static_cast(data["game_constants"]["game_time"]) - static_cast(game_time)}; if (remaining_time < 0) { - context.next_state = std::make_unique(points, data["game_constants"]); + context.next_state = std::make_unique(points, data["gameover_menu"]); return; }