the part with the rooms has been startes

parent 79128b9e
No related merge requests found
Showing with 134 additions and 3 deletions
+134 -3
......@@ -7,6 +7,6 @@ set(BUILD_SHARED_LIBS FALSE)
FetchContent_Declare(game_pacman GIT_REPOSITORY https://github.com/SFML/SFML.git GIT_TAG 2.6.1)
FetchContent_MakeAvailable(game_pacman)
add_executable(game_pacman main.cpp "Sources/Application/App_n_IState.cpp" "Sources/States/States.cpp" "Sources/Window/Window.cpp" "Sources/Button/Button.cpp" "Sources/SelectCommand/SelectCommand.cpp" "Sources/Font/MyFont.cpp" "Sources/Menu/Menu.cpp")
add_executable(game_pacman main.cpp "Sources/Application/App_n_IState.cpp" "Sources/States/States.cpp" "Sources/Window/Window.cpp" "Sources/Button/Button.cpp" "Sources/SelectCommand/SelectCommand.cpp" "Sources/Font/MyFont.cpp" "Sources/Menu/Menu.cpp" "Sources/Room/Room.cpp")
target_link_libraries(game_pacman PUBLIC sfml-window sfml-graphics sfml-system)
\ No newline at end of file
......@@ -3,7 +3,7 @@
#include <memory>
#include "../SelectCommand/SelectCommand.h"
#include "../IDrawable/IDrawable.h"
#include "../IDraw_n_IPrep/IDraw_n_IPrep.h"
class Button: public IDrawable {
......
......@@ -5,4 +5,11 @@ class IDrawable {
public:
virtual void draw_into(sf::RenderWindow& window) const = 0;
virtual ~IDrawable() = default;
};
class IPreparable: public IDrawable {
public:
virtual void prepare_for_drawing() = 0;
virtual ~IPreparable() = default; //здесь тоже, потому что он чисто virtual класс
};
\ No newline at end of file
......@@ -2,7 +2,7 @@
#include <array>
#include "../IDrawable/IDrawable.h"
#include "../IDraw_n_IPrep/IDraw_n_IPrep.h"
#include "../Application/App_n_IState.h"
#include "../Button/Button.h"
......
#include "Room.h"
//MAZE
Maze::Maze(std::vector<std::unique_ptr<Room>>& rooms): m_rooms(std::move(rooms)) {} //move потому что вектор с unique
void Maze::draw_into(sf::RenderWindow& window) const {
for (const std::unique_ptr<Room>& ptr_room : m_rooms)
ptr_room->draw_into(window); //-> потому что в ptr_room указатель, который надо разыменовать
}
//IENTITY
void IEntity::set_location(Room* ptr_room) {
m_ptr_room = ptr_room;
this->prepare_for_drawing(); //отрисовываем себя
}
Room* IEntity::get_location() {
return m_ptr_room;
}
//PASS
Pass::Pass(Room& room1, Room& room2): m_room1(room1), m_room2(room2) {}
void Pass::draw_into(sf::RenderWindow& window) const {};
void Pass::prepare_for_drawing() {};
//WALL
Wall::Wall(Room& room): m_room(room) {}
\ No newline at end of file
#pragma once
#include <array>
#include <vector>
#include "../IDraw_n_IPrep/IDraw_n_IPrep.h"
class Room;
class Maze: public IDrawable {
public:
Maze(std::vector<std::unique_ptr<Room>>& rooms);
void draw_into(sf::RenderWindow& window) const override;
private:
std::vector<std::unique_ptr<Room>> m_rooms;
};
class IEntity: public IPreparable { //мб entity отсюда надо убрать
public:
void set_location(Room* ptr_room);
Room* get_location();
protected:
Room* m_ptr_room; //не unique тк room без него живет
};
class IRoomSide: public IPreparable {
public:
virtual ~IRoomSide() = default;
virtual void enter(IEntity* entity) = 0;
};
class Pass: public IRoomSide {
public:
Pass(Room& room1, Room& room2);
void draw_into(sf::RenderWindow& window) const override;
void prepare_for_drawing() override;
void enter(IEntity* entity) override; //РЕАЛИЗОВАТЬ
private:
Room& m_room1;
Room& m_room2;
};
class Wall : public IRoomSide {
public:
Wall(Room& room);
void draw_into(sf::RenderWindow& window) const override; //РЕАЛИЗОВАТЬ
void prepare_for_drawing() override; //РЕАЛИЗОВАТЬ
void enter(IEntity* entity) override; //РЕАЛИЗОВАТЬ
private:
Room& m_room;
sf::Vertex m_line[2];
};
class Room: public IDrawable {
public:
enum Direction { INVALID = -1, LEFT, RIGHT, UP, DOWN };
Room(float size); //РЕАЛИЗОВАТЬ
float get_size(); //РЕАЛИЗОВАТЬ
void set_position(sf::Vector2f pos); //РЕАЛИЗОВАТЬ
sf::Vector2f get_position(); //РЕАЛИЗОВАТЬ
void set_side(Direction side, std::shared_ptr<IRoomSide> ptr_side); //РЕАЛИЗОВАТЬ // shared_ptr, потому что одна IRoomSide будет у нескольких комнат
IRoomSide* get_side(Direction side); //РЕАЛИЗОВАТЬ
Direction get_direction(IRoomSide* ptr_side); //РЕАЛИЗОВАТЬ
void draw_into(sf::RenderWindow& window) const override; //РЕАЛИЗОВАТЬ
public:
std::array<std::shared_ptr<IRoomSide>,4> m_sides;
private:
sf::RectangleShape m_rectangle;
};
\ 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