Commit aa6c9756 authored by Авдеев Евгений Владимирович's avatar Авдеев Евгений Владимирович
Browse files

changed CMakeLists; Created drawable menu with buttons

parent 687c0a00
No related merge requests found
Showing with 93 additions and 37 deletions
+93 -37
......@@ -8,12 +8,7 @@ FetchContent_Declare(SFML GIT_REPOSITORY https://github.com/SFML/SFML.git GIT_TA
FetchContent_MakeAvailable(SFML)
add_executable(pacman source/main.cpp
source/${SOURCE_CPP}
source/State/${SOURCE_CPP}
source/Menu/${SOURCE_CPP}
source/Draw/${SOURCE_CPP}
source/Command/${SOURCE_CPP})
add_executable(pacman source/main.cpp source/Application.cpp source/State/SelectState.cpp source/State/IWindowKeeper.cpp source/State/IState.cpp source/Menu/Menu.cpp source/Menu/Button.cpp "source/Draw/MyFont.cpp")
target_link_libraries(pacman PRIVATE sfml-window sfml-graphics sfml-system)
target_compile_definitions(pacman PRIVATE FONT_PATH="${CMAKE_CURRENT_SOURCE_DIR}/source/Assets/Fonts/Adbxtra.ttf")
#include "Application.h"
#include "State/SelectState.h"
#include "Config/Config.h"
#include <iostream>
Application::Application():m_ptr_state_current(std::make_unique<SelectState>(*this, "Menu")) {}
Application::Application() : m_ptr_state_current(std::make_unique<SelectState>(*this, config::SELECT_LEVEL_VIDEO_MODE, config::SELECT_LEVEL_TITLE)) {}
int Application::run() {
try {
while (m_ptr_state_current->do_step())
apply_deffer_state_change();
apply_deferred_state_change();
}
catch (std::exception& ex) {
std::cout << ex.what() << '\n';
......@@ -22,10 +22,10 @@ int Application::run() {
}
void Application::set_next_state(std::unique_ptr<IState> state) {
m_ptr_state_next = std::move(state)
m_ptr_state_next = std::move(state);
}
void Application::apply_deffer_state_change() {
void Application::apply_deferred_state_change() {
if (m_ptr_state_next)
std::swap(m_ptr_state_current, m_ptr_state_next);
m_ptr_state_next.reset();
......
#pragma once
#include "State/IState.h"
#include <iostream>
class IStateManager {
public:
virtual void set_next_state(std::unique_ptr<IState> state);
virtual ~IStateManager();
};
#include "./State/IState.h"
#include <memory>
class Application : public IStateManager {
private:
......
File added
File added
......@@ -10,6 +10,7 @@ private:
GameContext m_context;
std::unique_ptr<GameState> m_game_state;
public:
CommonBuilder(float width, float height, float room_size) : m_height(height), m_width(width), m_room_size(room_size) {}
void create_context(float dynamic_obj_ratio);
void create_state(IStateManager& state_manager, sf::VideoMode mode, std::string window_title);
void set_all_to_state();
......
#pragma once
#include <SFML/Graphics.hpp>
#include "IGameBuilder.h"
class GameBuilderDirector {
private:
std::string m_window_title;
sf::VideoMode m_mode;
float m_dynamic_obj_ratio;
std::unique_ptr<IGameBuilder> m_ptr_builder;
public:
GameBuilderDirector(std::unique_ptr<IGameBuilder>&& ptr_builder, const std::string& window_title, float dynamic_objects_ratio);
std::unique_ptr<IGameBuilder> build(IStateManager& state_manager);
};
\ No newline at end of file
......@@ -3,6 +3,7 @@
class SimpleBuilder:public CommonBuilder {
public:
using CommonBuilder::CommonBuilder;
void create_rooms();
void set_rooms_sides();
};
\ No newline at end of file
#include "ChangeStateCommand.h"
void ExitCommand::execute() {
m_state_manager.set_next_state(std::make_unique<ExitState>(m_state_manager));
}
void GameCommand::execute() {
auto state = m_ptr_director->build(m_state_manager);
m_state_manager.set_next_state(std::move(state));
}
\ No newline at end of file
#pragma once
#include "ISelectCommand.h"
#include "./../State/IState.h"
#include "./../Builder/GameBuilderDirector.h"
class ChangeStateCommand : public ISelectCommand {
public:
ChangeStateCommand(IStateManager& state_manager);
ChangeStateCommand(IStateManager& state_manager) : m_state_manager(state_manager) {};
protected:
IStateManager& m_state_manager;
};
class ExitCommand : public ChangeStateCommand {
using ChangeStateCommand::ChangeStateCommand;
void execute() override;
};
class GameCommand : public ChangeStateCommand {
public:
GameCommand(IStateManager& state_manager, std::unique_ptr<GameBuilderDirector> ptr_director)
GameCommand(IStateManager& state_manager, std::unique_ptr<GameBuilderDirector>&& ptr_director): ChangeStateCommand(state_manager), m_ptr_director(std::move(ptr_director)) {};
void execute() override;
private:
std::unique_ptr<GameBuilderDirector> m_ptr_director;
};
\ No newline at end of file
......@@ -9,7 +9,6 @@ namespace config {
const sf::Vector2f BUTTON_SIZE = { 250, 100 };
const size_t BUTTON_FONT_SIZE = static_cast<size_t>(BUTTON_SIZE.y / 1.5f);
const float BUTTON_FRAME_THICKNESS = 2.0f;
const char FONT_FILE[] = "Calibri-Light.ttf";
const char SELECT_LEVEL_TITLE[] = "Select Level";
const sf::VideoMode SELECT_LEVEL_VIDEO_MODE{ 400, 600 };
const char BUTTON_TEXT_EASY[] = "Easy";
......
#pragma once
#include "./../Draw/IDrawable.h"
#include <SFML/Graphics.hpp>
#include "./../Command/ISelectCommand.h"
class IPreparable :public IDrawable {
virtual void prepare_for_drawing() = 0;
virtual ~IPreparable() = default;
};
\ No newline at end of file
#include "MyFont.h"
#include "./../Config/Config.h"
MyFont::MyFont() {
if (!m_font.loadFromFile(std::string(FONT_PATH))) {
throw std::runtime_error("Cannot load file");
}
}
MyFont& MyFont::Instance() {
static MyFont instance;
return instance;
}
MyFont::operator const sf::Font& () const {
return m_font;
}
#pragma once
#include <SFML/Graphics.hpp>
#include "./../Config/Config.h"
class MyFont {
public:
MyFont(const MyFont&) = delete;
MyFont& operator = (const MyFont&) = delete;
static MyFont& Instance();
operator const sf::Font& () const;
private:
sf::Font m_font;
MyFont();
public:
Font& Instance();
};
\ No newline at end of file
private:
sf::Font m_font;
};
#pragma once
#include "./../State/GameState.h"
#include "./../Context/Context.h"
class IGameEvent {
public:
......@@ -7,7 +9,7 @@ public:
virtual ~IGameEvent() = default;
};
class DeleteStaticEntity {
class DeleteStaticEntity: public IGameEvent {
private:
IStaticEntity* m_ptr_entity;
public:
......@@ -16,6 +18,11 @@ public:
};
class LostGame : public IGameEvent {
public:
void handle(GameContext* context) override;
};
class WinGame : public IGameEvent {
public:
void handle(GameContext* context) override;
};
\ No newline at end of file
......@@ -3,6 +3,8 @@
#include "./../Maze/Room.h"
#include "IVisitor.h"
class Pacman :public IEntity, public IVisitor {
public:
void move(Room::Direction direction);
......
#include "Maze.h"
void Maze::draw_into(sf::RenderWindow& window) {
for (auto& room : m_rooms)
room->draw_into(window);
}
\ No newline at end of file
......@@ -6,7 +6,9 @@
class Maze : public IDrawable {
public:
Maze(std::vector<std::unique_ptr<Room>>& rooms);
Maze() = default;
Maze(std::vector<std::unique_ptr<Room>>& rooms) : m_rooms(std::move(rooms)) {};
void draw_into(sf::RenderWindow& window) override;
private:
std::vector<std::unique_ptr<Room>> m_rooms;
};
\ No newline at end of file
#include "Room.h"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment