created interface of second point functions

parent 446064f2
No related merge requests found
Showing with 89 additions and 5 deletions
+89 -5
......@@ -5,5 +5,5 @@ FetchContent_Declare(SFML GIT_REPOSITORY https://github.com/SFML/SFML.git GIT_TA
FetchContent_MakeAvailable(SFML)
project(pacman)
add_executable(proga application.cpp "main.cpp")
add_executable(proga application.cpp "main.cpp" "drawable.h" "drawable.cpp")
target_link_libraries(proga PUBLIC sfml-graphics sfml-window sfml-system)
......@@ -16,4 +16,9 @@ int Application::run() {
return 2;
}
return 0;
}
void Menu::draw_into(sf::RenderWindow& window) const {
for (const Button& ptr_button : m_buttons)
ptr_button.draw_into(window);
}
\ No newline at end of file
#include <iostream>
#include <memory>
#include <string>
#include <array>
#include <SFML/Graphics.hpp>
class IState;
......@@ -8,7 +9,7 @@ class IState;
class IStateManager {
public:
IStateManager() = default;
virtual ~IStateManager() {};
virtual ~IStateManager() {}
virtual void set_next_state(std::unique_ptr<IState> state) = 0;
};
......@@ -45,14 +46,77 @@ protected:
sf::RenderWindow m_window;
};
struct ISelectCommand {
virtual void execute() = 0;
};
class ChangeStateCommand : public ISelectCommand {
public:
ChangeStateCommand(IStateManager& state_manager): m_state_manager(state_manager) {}
protected:
IStateManager& m_state_manager;
};
struct IDrawable {
virtual void draw_into(sf::RenderWindow& window) const = 0;
virtual ~IDrawable() = default;
};
class ExitCommand : public ChangeStateCommand {
};
class GameBuilderDirector {
};
class GameCommand: public ChangeStateCommand {
public:
GameCommand(IStateManager& state_manager, std::unique_ptr< GameBuilderDirector> ptr_director):
ChangeStateCommand(state_manager) {}
};
class Button : public IDrawable {
public:
Button() {}
void set(sf::Vector2f pos, sf::Vector2f button_size, const std::string text, size_t font_size,
std::unique_ptr<ISelectCommand>&& ptr_command){}
void select() {}
void unselect() {}
bool is_selected() {}
bool is_position_in(sf::Vector2f pos){}
void push() {}
void draw_into(sf::RenderWindow& window) const override {}
private:
sf::Text m_text;
bool m_is_selected = false;
sf::RectangleShape m_rectangle;
std::unique_ptr<ISelectCommand> m_ptr_command;
};
class Menu : public IDrawable {
public:
Menu(IStateManager& state_manager) {}
void draw_into(sf::RenderWindow& window) const;
void process_mouse(sf::Vector2f pos, bool is_pressed) {}
private:
std::array<Button, 4> m_buttons;
};
class SelectState: public IState, public IWindowKeeper {
public:
using IState::IState;
using IWindowKeeper::IWindowKeeper;
SelectState(IStateManager& state_manager, sf::VideoMode videomode, const std::string window_title):
m_menu(state_manager), IState(state_manager), IWindowKeeper(videomode, window_title) {}
virtual bool do_step() const override {}
virtual void event_handling() override {}
virtual void update() override {}
virtual void render() override {}
private:
Menu m_menu;
};
class GameState: public IState, public IWindowKeeper {
......@@ -69,4 +133,19 @@ class ExitState: public IState {
public:
using IState::IState;
virtual bool do_step() const override { return false; }
};
\ No newline at end of file
};
class MyFont {
public: //singletone - we get the unique instance of the class
sf::Font& Instance() {
static sf::Font font;
return font;
}
MyFont(const MyFont& font) = delete;
MyFont& operator=(const MyFont&) = delete;
private:
MyFont() { m_font.loadFromFile("LibreBaskerville-Regular.ttf"); }
private:
sf::Font m_font;
};
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