Fix syntax errors and warnings

This commit is contained in:
NaiJi ✨ 2020-03-03 01:22:37 +03:00
parent f24193b309
commit fbf18501d7
9 changed files with 49 additions and 26 deletions

Binary file not shown.

Binary file not shown.

View File

@ -10,6 +10,9 @@ Cell::Cell(coordinate cell_x, coordinate cell_y, const sf::Color &color) :
cell_color(color) cell_color(color)
{} {}
Cell::~Cell()
{}
sf::Color Cell::color() const noexcept sf::Color Cell::color() const noexcept
{ {
return cell_color; return cell_color;

View File

@ -24,9 +24,9 @@ public:
coordinate cell_y = 0, coordinate cell_y = 0,
const sf::Color &color = sf::Color::White); const sf::Color &color = sf::Color::White);
virtual ~Cell() = 0; virtual ~Cell() override;
inline sf::Color color() const noexcept; sf::Color color() const noexcept;
/// Determine if Hero can move onto this cell or not /// Determine if Hero can move onto this cell or not
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) = 0; virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) = 0;

31
src/entity.cpp Normal file
View File

@ -0,0 +1,31 @@
#include "entity.h"
Entity::Entity(coordinate _x, coordinate _y) :
pos_x(_x), pos_y(_y)
{}
Entity::~Entity()
{}
/// Get current Entity position
void Entity::position(coordinate &x, coordinate &y) const noexcept
{
x = pos_x;
y = pos_y;
}
void Entity::setPosition(coordinate x, coordinate y)
{
pos_x = x;
pos_y = y;
}
coordinate Entity::x() const noexcept
{
return pos_x;
}
coordinate Entity::y() const noexcept
{
return pos_y;
}

View File

@ -10,37 +10,21 @@ protected:
coordinate pos_x, pos_y; coordinate pos_x, pos_y;
public: public:
Entity(coordinate _x = 0, coordinate _y = 0) : Entity(coordinate _x = 0, coordinate _y = 0);
pos_x(_x), pos_y(_y)
{}
virtual ~Entity() = 0; virtual ~Entity() = 0;
/// Get current Entity position /// Get current Entity position
void position(coordinate &x, coordinate &y) const noexcept void position(coordinate &x, coordinate &y) const noexcept;
{
x = pos_x;
y = pos_y;
}
/// Set Entity position explicitly /// Set Entity position explicitly
void setPosition(coordinate x, coordinate y) void setPosition(coordinate x, coordinate y);
{
pos_x = x;
pos_y = y;
}
/// Get current x of the Entity position /// Get current x of the Entity position
coordinate x() const noexcept coordinate x() const noexcept;
{
return pos_x;
}
/// Get current y of the Entity position /// Get current y of the Entity position
coordinate y() const noexcept coordinate y() const noexcept;
{
return pos_y;
}
}; };
#endif // ENTITY_H #endif // ENTITY_H

View File

@ -113,7 +113,7 @@ void Game::renderMap()
{ {
const Map &map = level->mapArray(); const Map &map = level->mapArray();
coordinate painter_x = 0, painter_y = 0; float painter_x = 0, painter_y = 0;
// Brush for cell sprites // Brush for cell sprites
sf::RectangleShape rectangle_brush; sf::RectangleShape rectangle_brush;
@ -157,7 +157,7 @@ void Game::renderMap()
// Place the hero sprite // Place the hero sprite
rectangle_brush.setFillColor(sf::Color::White); rectangle_brush.setFillColor(sf::Color::White);
rectangle_brush.setPosition(hero_x * cell_length, hero_y * cell_length); rectangle_brush.setPosition(static_cast<float>(hero_x) * cell_length, static_cast<float>(hero_y) * cell_length);
main_window.draw(rectangle_brush); main_window.draw(rectangle_brush);
main_window.draw(text); main_window.draw(text);
} }
@ -177,6 +177,7 @@ void Game::loadLevel(int level_index)
// Hardcoding is temporary! // Hardcoding is temporary!
hero->setPosition(1, 1); hero->setPosition(1, 1);
hero->setCharges(2); hero->setCharges(2);
map[0][0] = std::make_unique<WallCell>(0, 0); map[0][0] = std::make_unique<WallCell>(0, 0);
map[0][1] = std::make_unique<WallCell>(0, 1); map[0][1] = std::make_unique<WallCell>(0, 1);
map[1][0] = std::make_unique<WallCell>(1, 0); map[1][0] = std::make_unique<WallCell>(1, 0);

View File

@ -2,7 +2,8 @@
Hero::Hero(coordinate position_x, coordinate position_y, int initial_charges) : Hero::Hero(coordinate position_x, coordinate position_y, int initial_charges) :
Entity(position_x, position_y), Entity(position_x, position_y),
hero_charges(initial_charges) hero_charges(initial_charges),
on_exit(false)
{} {}
void Hero::refillCharges(int append_charges) void Hero::refillCharges(int append_charges)

View File

@ -3,8 +3,11 @@ CONFIG += c++17
CONFIG -= console app_bundle CONFIG -= console app_bundle
CONFIG -= qt CONFIG -= qt
QMAKE_CXXFLAGS = -Wall -Werror -Wextra -Wpedantic -Wconversion -std=c++17 -O2 -g
SOURCES += \ SOURCES += \
cell.cpp \ cell.cpp \
entity.cpp \
game.cpp \ game.cpp \
hero.cpp \ hero.cpp \
level.cpp \ level.cpp \