Commit 20cdb15c authored by Малева Мария Владимировна's avatar Малева Мария Владимировна
Browse files

declared select state

parents
No related merge requests found
Showing with 222 additions and 0 deletions
+222 -0
cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 17)
project(Pacman)
add_executable(Exec source/main.cpp "source/App.h" "source/App.cpp" )
set(SFML_DIR "C:/Users/Maria/Documents/libs/SFML-2.6.2/lib/cmake/SFML")
find_package(SFML 2.6 COMPONENTS graphics window system REQUIRED)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(Exec PUBLIC sfml-graphics sfml-window sfml-system sfml-audio)
{
"version": 3,
"configurePresets": [
{
"name": "windows-base",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_C_COMPILER": "cl.exe",
"CMAKE_CXX_COMPILER": "cl.exe"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "x64-debug",
"displayName": "x64 Debug",
"inherits": "windows-base",
"architecture": {
"value": "x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "x64-release",
"displayName": "x64 Release",
"inherits": "x64-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "x86-debug",
"displayName": "x86 Debug",
"inherits": "windows-base",
"architecture": {
"value": "x86",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "x86-release",
"displayName": "x86 Release",
"inherits": "x86-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
}
]
}
#include "App.h"
#include <iostream>
void Application::set_next_state(IState* state)
{
m_ptr_state_next = state;
}
void Application::apply_deffer_state_change()
{
m_ptr_state_current = m_ptr_state_next;
}
int Application::run() {
try {
while (m_ptr_state_current->do_step())
apply_deffer_state_change();
}
catch (std::exception& ex) {
std::cout << ex.what() << '\n';
return 1;
}
catch (...) {
std::cout << "Unknown exception\n";
return 2;
}
return 0;
}
bool IState::do_step()
{
return true;
}
source/App.h 0 → 100644
#pragma once
#include <SFML/Graphics.hpp>
class IState;
class IStateManager {
public:
void set_next_state(IState state);
};
class IState {
public:
IState(IStateManager& state_manager);
bool do_step();
protected:
IStateManager m_state_manager;
};
class Application: IStateManager {
public:
int run();
private:
void set_next_state(IState* ptr_state);
void apply_deffer_state_change();
IState* m_ptr_state_next;
IState* m_ptr_state_current;
};
class IWindowKeeper {
protected:
sf::RenderWindow m_window;
void event_handling();
void update();
void render();
public:
IWindowKeeper(sf::VideoMode video_mode, std::string window_title);
};
class ISelectCommand {
public:
void execute();
};
class IDrawable {
public:
void draw_into(sf::RenderWindow& window);
};
class MyFont {
private:
sf::Font m_font;
MyFont();
public:
sf::Font& instance();
};
class Button : IDrawable {
private:
sf::Text m_text;
sf::RectangleShape m_shape;
ISelectCommand* m_ptr_command;
public:
Button();
void set(sf::Vector2f pos, std::string text, size_t font_size, ISelectCommand ptr_command);
void select();
void unselect();
void is_position_in(sf::Vector2f pos);
void push();
};
class Menu {
private:
Button m_buttons[4];
public:
Menu(IStateManager& state_manager);
void process_mouse(sf::Vector2f pos, bool is_pressed);
};
class SelectState : IState, IWindowKeeper {
public:
SelectState(IStateManager& state_manager, sf::VideoMode video_mode, std::string window_title);
private:
Menu m_menu;
};
class GameState : IState, IWindowKeeper {
public:
GameState(IStateManager& state_manager, sf::VideoMode video_mode, std::string window_title);
};
class ExitState : IState {
public:
ExitState(IStateManager& state_manager);
};
#include "App.h"
#include "iostream"
using namespace std;
int main()
{
std::cout << "meow" << endl;
//Application app;
//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