Commit 350c53bb authored by Авдеев Евгений Владимирович's avatar Авдеев Евгений Владимирович
Browse files

created structure of project; completed 1 point of lab

parents
No related merge requests found
Showing with 124 additions and 0 deletions
+124 -0
.gitignore 0 → 100644
.vs/
out/
\ No newline at end of file
cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 17)
project(lab_3)
include(FetchContent)
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(pacman source/main.cpp)
target_link_libraries(pacman PRIVATE sfml-window sfml-graphics sfml-system)
#include "Application.h"
Application::Application():m_ptr_state_current(std::make_unique<SelectState>(*this, "Menu")) {}
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;
}
void Application::set_next_state(std::unique_ptr<IState> state) {
m_ptr_state_next = std::move(state)
}
void Application::apply_deffer_state_change() {
if (m_ptr_state_next)
std::swap(m_ptr_state_current, m_ptr_state_next);
m_ptr_state_next.reset();
}
\ No newline at end of file
#pragma once
#include "State/IState.h"
#include <iostream>
class IStateManager {
public:
virtual void set_next_state(std::unique_ptr<IState> state);
virtual ~IStateManager();
};
class Application : public IStateManager {
private:
std::unique_ptr<IState> m_ptr_state_current;
std::unique_ptr<IState> m_ptr_state_next;
private:
void apply_deferred_state_change();
void set_next_state(std::unique_ptr<IState> state) override;
public:
Application();
int run();
};
\ No newline at end of file
namespace config {
// :
const unsigned int FRAME_RATE_LIMIT = 60;
// :
const sf::Vector2f BUTTON_SIZE = { 250, 100 };
const size_t BUTTON_FONT_SIZE = static_cast<size_t>(BUTTON_SIZE.y / 1.5f);
const float BUTTON_FRAME_THICKNESS = 2.0f;
const char FONT_FILE[] = "Calibri-Light.ttf";
const char SELECT_LEVEL_TITLE[] = "Select Level";
const sf::VideoMode SELECT_LEVEL_VIDEO_MODE{ 400, 600 };
const char BUTTON_TEXT_EASY[] = "Easy";
const char BUTTON_TEXT_MEDIUM[] = "Medium";
const char BUTTON_TEXT_HARD[] = "Hard";
const char BUTTON_TEXT_EXIT[] = "Exit";
// :
const sf::VideoMode GAME_VIDEO_MODE{ 1080, 720 };
const char EASY_GAME_TITLE[] = "Level: Easy";
const char MEDIUM_GAME_TITLE[] = "Level: Medium";
const char HARD_GAME_TITLE[] = "Level: Hard";
const float EASY_GAME_ENEMY_RATIO = 0.0f;
const float MEDIUM_GAME_ENEMY_RATIO = 0.03f;
const float HARD_GAME_ENEMY_RATIO = 0.07f;
const float ROOM_SIZE = 50;
const float GAME_ENEMY_SIZE = ROOM_SIZE * 0.7;
const float GAME_FOOD_SIZE = ROOM_SIZE * 0.2;
// :
const float GAME_PACMAN_SIZE = ROOM_SIZE * 0.8;
const sf::Keyboard::Key KEY_LEFT = sf::Keyboard::A;
const sf::Keyboard::Key KEY_RIGHT = sf::Keyboard::D;
const sf::Keyboard::Key KEY_UP = sf::Keyboard::W;
const sf::Keyboard::Key KEY_DOWN = sf::Keyboard::S;
// :
const sf::Color BUTTON_COLOR_TEXT{ 0, 0, 0 };
const sf::Color BUTTON_COLOR_FILL{ 180, 180, 180 };
const sf::Color BUTTON_COLOR_SELECTION{ 255, 180, 180 };
const sf::Color BUTTON_COLOR_FRAME{ 0, 0, 0 };
const sf::Color SELECT_LEVEL_BACKGROUND_COLOR{ 230,230,230 };
const sf::Color GAME_COLOR_BACKGROUND_INGAME{ 230,230,230 };
const sf::Color GAME_COLOR_BACKGROUND_WIN{ 0, 255, 0 };
const sf::Color GAME_COLOR_BACKGROUND_LOST{ 255, 0, 0 };
const sf::Color GAME_COLOR_PACMAN{ 250, 150, 0 };
const sf::Color GAME_COLOR_ROOM{ 255, 255, 255 };
const sf::Color GAME_COLOR_WALL{ 0, 0, 0 };
const sf::Color GAME_FOOD_COLOR{ 0, 200, 100 };
const sf::Color GAME_ENEMY_COLOR{ 255, 50, 0 };
}
\ 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