Commit 9308d0b2 authored by Сулимов Игорь Андреевич's avatar Сулимов Игорь Андреевич
Browse files

Partially completed the second item of lab work

parent 6a02e5a6
No related merge requests found
Showing with 189 additions and 13 deletions
+189 -13
...@@ -13,10 +13,19 @@ add_executable(pac-man ...@@ -13,10 +13,19 @@ add_executable(pac-man
"source/main.cpp" "source/main.cpp"
"source/Application.cpp" "source/Application.cpp"
"source/State/SelectState.cpp" "source/State/SelectState.cpp"
"source/Drawable/Menu.cpp" "source/Draw/Menu.cpp"
"source/Drawable/Button.cpp" "source/Draw/Button.cpp"
"source/Draw/MyFont.cpp"
"source/Commands/ExitCommand.cpp"
) )
target_compile_definitions(pac-man PRIVATE
FONT_PATH="${CMAKE_CURRENT_SOURCE_DIR}/аssets/Fonts/"
# TEXTURE_PATH="${CMAKE_CURRENT_SOURCE_DIR}/source/Assets/Textures/"
# VIDEO_PATH="${CMAKE_CURRENT_SOURCE_DIR}/source/Assets/Video/"
# SOUND_PATH="${CMAKE_CURRENT_SOURCE_DIR}/source/Assets/Sound/"
)
target_include_directories(pac-man PUBLIC include/) target_include_directories(pac-man PUBLIC include/)
target_link_libraries(pac-man PUBLIC sfml-window sfml-graphics sfml-system) target_link_libraries(pac-man PUBLIC sfml-window sfml-graphics sfml-system)
\ No newline at end of file
File added
#pragma once
class GameBuilderDirector {
};
\ No newline at end of file
//
// Created by Игорь on 23.03.2025.
//
#ifndef PAC_MAN_IROOMSIDE_H
#define PAC_MAN_IROOMSIDE_H
#endif //PAC_MAN_IROOMSIDE_H
//
// Created by Игорь on 23.03.2025.
//
#ifndef PAC_MAN_ROOM_H
#define PAC_MAN_ROOM_H
#endif //PAC_MAN_ROOM_H
#pragma once
#include "ISelectCommand.h"
class ChangeStateCommand: public ISelectCommand {
public:
void execute() override;
public:
ChangeStateCommand(IStateManager& state_manager) : m_ptr_state_manager(state_manager) {}
virtual ~ChangeStateCommand() = default;
protected:
IStateManager& m_ptr_state_manager;
};
\ No newline at end of file
#pragma once
#include "ChangeStateCommand.h"
class ExitCommand: public ChangeStateCommand {
public:
void execute() override; ///@todo
public:
ExitCommand(IStateManager& state_manager);
};
\ No newline at end of file
#pragma once
#include "ChangeStateCommand.h"
#include "Builders/GameBuilderDirector.h"
class GameCommand: public ChangeStateCommand {
public:
void execute() override;
public:
GameCommand(IStateManager& state_manager, std::unique_ptr<GameBuilderDirector>&& ptr_director);
private:
std::unique_ptr<GameBuilderDirector> m_ptr_director;
};
\ No newline at end of file
#pragma once #pragma once
#include "States/IState.h"
class ISelectCommand { class ISelectCommand {
public: public:
virtual void execute() = 0; virtual void execute() = 0;
......
#pragma once #pragma once
#include "config.h"
#include "IDrawable.h" #include "IDrawable.h"
#include "ISelectCommand.h" #include "Commands/ISelectCommand.h"
class Button: public IDrawable { class Button: public IDrawable {
public: public:
void set(); ///@todo void set(); ///@todo
void select(); ///@todo void select() noexcept;
void unselect(); ///@todo void unselect() noexcept;
bool is_selected(); ///@todo bool is_selected() noexcept;
void is_position_in(sf::Vector2f pos); ///@todo bool is_position_in(sf::Vector2f pos) const noexcept;
void push() const; void push() const;
void draw_into(sf::RenderWindow& window) const override {}; ///@todo void draw_into(sf::RenderWindow& window) const override {}; ///@todo
public:
Button(); ///@todo
private: private:
sf::Text m_text; sf::Text m_text;
bool m_is_selected = false; bool m_is_selected = false;
......
#pragma once #pragma once
#include <SFML/Graphics.hpp> #include "SFML/Graphics.hpp"
struct IDrawable { struct IDrawable {
virtual void draw_into(sf::RenderWindow& window) const = 0; virtual void draw_into(sf::RenderWindow& window) const = 0;
......
#pragma once #pragma once
#include "Button.h" #include "Draw/Button.h"
#include "States/IState.h" #include "States/IState.h"
class Menu: public IDrawable { class Menu: public IDrawable {
public: public:
void draw_into(sf::RenderWindow& window) const override; void draw_into(sf::RenderWindow& window) const override;
void process_mouse(sf::Vector2f pos, bool is_pressed); ///@todo void process_mouse(sf::Vector2f pos, bool is_pressed);
public: public:
Menu(IStateManager& state_manager) {} ///@todo Menu(IStateManager& state_manager) {} ///@todo
private: private:
......
#pragma once
#include "SFML/Graphics/Font.hpp"
class MyFont {
public:
MyFont(const MyFont&) = delete;
MyFont& operator = (const MyFont&) = delete;
static MyFont& Instance();
private:
MyFont();
private:
sf::Font m_font;
};
\ No newline at end of file
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
class ExitState: public IState { class ExitState: public IState {
public: public:
ExitState(IStateManager& state_manager);
bool do_step() override { return false; } bool do_step() override { return false; }
public:
ExitState(IStateManager& state_manager);
}; };
\ No newline at end of file
...@@ -6,9 +6,10 @@ struct IStateManager; ...@@ -6,9 +6,10 @@ struct IStateManager;
class IState { class IState {
public: public:
IState(IStateManager& state_manager): m_state_manager(state_manager) {}
virtual bool do_step() = 0; virtual bool do_step() = 0;
virtual ~IState() = default; virtual ~IState() = default;
public:
IState(IStateManager& state_manager): m_state_manager(state_manager) {}
protected: protected:
IStateManager& m_state_manager; IStateManager& m_state_manager;
}; };
......
#pragma once #pragma once
#include "IWindowKeeper.h" #include "IWindowKeeper.h"
#include "Drawable/Menu.h" #include "Draw/Menu.h"
class SelectState: public IState, public IWindowKeeper { class SelectState: public IState, public IWindowKeeper {
public: public:
......
#pragma once
#include <SFML/Graphics.hpp>
namespace config {
// Общее:
// const unsigned int FRAME_RATE_LIMIT = 60;
// Меню:
// 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";
// const char BUTTON_TEXT_MEDIUM[] = "Medium";
// const char BUTTON_TEXT_HARD[] = "Hard";
// const char BUTTON_TEXT_EXIT[] = "Exit";
// Игра:
// const sf::VideoMode GAME_VIDEO_MODE{ 1080, 720 };
// const char EASY_GAME_TITLE[] = "Level: Easy";
// const char MEDIUM_GAME_TITLE[] = "Level: Medium";
// const char HARD_GAME_TITLE[] = "Level: Hard";
// const float EASY_GAME_ENEMY_RATIO = 0.0f;
// const float MEDIUM_GAME_ENEMY_RATIO = 0.03f;
// const float HARD_GAME_ENEMY_RATIO = 0.07f;
// const float ROOM_SIZE = 50;
// const float GAME_ENEMY_SIZE = ROOM_SIZE * 0.7;
// const float GAME_FOOD_SIZE = ROOM_SIZE * 0.2;
// Пакмэн:
// const float GAME_PACMAN_SIZE = ROOM_SIZE * 0.8;
// const sf::Keyboard::Key KEY_LEFT = sf::Keyboard::A;
// const sf::Keyboard::Key KEY_RIGHT = sf::Keyboard::D;
// const sf::Keyboard::Key KEY_UP = sf::Keyboard::W;
// const sf::Keyboard::Key KEY_DOWN = sf::Keyboard::S;
// Цвета:
// const sf::Color BUTTON_COLOR_TEXT{ 0, 0, 0 };
const sf::Color BUTTON_COLOR_FILL{ 180, 180, 180 };
const sf::Color BUTTON_COLOR_SELECTION{ 255, 180, 180 };
// const sf::Color BUTTON_COLOR_FRAME{ 0, 0, 0 };
// const sf::Color SELECT_LEVEL_BACKGROUND_COLOR{ 230,230,230 };
// const sf::Color GAME_COLOR_BACKGROUND_INGAME{ 230,230,230 };
// const sf::Color GAME_COLOR_BACKGROUND_WIN{ 0, 255, 0 };
// const sf::Color GAME_COLOR_BACKGROUND_LOST{ 255, 0, 0 };
// const sf::Color GAME_COLOR_PACMAN{ 250, 150, 0 };
// const sf::Color GAME_COLOR_ROOM{ 255, 255, 255 };
// const sf::Color GAME_COLOR_WALL{ 0, 0, 0 };
// const sf::Color GAME_FOOD_COLOR{ 0, 200, 100 };
// const sf::Color GAME_ENEMY_COLOR{ 255, 50, 0 };
}
\ No newline at end of file
#include "Commands/ExitCommand.h"
#include "States/ExitState.h"
ExitCommand::ExitCommand(IStateManager& state_manager) : ChangeStateCommand(state_manager) {}
void ExitCommand::execute() {
m_ptr_state_manager.set_next_state(std::make_unique<ExitState>(m_ptr_state_manager));
}
\ No newline at end of file
#include "Commands/GameCommand.h"
#include "States/GameState.h"
GameCommand::GameCommand(IStateManager& state_manager, std::unique_ptr<GameBuilderDirector>&& ptr_director) :
ChangeStateCommand(state_manager), m_ptr_director(std::move(ptr_director)) {}
void GameCommand::execute() {
m_ptr_state_manager.set_next_state(m_ptr_director->build(m_ptr_state_manager));
}
\ No newline at end of file
#include "Draw/Button.h"
void Button::push() const {
m_ptr_command->execute();
}
void Button::select() noexcept {
m_rectangle.setFillColor(config::BUTTON_COLOR_SELECTION);
m_is_selected = true;
}
void Button::unselect() noexcept {
m_rectangle.setFillColor(config::BUTTON_COLOR_FILL);
m_is_selected = false;
}
bool Button::is_selected() noexcept{
return m_is_selected;
}
bool Button::is_position_in(sf::Vector2f pos) const noexcept {
return m_rectangle.getGlobalBounds().contains(pos);
}
\ No newline at end of file
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