Commit 162943df authored by Печенин Данила Михайлович's avatar Печенин Данила Михайлович
Browse files

Initial commit

parents
No related merge requests found
Showing with 104 additions and 0 deletions
+104 -0
.gitignore 0 → 100644
.vs/
out/
.idea/
cmake-build-debug/
cmake-build-release/
.DS_Store
build/
.vscode/
\ No newline at end of file
cmake_minimum_required(VERSION 3.12)
project(Pacman)
set(CMAKE_CXX_STANDARD 17)
file(GLOB_RECURSE HEADERS include/*h)
file(GLOB_RECURSE SOURCES src/*cpp)
#set(SFML_STATIC_LIBRARIES TRUE)
set(BUILD_SHARED_LIBS FALSE)
#FetchContent_Declare(SFML GIT_REPOSITORY https://github.com/SFML/SFML.git GIT_TAG 2.6.1)
#FetchContent_MakeAvailable(SFML)
add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES})
#target_link_libraries(${PROJECT_NAME} PRIVATE sfml-system sfml-window sfml-graphics)
\ No newline at end of file
#pragma once
#include "States/States.h"
class Application : public IStateManager {
public:
static Application& Instance() {
static Application instance;
return instance;
}
Application(const IStateManager&) = delete;
Application& operator=(const Application&) = delete;
int run();
private:
Application() = default;
~Application() override = default;
void set_next_state(std::unique_ptr<IState> state) override { m_ptr_state_next = std::move(state); };
void apply_deffer_state_change();
std::unique_ptr<IState> m_ptr_state_current = std::make_unique<ExitState>(*this);
std::unique_ptr<IState> m_ptr_state_next;
};
\ No newline at end of file
#pragma once
#include "IStateManager.h"
class IState {
public:
explicit IState(IStateManager& state_manager) : m_state_manager(state_manager) {}
virtual bool do_step() = 0;
virtual ~IState() = default;
protected:
IStateManager& m_state_manager;
};
#pragma once
#include <memory>
class IState;
struct IStateManager {
virtual void set_next_state(std::unique_ptr<IState> state) = 0;
virtual ~IStateManager() = default;
};
\ No newline at end of file
#pragma once
#include "IState.h"
struct ExitState : IState {
explicit ExitState(IStateManager& state_manager) : IState(state_manager) {}
bool do_step() override { return false; }
};
\ No newline at end of file
#include "../include/Application.h"
#include <iostream>
void Application::apply_deffer_state_change() {
if (m_ptr_state_next)
m_ptr_state_current = std::move(m_ptr_state_next);
}
int Application::run() {
try {
while (m_ptr_state_current->do_step())
apply_deffer_state_change();
}
catch (const std::exception& ex) {
std::cout << ex.what() << '\n';
return 1;
}
catch (...) {
std::cout << "Unknown exception\n";
return 2;
}
return 0;
}
\ No newline at end of file
#include "../include/Application.h"
int main() {
Application& app = Application::Instance();
return app.run();
}
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