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

Partially completed the fith item of lab work

parent 340c5a84
No related merge requests found
Showing with 92 additions and 14 deletions
+92 -14
......@@ -12,7 +12,8 @@ FetchContent_MakeAvailable(sfml)
add_executable(pac-man
"source/main.cpp"
"source/Application.cpp"
"source/State/SelectState.cpp"
"source/States/SelectState.cpp"
"source/States/GameState.cpp"
"source/Draw/Menu.cpp"
"source/Draw/Button.cpp"
"source/Draw/MyFont.cpp"
......@@ -21,6 +22,7 @@ add_executable(pac-man
"source/Maze_Content/Buildings/Room.cpp"
"source/Maze_Content/Entities/Pacman.cpp"
"source/Maze_Content/Entities/DynamicEntities/Enemy.cpp"
"source/Context/GameContext.cpp"
)
target_compile_definitions(pac-man PRIVATE
......
#pragma once
#include "GameContext.h"
#include "stack"
class ContextManager {
public:
void reset(GameContext&& context);
GameContext& get_current_context();
void save_current_context(); ///@todo
void restore_previous_context();
private:
GameContext m_initial_context;
std::stack<GameContext> m_contexts;
};
\ No newline at end of file
#pragma once
#include "MazeContent/Entities/Pacman.h"
#include "MazeContent/Entities/DynamicEntities/IDynamicEntity.h"
#include "MazeContent/Entities/StaticEntities//IStaticEntity.h"
class GameContext {
public:
GameContext clone() const; ///@todo
public:
enum State{ INGAME, WIN, LOST } state = INGAME;
Pacman pacman;
std::vector<std::unique_ptr<IStaticEntity>> static_objects;
std::vector<std::unique_ptr<IDynamicEntity>> dynamic_objects;
};
\ No newline at end of file
#pragma once
class GameContext {
public:
public:
};
\ No newline at end of file
......@@ -6,7 +6,8 @@ class Maze: public IDrawable {
public:
void draw_into(sf::RenderWindow& window) const override;
public:
Maze() = default;
Maze(std::vector<std::unique_ptr<Room>>&& rooms): m_rooms(std::move(rooms)) {}
private:
std::vector<std::unique_ptr<Room>>&& m_rooms;
std::vector<std::unique_ptr<Room>> m_rooms;
};
\ No newline at end of file
......@@ -4,5 +4,11 @@
class Pacman: public IEntity {
public:
void move(Room::Direction direction); ///@todo
void prepare_for_drawing() override; ///@todo
void draw_into(sf::RenderWindow& window) const override; ///@todo
void move(Room::Direction direction);
public:
Pacman(); ///@todo
private:
sf::CircleShape m_circle;
};
\ No newline at end of file
......@@ -2,8 +2,17 @@
#include "States/IState.h"
#include "IWindowKeeper.h"
#include "MazeContent/Buildings/Maze.h"
#include "Context/ContextManager.h"
class SelectState: public IState, public IWindowKeeper {
class GameState: public IState, public IWindowKeeper {
public:
SelectState(IStateManager& state_manager, const sf::VideoMode& video_mode, const std::string& window_title);
void set_maze(Maze&& maze);
void set_context(GameContext&& context);
public:
GameState(IStateManager& state_manager,
const sf::VideoMode& video_mode, const std::string& window_title);
private:
Maze m_maze;
ContextManager m_context_manager;
};
\ No newline at end of file
#include "Context/ContextManager.h"
void ContextManager::reset(GameContext&& context) {
while (!m_contexts.empty()) {
m_contexts.pop();
}
m_initial_context = context.clone();
m_contexts.emplace(m_initial_context.clone());
}
GameContext& ContextManager::get_current_context() {
return m_contexts.top();
}
void ContextManager::save_current_context() {
}
void ContextManager::restore_previous_context() {
if (m_contexts.size() > 1)
m_contexts.pop();
else
m_contexts.top() = m_initial_context.clone();
}
\ No newline at end of file
#include "Context/GameContext.h"
//
// Created by Игорь on 22.03.2025.
//
#include "States/GameState.h"
GameState::GameState(IStateManager& state_manager, const sf::VideoMode& video_mode, const std::string& window_title):
IWindowKeeper(video_mode, window_title), IState(state_manager) {}
void GameState::set_maze(Maze&& maze) {
m_maze = std::move(maze);
}
void GameState::set_context(GameContext&& context) {
m_context_manager.reset(std::move(context));
}
\ No newline at end of file
File moved
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