diff --git a/src/game/combat_manager.cpp b/src/game/combat_manager.cpp index b0a1f4c..c32ee0f 100644 --- a/src/game/combat_manager.cpp +++ b/src/game/combat_manager.cpp @@ -10,15 +10,140 @@ */ #include "combat_manager.hpp" #include "gameplay_manager.hpp" + using Game::CombatManager; CombatManager::CombatManager(MenuManager &menu_manager) : menu_manager(menu_manager) {} -Nostd::Matrix::iterator CombatManager::get_item() { - auto &position = menu_manager.get_world().player.second; - return position.get_fragment()->items[position.get_y()][position.get_x()]; +void CombatManager::manage_items() { + auto item = get_item(); + if (item.value() != nullptr) { + auto &hero = menu_manager.get_world().player.first; + hero.interact(*item.value()); + menu_manager.set_message(Nostd::String(hero.name()) + .append(" found ") + .append(item.value()->name()) + .append("!")); + auto &items = menu_manager.get_world().items; + // erase the Item which is being consumed + for (auto p = items.begin(); p != items.end(); p++) + if (item.value() == &p->first) { + item.value() = nullptr; + items.erase(p, std::next(p)); + break; + } + } +} + +void CombatManager::manage_projectiles() { + auto &projectiles = menu_manager.get_world().projectiles; + auto &player = menu_manager.get_world().player; + for (auto p = projectiles.begin(); p != projectiles.end();) { + bool to_be_destroyed = p->first.is_expired(); + if (!to_be_destroyed) { + Nostd::Matrix::iterator enemy = + get_enemy(p->second); + if (p->first.was_casted_by_player()) { + // hit enemy + if (enemy.value() != nullptr) { + enemy.value()->kill(); + player.first.award(); + menu_manager.set_message(Nostd::String(enemy.value()->name()) + .append(" was hit by ") + .append(p->first.name()) + .append(".")); + enemy.value() = nullptr; + } + } else if (p->second == player.second) { + // hit player + player.first.interact(p->first); + to_be_destroyed = true; + menu_manager.set_message(Nostd::String(player.first.name()) + .append(" was hit by ") + .append(p->first.name()) + .append("!")); + } + if (!to_be_destroyed) { + // move projectile + Nostd::Matrix::iterator projectile_pointer = + get_projectile(p->second); + projectile_pointer.value() = nullptr; + if (move_projectile(p->first, &p->second) && + GameplayManager::can_dig(get_mapunit(p->second))) { + projectile_pointer = get_projectile(p->second); + if (projectile_pointer.value() == nullptr) + projectile_pointer.value() = &p->first; + else + to_be_destroyed = true; + } else + to_be_destroyed = true; + } + } + if (to_be_destroyed) { + // destroy projectile + get_projectile(p->second).value() = nullptr; + p = projectiles.erase(p, std::next(p)); + } else { + p->first.count_movement(); + p++; + } + } +} + +void CombatManager::manage_enemies() { + auto &enemies = menu_manager.get_world().enemies; + auto &hero = menu_manager.get_world().player.first; + for (auto e = enemies.begin(); e != enemies.end();) { + bool to_be_destroyed = e->first.is_dead(); + auto enemy_pointer = get_enemy(e->second); + if (!to_be_destroyed) { + if (e->second == menu_manager.get_world().player.second) { + // the Enemy bumps into the player + hero.interact(e->first); + menu_manager.set_message(Nostd::String(hero.name()) + .append(" was hit by ") + .append(e->first.name()) + .append("!")); + to_be_destroyed = true; + } else + enemy_act(e); + } + // destroy Enemy + if (to_be_destroyed) { + e = enemies.erase(e, std::next(e)); + enemy_pointer.value() = nullptr; + } else + e++; + } } + +void CombatManager::use_skill() { + auto &hero = menu_manager.get_world().player.first; + hero.interact(hero.skill()); + menu_manager.set_message(Nostd::String(hero.name()) + .append(" used ") + .append(hero.skill().name()) + .append(".")); + cast_skill(hero.skill(), menu_manager.get_world().player.second); +} + +void CombatManager::use_superskill() { + auto &hero = menu_manager.get_world().player.first; + if (hero.attempt_super_skill()) { + hero.interact(hero.superskill()); + menu_manager.set_message(Nostd::String(hero.name()) + .append(" used ") + .append(hero.superskill().name()) + .append("!")); + cast_skill(hero.superskill(), menu_manager.get_world().player.second); + } else + menu_manager.set_message(Nostd::String(hero.name()) + .append(" lacks the mana for ") + .append(hero.superskill().name()) + .append("...")); +} + Data::MapUnit CombatManager::get_mapunit(World::Position position) { return position.get_fragment() ->map_chunk->at(position.get_y()) @@ -26,11 +151,9 @@ Data::MapUnit CombatManager::get_mapunit(World::Position position) { .value(); } -Nostd::Matrix::iterator -CombatManager::get_enemy(World::Position position) { - return position.get_fragment() - ->enemies.at(position.get_y()) - .at(position.get_x()); +Nostd::Matrix::iterator CombatManager::get_item() { + auto &position = menu_manager.get_world().player.second; + return position.get_fragment()->items[position.get_y()][position.get_x()]; } Nostd::Matrix::iterator @@ -40,8 +163,15 @@ CombatManager::get_projectile(World::Position position) { .at(position.get_x()); } -bool CombatManager::move_projectiles(Data::Pawns::Projectile projectile, - World::Position *position) { +Nostd::Matrix::iterator +CombatManager::get_enemy(World::Position position) { + return position.get_fragment() + ->enemies.at(position.get_y()) + .at(position.get_x()); +} + +bool CombatManager::move_projectile(Data::Pawns::Projectile projectile, + World::Position *position) { switch (projectile.get_x()) { // x case -1: if (!position->move_left()) @@ -70,8 +200,9 @@ void CombatManager::cast_skill(Data::Pawns::Skill skill, World::Position position) { for (auto projectile : skill.projectiles()) { World::Position projectile_position = position; - if (move_projectiles(projectile, &projectile_position) && + if (move_projectile(projectile, &projectile_position) && GameplayManager::can_dig(get_mapunit(projectile_position))) { + // the Projectile can be spawned menu_manager.get_world().projectiles.push_back( {projectile, projectile_position}); projectile_position.get_fragment() @@ -158,127 +289,3 @@ void CombatManager::enemy_act( cast_skill(e->first.skill(), e->second); } } - -void CombatManager::manage_items() { - auto item = get_item(); - if (item.value() != nullptr) { - auto &hero = menu_manager.get_world().player.first; - hero.interact(*item.value()); - menu_manager.set_message(Nostd::String(hero.name()) - .append(" found ") - .append(item.value()->name()) - .append("!")); - auto &items = menu_manager.get_world().items; - for (auto p = items.begin(); p != items.end(); p++) - if (item.value() == &p->first) { - item.value() = nullptr; - items.erase(p, std::next(p)); - break; - } - } -} - -void CombatManager::manage_projectiles() { - auto &projectiles = menu_manager.get_world().projectiles; - auto &player = menu_manager.get_world().player; - for (auto p = projectiles.begin(); p != projectiles.end();) { - bool to_be_destroyed = p->first.is_expired(); - if (!to_be_destroyed) { - Nostd::Matrix::iterator enemy = - get_enemy(p->second); - if (p->first.was_casted_by_player()) { - // hit enemy - if (enemy.value() != nullptr) { - enemy.value()->kill(); - player.first.award(); - menu_manager.set_message(Nostd::String(enemy.value()->name()) - .append(" was hit by ") - .append(p->first.name()) - .append(".")); - enemy.value() = nullptr; - } - } else if (p->second == player.second) { - // hit player - player.first.interact(p->first); - to_be_destroyed = true; - menu_manager.set_message(Nostd::String(player.first.name()) - .append(" was hit by ") - .append(p->first.name()) - .append("!")); - } - if (!to_be_destroyed) { - // move projectile - Nostd::Matrix::iterator projectile_pointer = - get_projectile(p->second); - projectile_pointer.value() = nullptr; - if (move_projectiles(p->first, &p->second) && - GameplayManager::can_dig(get_mapunit(p->second))) { - projectile_pointer = get_projectile(p->second); - if (projectile_pointer.value() == nullptr) - projectile_pointer.value() = &p->first; - else - to_be_destroyed = true; - } else - to_be_destroyed = true; - } - } - if (to_be_destroyed) { - // destroy projectile - get_projectile(p->second).value() = nullptr; - p = projectiles.erase(p, std::next(p)); - } else { - p->first.count_movement(); - p++; - } - } -} - -void CombatManager::manage_enemies() { - auto &enemies = menu_manager.get_world().enemies; - auto &hero = menu_manager.get_world().player.first; - for (auto e = enemies.begin(); e != enemies.end();) { - bool to_be_destroyed = e->first.is_dead(); - auto enemy_pointer = get_enemy(e->second); - if (!to_be_destroyed) { - if (e->second == menu_manager.get_world().player.second) { - hero.interact(e->first); - menu_manager.set_message(Nostd::String(hero.name()) - .append(" was hit by ") - .append(e->first.name()) - .append("!")); - to_be_destroyed = true; - } else - enemy_act(e); - // TODO - } - if (to_be_destroyed) { - e = enemies.erase(e, std::next(e)); - enemy_pointer.value() = nullptr; - } else - e++; - } -} -void CombatManager::use_skill() { - auto &hero = menu_manager.get_world().player.first; - hero.interact(hero.skill()); - menu_manager.set_message(Nostd::String(hero.name()) - .append(" used ") - .append(hero.skill().name()) - .append(".")); - cast_skill(hero.skill(), menu_manager.get_world().player.second); -} -void CombatManager::use_superskill() { - auto &hero = menu_manager.get_world().player.first; - if (hero.attempt_super_skill()) { - hero.interact(hero.superskill()); - menu_manager.set_message(Nostd::String(hero.name()) - .append(" used ") - .append(hero.superskill().name()) - .append("!")); - cast_skill(hero.superskill(), menu_manager.get_world().player.second); - } else - menu_manager.set_message(Nostd::String(hero.name()) - .append(" lacks the mana for ") - .append(hero.superskill().name()) - .append("...")); -} diff --git a/src/game/combat_manager.hpp b/src/game/combat_manager.hpp index 2c2bd05..a1217d2 100644 --- a/src/game/combat_manager.hpp +++ b/src/game/combat_manager.hpp @@ -14,29 +14,43 @@ #include "../world/random_generator.hpp" #include "../world/world.hpp" #include "menu_manager.hpp" -namespace Game { +namespace Game { +/*A CombatManager implements the combat logic, allowing items, + projectiles and enemies to take life. It also lets the player + cast their skills. + */ class CombatManager { +public: + CombatManager(MenuManager &); + + void manage_items(); + void manage_projectiles(); + void manage_enemies(); + void use_skill(); + void use_superskill(); + private: - Nostd::Matrix::iterator get_item(); MenuManager &menu_manager; + + World::RandomGenerator random_generator; + + // Returns the MapUnit/Item/Projectile/Enemy (or an iterator to it) + // in the given Position. Data::MapUnit get_mapunit(World::Position); - Nostd::Matrix::iterator get_enemy(World::Position); + Nostd::Matrix::iterator get_item(); Nostd::Matrix::iterator get_projectile(World::Position); - World::RandomGenerator random_generator; - bool move_projectiles(Data::Pawns::Projectile, World::Position *); + Nostd::Matrix::iterator get_enemy(World::Position); + + // Updates the Position of a Projectile, returning true if and only if + // this operation was successful. + bool move_projectile(Data::Pawns::Projectile, World::Position *); + + // Casts a new Skill starting from the given Position. void cast_skill(Data::Pawns::Skill, World::Position); void enemy_act( Nostd::List>::iterator); - -public: - CombatManager(MenuManager &); - void manage_items(); - void manage_projectiles(); - void manage_enemies(); - void use_skill(); - void use_superskill(); }; } // namespace Game diff --git a/src/game/game.cpp b/src/game/game.cpp index b2af2ac..d3be721 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -16,9 +16,11 @@ #include "../engine/menu/select.hpp" #include "../engine/menu/settings.hpp" #include "../engine/scene/scene.hpp" + #include #include #include + using Engine::Audio; using Engine::Drawable; using Engine::Menu::Main; @@ -39,8 +41,6 @@ Game::Game::~Game() { before_close(0); // useless parameter } -void Game::Game::before_close(int) { Audio::stop(); } - int Game::Game::run() { screen.set_content
(); while (running) { @@ -63,6 +63,7 @@ bool Game::Game::loop() { } else if (gameplay_manager.get_menu_manager().is_in_game()) { if ((frame / (fps / 10)) % 3 == 0) gameplay_manager.gravity(); + // refresh the screen screen.send_event(Engine::Drawable::Event::redraw); } @@ -168,3 +169,5 @@ void Game::Game::handle_keypress() { }; last_key = key; } + +void Game::Game::before_close(int) { Audio::stop(); } diff --git a/src/game/game.hpp b/src/game/game.hpp index 62ceb22..f4df37a 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -11,30 +11,41 @@ #ifndef GAME_GAME_HPP #define GAME_GAME_HPP + #include "../data/database.hpp" #include "../engine/screen.hpp" #include "../world/world.hpp" #include "combat_manager.hpp" #include "gameplay_manager.hpp" + namespace Game { + class Game { +public: + Game(); + ~Game(); + + // Execuies the main game loop and returns the exit codeo9 + int run(); + private: Data::Database db; Engine::Screen screen; + + GameplayManager gameplay_manager; + CombatManager combat_manager; + bool running = true; - int frame = 1; - static void before_close(int); + // the main game loop bool loop(); - void handle_keypress(); - GameplayManager gameplay_manager; + char last_key = '\0'; - CombatManager combat_manager; -public: - int run(); - Game(); - ~Game(); - ; + int frame = 1; + + void handle_keypress(); + + static void before_close(int); }; } // namespace Game diff --git a/src/game/gameplay_manager.cpp b/src/game/gameplay_manager.cpp index f67288b..e3bb5c2 100644 --- a/src/game/gameplay_manager.cpp +++ b/src/game/gameplay_manager.cpp @@ -25,15 +25,23 @@ bool GameplayManager::can_stand(Data::MapUnit u) { u == Data::MapUnit::enemy; } +bool GameplayManager::can_dig(Data::MapUnit u) { + return can_stand(u) || u == Data::MapUnit::platform; +} + void GameplayManager::gravity() { auto &player = menu_manager.get_world().player; auto &chunk = player.second.get_fragment()->map_chunk; if ((size_t)player.second.get_y() >= Data::MapChunk::height - 1) + // check the player's position is at the end of the screen die(); else { + // otherwise he go down one position auto unit_below = chunk->at(player.second.get_y() + 1).at(player.second.get_x()).value(); if (can_stand(unit_below) && !player.second.move_down()) + // check the underlying unit is empty and check if the player can't move + // down die(); } } @@ -41,6 +49,7 @@ void GameplayManager::gravity() { void GameplayManager::move_left() { auto &player = menu_manager.get_world().player; if (player.second.move_left()) { + // The player has moved successfully, now check if he is in a wall auto &chunk = player.second.get_fragment()->map_chunk; auto unit = chunk->at(player.second.get_y()).at(player.second.get_x()).value(); @@ -59,6 +68,7 @@ void GameplayManager::move_right() { player.second.move_left(); else if (std::next(player.second.get_fragment()) == menu_manager.get_world().environment.end()) { + // when moving right check if there is need to widen the world menu_manager.get_world().add_chunk(1); const size_t world_length = menu_manager.get_world().environment.size(), music_duration = @@ -81,16 +91,18 @@ void GameplayManager::move_right() { void GameplayManager::move_up() { auto &player = menu_manager.get_world().player; auto &chunk = player.second.get_fragment()->map_chunk; + // Check if the player has a unit below him if (player.second.get_y() + 1 < chunk->height) { auto unit_below = chunk->at(player.second.get_y() + 1).at(player.second.get_x()).value(); + // Prevent the player from escaping the map or jumping while falling if (player.second.get_y() != 0 && !can_stand(unit_below)) { auto unit_above = chunk->at(player.second.get_y() - 1) .at(player.second.get_x()) .value(); if (unit_above == Data::MapUnit::platform) { // dig platform - menu_manager.get_world().player.second.move_up(); - menu_manager.get_world().player.second.move_up(); + player.second.move_up(); + player.second.move_up(); } else { // attempt traditional jump int i = 2; while (player.second.get_y() > 0 && i > 0) { @@ -99,7 +111,7 @@ void GameplayManager::move_up() { .value(); if (!can_stand(unit_above)) break; - menu_manager.get_world().player.second.move_up(); + player.second.move_up(); i--; } } @@ -117,20 +129,10 @@ void GameplayManager::move_down() { auto unit_below = chunk->at(player.second.get_y() + 1).at(player.second.get_x()).value(); if (can_stand(unit_below)) - menu_manager.get_world().player.second.move_down(); + player.second.move_down(); } } -void GameplayManager::die() { - menu_manager.set_message(Nostd::String()); - menu_manager.get_settings_manager().play_soundtrack("main_menu"); - screen.send_event(Engine::Drawable::Event::interact); -} - -bool GameplayManager::can_dig(Data::MapUnit u) { - return can_stand(u) || u == Data::MapUnit::platform; -} - void GameplayManager::move_dig() { auto &player = menu_manager.get_world().player; auto &chunk = player.second.get_fragment()->map_chunk; @@ -138,6 +140,11 @@ void GameplayManager::move_dig() { chunk->at(player.second.get_y() + 1).at(player.second.get_x()).value(); if (!can_dig(unit_below)) return; - - menu_manager.get_world().player.second.move_down(); + player.second.move_down(); } + +void GameplayManager::die() { + menu_manager.set_message(Nostd::String()); + menu_manager.get_settings_manager().play_soundtrack("main_menu"); + screen.send_event(Engine::Drawable::Event::interact); +} \ No newline at end of file diff --git a/src/game/gameplay_manager.hpp b/src/game/gameplay_manager.hpp index 19fc9bc..50a4899 100644 --- a/src/game/gameplay_manager.hpp +++ b/src/game/gameplay_manager.hpp @@ -16,28 +16,30 @@ namespace Game { class GameplayManager { -private: - Engine::Screen &screen; - MenuManager menu_manager; - public: GameplayManager(Data::Database &, Engine::Screen &); + + // Returns a reference to the menu manager MenuManager &get_menu_manager(); + // Returns whether the player can stand/dig on the given MapUnit static bool can_stand(Data::MapUnit); static bool can_dig(Data::MapUnit); + void gravity(); void move_left(); void move_right(); void move_up(); void move_down(); - void die(); + // Brings down the player from a platoform void move_dig(); + void die(); - Nostd::Matrix::iterator get_item(); - void manage_items(); -}; +private: + Engine::Screen &screen; + MenuManager menu_manager; +}; } // namespace Game #endif diff --git a/src/game/menu_manager.cpp b/src/game/menu_manager.cpp index d5fe7ce..3ab2e3e 100644 --- a/src/game/menu_manager.cpp +++ b/src/game/menu_manager.cpp @@ -26,6 +26,14 @@ using Game::MenuManager; MenuManager::MenuManager(Data::Database &datab, Engine::Screen &scr) : db(datab), screen(scr), settings_manager(datab) {} +Game::SettingsManager &MenuManager::get_settings_manager() { + return settings_manager; +} + +World::World &MenuManager::get_world() { return *world; } + +Nostd::String Game::MenuManager::get_message() const { return message; } + bool MenuManager::change_content() { if (screen.is_content
()) { // do something when the main menu is exited @@ -49,7 +57,7 @@ bool MenuManager::change_content() { update_scoreboard(); delete world; world = nullptr; - in_game = true; + in_game = false; db.save_results(); screen.set_content &>( db.results()); @@ -76,27 +84,23 @@ bool MenuManager::change_content() { return true; } +bool MenuManager::is_in_game() { return in_game && world != nullptr; } + void MenuManager::update_scoreboard() { auto &scoreboard = db.results(); if (scoreboard.size() == 0) + // there are no other scores scoreboard.push_front(world->player.first); else { Nostd::List::iterator p; for (p = scoreboard.begin(); p != scoreboard.end() && *p >= world->player.first.score(); p++) - ; + ; // comparison between the new score and the old ones to put it + // it in the right position scoreboard.insert(p, world->player.first); } } -Game::SettingsManager &MenuManager::get_settings_manager() { - return settings_manager; -} - -bool MenuManager::is_in_game() { return in_game && world != nullptr; } void MenuManager::set_in_game(bool g) { in_game = g; } -World::World &MenuManager::get_world() { return *world; } - -const Nostd::String Game::MenuManager::get_message() const { return message; } void Game::MenuManager::set_message(const Nostd::String &str) { message = str; } diff --git a/src/game/menu_manager.hpp b/src/game/menu_manager.hpp index 5d41482..08e20ff 100644 --- a/src/game/menu_manager.hpp +++ b/src/game/menu_manager.hpp @@ -20,28 +20,39 @@ namespace Game { class MenuManager { +public: + MenuManager(Data::Database &, Engine::Screen &); + + // Returns a reference to the settings manager + SettingsManager &get_settings_manager(); + + // Returns a reference to the world + World::World &get_world(); + + // Returns the currently displayed message + Nostd::String get_message() const; + + // Gets called when a menu is closed.Decides what to display next + bool change_content(); + // Returns true if the player is in the game + bool is_in_game(); + + void update_scoreboard(); + // Updates the value of in_game + void set_in_game(bool); + // Updates the massage showed on the display + void set_message(const Nostd::String &); private: Data::Database &db; Engine::Screen &screen; World::World *world = nullptr; - SettingsManager settings_manager; - bool in_game = false; Nostd::String message = ""; -public: - MenuManager(Data::Database &, Engine::Screen &); - bool change_content(); - void update_scoreboard(); - SettingsManager &get_settings_manager(); - bool is_in_game(); - void set_in_game(bool); - World::World &get_world(); + SettingsManager settings_manager; - const Nostd::String get_message() const; - void set_message(const Nostd::String &); + bool in_game = false; }; - } // namespace Game #endif diff --git a/src/game/settings_manager.cpp b/src/game/settings_manager.cpp index f89c5ef..282e3ca 100644 --- a/src/game/settings_manager.cpp +++ b/src/game/settings_manager.cpp @@ -19,21 +19,11 @@ using std::cout; SettingsManager::SettingsManager(const Data::Database &datab) : db(datab) {} -void SettingsManager::apply_settings() { - for (auto x : db.settings()) { - if (x.label() == "Sounds") { - sound = *x.current_value(); - if (!sound) - Audio::stop(); - else if (Audio::status() == Audio::State::stopped) - play_soundtrack("main_menu"); - } else if (x.label() == "Frames per second") - fps = *x.current_value(); - } -} +bool SettingsManager::is_sound_on() { return sound; } int SettingsManager::play_soundtrack(const char fn[]) { if (sound) { + // absolute file path for the given file name. auto fp = db.to_audio_filepath(fn); switch (Audio::play(fp.c_str())) { case Audio::Error::none: @@ -55,4 +45,16 @@ int SettingsManager::play_soundtrack(const char fn[]) { int SettingsManager::get_fps() { return fps; } -bool SettingsManager::get_sound() { return sound; } +void SettingsManager::apply_settings() { + // Iterates over each setting pair. + for (auto x : db.settings()) { + if (x.label() == "Sounds") { + sound = *x.current_value(); + if (!sound) + Audio::stop(); + else if (Audio::status() == Audio::State::stopped) + play_soundtrack("main_menu"); + } else if (x.label() == "Frames per second") + fps = *x.current_value(); + } +} \ No newline at end of file diff --git a/src/game/settings_manager.hpp b/src/game/settings_manager.hpp index d904e43..acdf30c 100644 --- a/src/game/settings_manager.hpp +++ b/src/game/settings_manager.hpp @@ -19,19 +19,28 @@ namespace Game { class SettingsManager { -private: - const Data::Database &db; - int fps = 60; - bool sound = true; - public: SettingsManager(const Data::Database &); + + // Returns true if the sound is on. + bool is_sound_on(); + + // Plays the track identified in the input string, + // returns value 0 if it was successful, a positive integer otherwise int play_soundtrack(const char[]); - void apply_settings(); + // Returns the current fps value. int get_fps(); - bool get_sound(); -}; + // Updates the local fields based on the settings values. + void apply_settings(); + +private: + const Data::Database &db; + + bool sound = true; + + int fps = 60; +}; } // namespace Game #endif diff --git a/src/nostd/list.hpp b/src/nostd/list.hpp index 4f25102..15a5a52 100644 --- a/src/nostd/list.hpp +++ b/src/nostd/list.hpp @@ -222,7 +222,7 @@ template class List { sz++; } - // Removes from the list container either a single element (position) or a + // Removes from the list container either a // range of elements ([first,last)). // This effectively reduces the container size by the number of elements // removed, which are destroyed. diff --git a/src/nostd/list.test.cpp b/src/nostd/list.test.cpp index 11686e3..5108189 100644 --- a/src/nostd/list.test.cpp +++ b/src/nostd/list.test.cpp @@ -6,11 +6,12 @@ Andreea Scrob #989372 03/27/2021 - list.test.hpp: tests for Nostd::List + list.test.cpp: tests for Nostd::List */ #include "list.hpp" #include "test.hpp" + #include using namespace Nostd; @@ -61,6 +62,17 @@ int main() { assert(l.front() == 7); }); + it("changes the length of the list", [] { + List l; + l.push_back(278); + l.push_back(490); + l.push_back(89); + l.resize(2, 8); + assert(l.front() == 278); + assert(l.back() == 490); + assert(l.size() == 2); + }); + it("inserts new elements", [] { List l; l.insert(l.begin(), 3); @@ -88,17 +100,6 @@ int main() { assert(l.size() == 2); }); - it("changes the length of the list", [] { - List l; - l.push_back(278); - l.push_back(490); - l.push_back(89); - l.resize(2, 8); - assert(l.front() == 278); - assert(l.back() == 490); - assert(l.size() == 2); - }); - it("copy content from another list", [] { List l; l.push_back(3); diff --git a/src/nostd/vector.hpp b/src/nostd/vector.hpp index 7a98c0c..a0dadae 100644 --- a/src/nostd/vector.hpp +++ b/src/nostd/vector.hpp @@ -13,6 +13,7 @@ #define NOSTD_VECTOR_HPP #include "allocator.hpp" + #include #include #include diff --git a/src/nostd/vector.test.cpp b/src/nostd/vector.test.cpp index a27a998..1efbe16 100644 --- a/src/nostd/vector.test.cpp +++ b/src/nostd/vector.test.cpp @@ -6,11 +6,12 @@ Andreea Scrob #989372 03/24/2021 - vector.test.hpp: tests for Nostd::Vector + vector.test.cpp: tests for Nostd::Vector */ #include "vector.hpp" #include "pair.hpp" #include "test.hpp" + #include using namespace Nostd;