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

Finally FIXED BUGS and it WORKS

parent 20497752
No related merge requests found
Showing with 39 additions and 74 deletions
+39 -74
......@@ -12,12 +12,13 @@ Button::Button() {
void Button::set(const sf::Vector2f& pos, const sf::Vector2f& button_size, const std::string& text,
size_t font_size, std::unique_ptr<ISelectCommand> ptr_command) {
m_rectangle.setOrigin(m_rectangle.getSize() / 2.f);
m_rectangle.setSize(button_size);
m_rectangle.setOrigin(m_rectangle.getSize() / 2.f);
m_rectangle.setPosition(pos);
m_text.setString(text);
auto bounds = m_text.getLocalBounds();
m_text.setOrigin(bounds.left + bounds.width / 2.0f, bounds.top + bounds.height / 2.0f);
m_text.setPosition(pos);
m_ptr_command = std::move(ptr_command);
}
......
......@@ -5,83 +5,47 @@
#include "Commands/ExitCommand.h"
//Menu::Menu(IStateManager& state_manager) {
// sf::Vector2f starting_position(config::SELECT_LEVEL_VIDEO_MODE.width / 4.f,
// config::SELECT_LEVEL_VIDEO_MODE.height / 5.f);
//
// auto easy_director = std::make_unique<GameBuilderDirector>(
// std::make_unique<SimpleBuilder>(
// config::GAME_VIDEO_MODE.width, config::GAME_VIDEO_MODE.height,
// config::ROOM_SIZE),
// config::GAME_VIDEO_MODE,
// config::EASY_GAME_TITLE,
// config::EASY_GAME_ENEMY_RATIO);
//
// auto medium_director = std::make_unique<GameBuilderDirector>(
// std::make_unique<SimpleBuilder>(
// config::GAME_VIDEO_MODE.width, config::GAME_VIDEO_MODE.height,
// config::ROOM_SIZE),
// config::GAME_VIDEO_MODE,
// config::MEDIUM_GAME_TITLE,
// config::MEDIUM_GAME_ENEMY_RATIO);
//
// auto hard_director = std::make_unique<GameBuilderDirector>(
// std::make_unique<ComplexBuilder>(
// config::GAME_VIDEO_MODE.width, config::GAME_VIDEO_MODE.height,
// config::ROOM_SIZE),
// config::GAME_VIDEO_MODE,
// config::HARD_GAME_TITLE,
// config::HARD_GAME_ENEMY_RATIO);
//
// auto easy_command = std::make_unique<GameCommand>(state_manager, std::move(easy_director));
// auto medium_command = std::make_unique<GameCommand>(state_manager, std::move(medium_director));
// auto hard_command = std::make_unique<GameCommand>(state_manager, std::move(hard_director));
// auto exit_command = std::make_unique<ExitCommand>(state_manager);
// m_buttons[0].set(sf::Vector2f{ starting_position.x, 2*starting_position.y}, config::BUTTON_SIZE, config::BUTTON_TEXT_EASY, config::BUTTON_FONT_SIZE, std::move(easy_command));
// m_buttons[1].set(sf::Vector2f{ starting_position.x, 3*starting_position.y}, config::BUTTON_SIZE, config::BUTTON_TEXT_MEDIUM, config::BUTTON_FONT_SIZE, std::move(medium_command));
// m_buttons[2].set(sf::Vector2f{ starting_position.x, 4*starting_position.y}, config::BUTTON_SIZE, config::BUTTON_TEXT_HARD, config::BUTTON_FONT_SIZE, std::move(hard_command));
// m_buttons[3].set(sf::Vector2f{ starting_position.x, 5*starting_position.y}, config::BUTTON_SIZE, config::BUTTON_TEXT_EXIT, config::BUTTON_FONT_SIZE, std::move(exit_command));
//}
Menu::Menu(IStateManager& state_manager) {
float select_screen_width = config::SELECT_LEVEL_VIDEO_MODE.width;
float select_screen_height = config::SELECT_LEVEL_VIDEO_MODE.height;
float game_screen_width = config::GAME_VIDEO_MODE.width;
float game_screen_height = config::GAME_VIDEO_MODE.height;
auto ptr_director_simple = std::make_unique<GameBuilderDirector>
(std::make_unique<SimpleBuilder>(game_screen_width,
game_screen_height, config::ROOM_SIZE), config::GAME_VIDEO_MODE,
config::EASY_GAME_TITLE, config::EASY_GAME_ENEMY_RATIO);
auto ptr_director_medium = std::make_unique<GameBuilderDirector>
(std::make_unique<SimpleBuilder>(game_screen_width,
game_screen_height, config::ROOM_SIZE),
config::GAME_VIDEO_MODE, config::MEDIUM_GAME_TITLE, config::MEDIUM_GAME_ENEMY_RATIO);
auto ptr_director_hard = std::make_unique<GameBuilderDirector>
(std::make_unique<ComplexBuilder>(game_screen_width,
game_screen_height, config::ROOM_SIZE),
config::GAME_VIDEO_MODE, config::HARD_GAME_TITLE, config::HARD_GAME_ENEMY_RATIO);
float button_pos_x = select_screen_width / 2.f;
float button_pos_y = select_screen_height / 5.f;
m_buttons.at(0).set({ button_pos_x, button_pos_y }, config::BUTTON_SIZE,
config::BUTTON_TEXT_EASY, config::BUTTON_FONT_SIZE,
std::make_unique<GameCommand>(state_manager, std::move(ptr_director_simple)));
m_buttons.at(1).set({ button_pos_x, 2 * button_pos_y }, config::BUTTON_SIZE,
config::BUTTON_TEXT_MEDIUM, config::BUTTON_FONT_SIZE,
std::make_unique<GameCommand>(state_manager, std::move(ptr_director_medium)));
m_buttons.at(2).set({ button_pos_x, 3 * button_pos_y }, config::BUTTON_SIZE,
config::BUTTON_TEXT_HARD, config::BUTTON_FONT_SIZE,
std::make_unique<GameCommand>(state_manager, std::move(ptr_director_hard)));
m_buttons.at(3).set({ button_pos_x, 4 * button_pos_y }, config::BUTTON_SIZE,
config::BUTTON_TEXT_EXIT, config::BUTTON_FONT_SIZE,
std::make_unique<ExitCommand>(state_manager));
sf::Vector2f starting_position(config::SELECT_LEVEL_VIDEO_MODE.width / 2.f,
config::SELECT_LEVEL_VIDEO_MODE.height / 5.f);
auto easy_director = std::make_unique<GameBuilderDirector>(
std::make_unique<SimpleBuilder>(
config::GAME_VIDEO_MODE.width, config::GAME_VIDEO_MODE.height,
config::ROOM_SIZE),
config::GAME_VIDEO_MODE,
config::EASY_GAME_TITLE,
config::EASY_GAME_ENEMY_RATIO);
auto medium_director = std::make_unique<GameBuilderDirector>(
std::make_unique<SimpleBuilder>(
config::GAME_VIDEO_MODE.width, config::GAME_VIDEO_MODE.height,
config::ROOM_SIZE),
config::GAME_VIDEO_MODE,
config::MEDIUM_GAME_TITLE,
config::MEDIUM_GAME_ENEMY_RATIO);
auto hard_director = std::make_unique<GameBuilderDirector>(
std::make_unique<ComplexBuilder>(
config::GAME_VIDEO_MODE.width, config::GAME_VIDEO_MODE.height,
config::ROOM_SIZE),
config::GAME_VIDEO_MODE,
config::HARD_GAME_TITLE,
config::HARD_GAME_ENEMY_RATIO);
auto easy_command = std::make_unique<GameCommand>(state_manager, std::move(easy_director));
auto medium_command = std::make_unique<GameCommand>(state_manager, std::move(medium_director));
auto hard_command = std::make_unique<GameCommand>(state_manager, std::move(hard_director));
auto exit_command = std::make_unique<ExitCommand>(state_manager);
m_buttons[0].set(sf::Vector2f{ starting_position.x, starting_position.y}, config::BUTTON_SIZE, config::BUTTON_TEXT_EASY, config::BUTTON_FONT_SIZE, std::move(easy_command));
m_buttons[1].set(sf::Vector2f{ starting_position.x, 2*starting_position.y}, config::BUTTON_SIZE, config::BUTTON_TEXT_MEDIUM, config::BUTTON_FONT_SIZE, std::move(medium_command));
m_buttons[2].set(sf::Vector2f{ starting_position.x, 3*starting_position.y}, config::BUTTON_SIZE, config::BUTTON_TEXT_HARD, config::BUTTON_FONT_SIZE, std::move(hard_command));
m_buttons[3].set(sf::Vector2f{ starting_position.x, 4*starting_position.y}, config::BUTTON_SIZE, config::BUTTON_TEXT_EXIT, config::BUTTON_FONT_SIZE, std::move(exit_command));
}
void Menu::draw_into(sf::RenderWindow& window) const {
for (const Button& ptr_button : m_buttons)
ptr_button.draw_into(window);
for (const Button& button : m_buttons)
button.draw_into(window);
}
void Menu::process_mouse(sf::Vector2f pos, bool is_pressed) {
......
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