diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-01 19:02:28 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-01 19:02:28 +0100 |
commit | 221b08e07246e84587b4144eca5564ce9ad3a20a (patch) | |
tree | d46a71a331ff51a92c1c332e57e0a7c88851a713 /frontend/GameController.cpp | |
parent | ca3e80a5b474d99391c253d3173117e955e33a20 (diff) |
implement leaderboard functionality
Diffstat (limited to 'frontend/GameController.cpp')
-rw-r--r-- | frontend/GameController.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/frontend/GameController.cpp b/frontend/GameController.cpp index d7b5f96..e015348 100644 --- a/frontend/GameController.cpp +++ b/frontend/GameController.cpp @@ -70,14 +70,17 @@ unique_ptr<Dungeon> GameController::make_dungeon() noexcept { void GameController::gameloop() { this->dungeon = make_dungeon(); Player & player = this->dungeon->get_player(); + GameData & gamedata = GameData::get_instance(); lprtf("Wat is de naam van je karakter?\n"); player.name = rl().c_str(); player.set_location(dungeon->get_start_location()); - player.equip(static_cast<WeaponObject *>(GameData::get_instance().create_object("Dolk"))); + player.equip(static_cast<WeaponObject *>(gamedata.create_object("Dolk"))); cmdset_default(); + bool is_dead = false, last_is_dead = false; + this->playing = true; while (this->playing) { string line = rl(); @@ -88,8 +91,15 @@ void GameController::gameloop() { lprtf("FOUT: %s.\n", e.what()); } - if (player.is_dead()) - cmdset_death(); + last_is_dead = is_dead; + is_dead = player.is_dead(); + bool just_died = last_is_dead == false && is_dead == true; + if (!just_died) continue; + + cmdset_death(); + gamedata.leaderbord_add(player.name.c_str(), player.gold); + str_print(strings::DEATH); + gamedata.leaderbord_print(); } } |