Skip to content
Snippets Groups Projects
Commit 81aa04cc authored by Frederik Alexander Keens's avatar Frederik Alexander Keens
Browse files

Merge branch 'Game-ending' into 'main'

Implement the end screen on capture of hq

See merge request !37
parents f3eaad31 e2b34e99
No related branches found
No related tags found
2 merge requests!37Implement the end screen on capture of hq,!29Merge main into box2d to implement physics
...@@ -34,15 +34,16 @@ BuildingFaction Building::getFaction() ...@@ -34,15 +34,16 @@ BuildingFaction Building::getFaction()
return this->m_faction; return this->m_faction;
} }
void Building::switch_faction(BuildingFaction faction) bool Building::switch_faction(BuildingFaction faction)
{ {
this->m_faction = faction; this->m_faction = faction;
if (this->m_id == BuildingId::HEADQUARTER) if (this->m_id == BuildingId::HEADQUARTER)
{ {
std::cout << "The game is over!" << std::endl; return true;
} }
return false;
} }
// implement call to UI to show available units // implement call to UI to show available units
...@@ -105,7 +106,8 @@ std::vector<UnitId> Building::recruitableUnits() ...@@ -105,7 +106,8 @@ std::vector<UnitId> Building::recruitableUnits()
return {}; return {};
} }
BuildingId Building::getBuildingId() { BuildingId Building::getBuildingId()
{
return this->m_id; return this->m_id;
} }
......
...@@ -26,8 +26,10 @@ class Building ...@@ -26,8 +26,10 @@ class Building
Changes the faction to the specified one Changes the faction to the specified one
@param faction The new faction the unit will belong to @param faction The new faction the unit will belong to
@return true if building was a headquarter
*/ */
void switch_faction(BuildingFaction faction); bool switch_faction(BuildingFaction faction);
/* /*
checks if the tile ontop of the building is free checks if the tile ontop of the building is free
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "Unit.hpp" #include "Unit.hpp"
#include "highfive/H5File.hpp" #include "highfive/H5File.hpp"
#include "ui/Contextmenu.hpp" #include "ui/Contextmenu.hpp"
#include "ui/Endscreen.hpp"
#include "ui/Helpmenu.hpp" #include "ui/Helpmenu.hpp"
#include "ui/Pausemenu.hpp" #include "ui/Pausemenu.hpp"
#include <SDL.h> #include <SDL.h>
...@@ -29,7 +30,8 @@ Level::Level( ...@@ -29,7 +30,8 @@ Level::Level(
: m_name(name), m_width(width), m_height(height), m_tiles(tiles), m_selectedUnit(-1), : m_name(name), m_width(width), m_height(height), m_tiles(tiles), m_selectedUnit(-1),
m_selectedBuilding(-1), m_contextMenu(ContextMenu()), m_id(0), m_selectedBuilding(-1), m_contextMenu(ContextMenu()), m_id(0),
m_state(LevelState::SELECTING_STATE), m_state(LevelState::SELECTING_STATE),
m_currentPos(TileMarker(RENDERING_SCALE, 1, 1, m_width, m_height)), m_turnQ(turnQ) m_currentPos(TileMarker(RENDERING_SCALE, 1, 1, m_width, m_height)), m_turnQ(turnQ),
m_gameOver(false)
{ {
m_contextMenu.setOptions({"Move", "Info", "Wait"}); m_contextMenu.setOptions({"Move", "Info", "Wait"});
...@@ -179,6 +181,12 @@ int Level::selectBuilding(int tileX, int tileY) ...@@ -179,6 +181,12 @@ int Level::selectBuilding(int tileX, int tileY)
void Level::handleEvent(Engine& engine, SDL_Event& event) void Level::handleEvent(Engine& engine, SDL_Event& event)
{ {
if (m_gameOver)
{
engine.pushScene(std::make_shared<Endscreen>(Endscreen(m_turnQ.front())));
return;
}
if (event.type == SDL_KEYDOWN) if (event.type == SDL_KEYDOWN)
{ {
if (event.key.keysym.sym == SDLK_h) if (event.key.keysym.sym == SDLK_h)
...@@ -841,7 +849,8 @@ void Level::handleMenuActiveEvents(Engine& engine, SDL_Event& event) ...@@ -841,7 +849,8 @@ void Level::handleMenuActiveEvents(Engine& engine, SDL_Event& event)
UnitFaction u_f = m_units.at(m_selectedUnit).getFaction(); UnitFaction u_f = m_units.at(m_selectedUnit).getFaction();
BuildingFaction b_f = static_cast<BuildingFaction>(u_f); BuildingFaction b_f = static_cast<BuildingFaction>(u_f);
b.switch_faction(b_f); m_gameOver = b.switch_faction(b_f);
m_units.at(m_selectedUnit).setState(UnitState::UNAVAILABLE); m_units.at(m_selectedUnit).setState(UnitState::UNAVAILABLE);
m_state = LevelState::SELECTING_STATE; m_state = LevelState::SELECTING_STATE;
m_selectedBuilding = -1; m_selectedBuilding = -1;
......
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
#include "Tile.hpp" #include "Tile.hpp"
#include "Unit.hpp" #include "Unit.hpp"
#include "ui/Contextmenu.hpp" #include "ui/Contextmenu.hpp"
#include "ui/Helpmenu.hpp"
#include "ui/Recruitingmenu.hpp" #include "ui/Recruitingmenu.hpp"
#include "ui/TileMarker.hpp" #include "ui/TileMarker.hpp"
#include "ui/Helpmenu.hpp"
#include <SDL.h> #include <SDL.h>
#include <array> #include <array>
#include <queue> #include <queue>
...@@ -122,6 +122,8 @@ class Level : public Scene ...@@ -122,6 +122,8 @@ class Level : public Scene
std::vector<std::pair<int, int>> m_attackableTiles; std::vector<std::pair<int, int>> m_attackableTiles;
bool m_gameOver;
private: private:
std::string m_name; std::string m_name;
int m_width; int m_width;
...@@ -170,7 +172,6 @@ class Level : public Scene ...@@ -170,7 +172,6 @@ class Level : public Scene
void handlePositionMarker(Engine& engine, SDL_Event& event); void handlePositionMarker(Engine& engine, SDL_Event& event);
std::pair<int, int> unit_fallback_position; std::pair<int, int> unit_fallback_position;
}; };
} // namespace advanced_wars } // namespace advanced_wars
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment