diff --git a/Board.cpp b/Board.cpp new file mode 100644 index 0000000..62636fa --- /dev/null +++ b/Board.cpp @@ -0,0 +1,282 @@ +#include + +#include + +#include "Board.hpp" +#include "Gem.hpp" + + +Board::Board(int width, int height) { + rows_ = height / sizeGem_; + columns_ = width / sizeGem_; + width_ = width; + height_ = height; +} + +void Board::Draw(sf::RenderWindow& window) { + // + + for (int i = 0; i < gems_.size(); i++) + { + for (int j = 0; j < gems_[i].size(); j++) + { + sf::RectangleShape square(sf::Vector2f(sizeGem_, sizeGem_)); + square.setFillColor(gems_[i][j]->GetColor()); + square.setPosition(j * sizeGem_, i * sizeGem_); + window.draw(square); + } + } +} + +void Board::CreateGems() { + // , + + for (int i = 0; i < rows_; i++) { + std::vector row; + for (int j = 0; j < columns_; j++) { + sf::Color color = Gem::ChoiceColor(); + row.push_back(new Gem(i, j, color)); + } + gems_.push_back(row); + } + if (IsFoundCombinatioins()) { + for (vector row_gem : gems_) { + row_gem.clear(); + } + gems_.clear(); + CreateGems(); + } +} + +int Board::GetSizeGem() { + return sizeGem_; +} + +vector> Board::GetGems() { + return gems_; +} + +Gem& Board::GetGemAt(int x, int y) { + return *gems_[y][x]; +} + +void Board::AnimationMove(int x1, int y1, int x2, int y2, float transitionTime, sf::RenderWindow& window) { + // (x1, y1) (x2, y2) + + sf::Color gem1_color = gems_[x1][y1]->GetColor(); + sf::Color gem2_color = gems_[x2][y2]->GetColor(); + gems_[x1][y1]->SetColor(sf::Color::Black); + gems_[x2][y2]->SetColor(sf::Color::Black); + const int numSteps = 100; + + sf::RectangleShape square1(sf::Vector2f(sizeGem_, sizeGem_)); + square1.setFillColor(gem1_color); + + sf::RectangleShape square2(sf::Vector2f(sizeGem_, sizeGem_)); + square2.setFillColor(gem2_color); + + sf::Vector2f startPos1(y1 * sizeGem_, x1 * sizeGem_); + sf::Vector2f endPos1(y2 * sizeGem_, x2 * sizeGem_); + sf::Vector2f startPos2(y2 * sizeGem_, x2 * sizeGem_); + sf::Vector2f endPos2(y1 * sizeGem_, x1 * sizeGem_); + + sf::Vector2f currentPos1(startPos1); + sf::Vector2f currentPos2(startPos2); + + sf::Clock clock; + float elapsedTime = 0.0f; + + for (int i = 0; i < numSteps; ++i) { + elapsedTime = clock.getElapsedTime().asSeconds(); + if (elapsedTime > transitionTime) { + currentPos1 = endPos1; + break; + } + float interpFactor = elapsedTime / transitionTime; + + currentPos1.x = startPos1.x + interpFactor * (endPos1.x - startPos1.x); + currentPos1.y = startPos1.y + interpFactor * (endPos1.y - startPos1.y); + + currentPos2.x = startPos2.x + interpFactor * (endPos2.x - startPos2.x); + currentPos2.y = startPos2.y + interpFactor * (endPos2.y - startPos2.y); + + square1.setPosition(currentPos1); + square1.setFillColor(gem1_color); + square2.setPosition(currentPos2); + square2.setFillColor(gem2_color); + + window.clear(); + Draw(window); + window.draw(square1); + window.draw(square2); + sf::VertexArray lines = CreateLines(); + window.draw(lines); + window.display(); + + sf::sleep(sf::milliseconds(5)); + } + gems_[x1][y1]->SetColor(gem1_color); + gems_[x2][y2]->SetColor(gem2_color); +} + +void Board::SwapGems(int x1, int y1, int x2, int y2) { + // + + int temp_x = gems_[x1][y1]->GetX(); + int temp_y = gems_[x1][y1]->GetY(); + gems_[x1][y1]->SetX(gems_[x2][y2]->GetX()); + gems_[x1][y1]->SetY(gems_[x2][y2]->GetY()); + gems_[x2][y2]->SetX(temp_x); + gems_[x2][y2]->SetY(temp_y); + std::swap(gems_[x1][y1], gems_[x2][y2]); +} + +bool Board::IsFoundCombinatioins() { + // " " + + const int num_rows = gems_.size(); + const int num_cols = gems_[0].size(); + + for (int i = 0; i < num_rows; i++) { + for (int j = 0; j < num_cols - 2; j++) { + if (gems_[i][j]->GetColor() == gems_[i][j + 1]->GetColor() && gems_[i][j + 1]->GetColor() == gems_[i][j + 2]->GetColor()) { + return true; + } + } + } + + for (int i = 0; i < num_rows - 2; i++) { + for (int j = 0; j < num_cols; j++) { + if (gems_[i][j]->GetColor() == gems_[i + 1][j]->GetColor() && gems_[i + 1][j]->GetColor() == gems_[i + 2][j]->GetColor()) { + return true; + } + } + } + + return false; +} + +std::set> Board::SearchCombinations() { + // , + + std::set> coordinates_combinations; + const int num_rows = gems_.size(); + const int num_cols = gems_[0].size(); + + for (int i = 0; i < num_rows; i++) { + for (int j = 0; j < num_cols - 2; j++) { + if (gems_[i][j]->GetColor() == gems_[i][j + 1]->GetColor() && gems_[i][j + 1]->GetColor() == gems_[i][j + 2]->GetColor()) { + coordinates_combinations.insert(std::make_tuple(i, j)); + coordinates_combinations.insert(std::make_tuple(i, j + 1)); + coordinates_combinations.insert(std::make_tuple(i, j + 2)); + } + } + } + + for (int i = 0; i < num_rows - 2; i++) { + for (int j = 0; j < num_cols; j++) { + if (gems_[i][j]->GetColor() == gems_[i + 1][j]->GetColor() && gems_[i + 1][j]->GetColor() == gems_[i + 2][j]->GetColor()) { + coordinates_combinations.insert(std::make_tuple(i, j)); + coordinates_combinations.insert(std::make_tuple(i + 1, j)); + coordinates_combinations.insert(std::make_tuple(i + 2, j)); + } + } + } + + return coordinates_combinations; +} + +void Board::DestroyGems(std::set>& coordinates_combinations, sf::RenderWindow& window) { + // + // + + for (auto& coordinate : coordinates_combinations) { + int x = std::get<0>(coordinate); + int y = std::get<1>(coordinate); + gems_[x][y]->SetColor(sf::Color::Black); + + switch (std::rand() % 15) { + case 0: { + std::tuple positionBomb = SetBonusPosition(x, y); + gems_[std::get<0>(positionBomb)][std::get<1>(positionBomb)]->SetBomb(true); + gems_[x][y]->SetColor(sf::Color::Black); + } + break; + case 1: { + std::tuple positionMarker = SetBonusPosition(x, y); + gems_[std::get<0>(positionMarker)][std::get<1>(positionMarker)]->SetMarker(true); + gems_[x][y]->SetColor(sf::Color::Black); + } + } + } +} + +void Board::AddGems(sf::RenderWindow& window) { + // + // + + for (int j = 0; j < gems_[0].size(); ++j) { + for (int i = 0; i < gems_.size(); ++i) { + if (gems_[i][j]->GetColor() == sf::Color::Black) { + for (int k = i; k > 0; --k) { + SwapGems(gems_[k][j]->GetX(), gems_[k][j]->GetY(), gems_[k - 1][j]->GetX(), gems_[k - 1][j]->GetY()); + AnimationMove(gems_[k][j]->GetX(), gems_[k][j]->GetY(), gems_[k - 1][j]->GetX(), gems_[k - 1][j]->GetY(), 0.1f, window); + } + gems_[0][j]->SetColor(Gem::ChoiceColor()); + } + } + } +} + +std::tuple Board::SetBonusPosition(int x, int y) { + // + // + + std::vector> candidates; + for (int i = x - 3; i <= x + 3; ++i) { + for (int j = y - 3; j <= y + 3; ++j) { + if (i >= 0 && i < rows_ && j >= 0 && j < columns_) { + candidates.push_back({ i, j }); + } + } + } + + int indexPositionBonus = rand () % candidates.size(); + return candidates[indexPositionBonus]; +} + +sf::VertexArray Board::CreateLines() { + // + + sf::VertexArray lines(sf::Lines); + for (int i = 0; i <= width_; i += sizeGem_) { + lines.append(sf::Vertex(sf::Vector2f(static_cast(i), 0), sf::Color::Black)); + lines.append(sf::Vertex(sf::Vector2f(static_cast(i), static_cast(height_)), sf::Color::Black)); + } + for (int i = 0; i <= height_; i += sizeGem_) { + lines.append(sf::Vertex(sf::Vector2f(0, static_cast(i)), sf::Color::Black)); + lines.append(sf::Vertex(sf::Vector2f(static_cast(width_), static_cast(i)), sf::Color::Black)); + } + return lines; +} + +void Board::Update(sf::RenderWindow& window) { + // : , + // , , + // , + + std::set> coordinates_combinations; + do { + coordinates_combinations = SearchCombinations(); + DestroyGems(coordinates_combinations, window); + Draw(window); + window.draw(CreateLines()); + window.display(); + sf::sleep(sf::seconds(0.3f)); + AddGems(window); + Draw(window); + window.draw(CreateLines()); + window.display(); + sf::sleep(sf::seconds(0.3f)); + } while (!coordinates_combinations.empty()); +} \ No newline at end of file diff --git a/Board.hpp b/Board.hpp new file mode 100644 index 0000000..a731ec9 --- /dev/null +++ b/Board.hpp @@ -0,0 +1,44 @@ +#pragma once + +#include + +#include "Gem.hpp" + +#include +#include +#include +#include + +using namespace std; + +class Board { +private: + vector> gems_; + int rows_; + int columns_; + int width_; + int height_; + static const int sizeGem_ = 100; + +public: + Board(int width, int height); + + void Draw(sf::RenderWindow& window); + void AnimationMove(int x1, int y1, int x2, int y2, float transitionTime, sf::RenderWindow& window); + sf::VertexArray CreateLines(); + + void CreateGems(); + void SwapGems(int x1, int y1, int x2, int y2); + void DestroyGems(std::set>& coordinates_combinations, sf::RenderWindow& window); + void AddGems(sf::RenderWindow& window); + + int GetSizeGem(); + vector> GetGems(); + Gem& GetGemAt(int x, int y); + + bool IsFoundCombinatioins(); + std::set> SearchCombinations(); + void Update(sf::RenderWindow& window); + + std::tuple SetBonusPosition(int x, int y); +}; \ No newline at end of file diff --git a/Bomb.cpp b/Bomb.cpp new file mode 100644 index 0000000..3159d04 --- /dev/null +++ b/Bomb.cpp @@ -0,0 +1,60 @@ +#include + +#include "Bomb.hpp" + +Bomb::Bomb(int x, int y) { + x_ = x; + y_ = y; +} + +void Bomb::Draw(sf::RenderWindow& window, int sizeGem) { + // + + sf::CircleShape circle(200); + + float radius = 30; + float delta = 1; + circle.setRadius(radius); + circle.setPosition(x_ * sizeGem + 0.2 * sizeGem, y_ * sizeGem + 0.2 * sizeGem); + + circle.setFillColor(sf::Color(40, 40, 40)); + + circle.setOutlineThickness(10); + circle.setOutlineColor(sf::Color::Black); + + sf::RectangleShape wick(sf::Vector2f(20, 10)); + wick.setFillColor(sf::Color::Black); + wick.rotate(135); + + wick.setPosition(x_ * sizeGem + 0.95 * sizeGem, y_ * sizeGem + 0.1 * sizeGem); + window.draw(wick); + window.draw(circle); + sf::RectangleShape fire(sf::Vector2f(10, 10)); + fire.rotate(135); + fire.setFillColor(sf::Color(255, 165, 0)); + fire.setOutlineThickness(3); + fire.setOutlineColor(sf::Color::Black); + + fire.setPosition(wick.getPosition() + sf::Vector2f(0, 0)); + + window.draw(fire); +} + +void Bomb::ActionBomb(sf::RenderWindow& window, Board& board) { + // + + for (int i = 0; i < 4; i++) { + int x = rand() % board.GetGems()[0].size(); + int y = rand() % board.GetGems().size(); + std::cout << x << std::endl; + std::cout << y << std::endl; + Gem& gem = board.GetGemAt(x, y); + gem.SetColor(sf::Color::Black); + std::cout << x << std::endl; + std::cout << y << std::endl; + } + Gem& gem_with_bomb = board.GetGemAt(x_, y_); + gem_with_bomb.SetColor(sf::Color::Black); + board.Draw(window); + board.AddGems(window); +} diff --git a/Bomb.hpp b/Bomb.hpp new file mode 100644 index 0000000..43fe44a --- /dev/null +++ b/Bomb.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include + +#include "Gem.hpp" +#include "Board.hpp" + +class Bomb : public Gem { +public: + Bomb(int x, int y); + void Draw(sf::RenderWindow& window, int sizeGem); + void ActionBomb(sf::RenderWindow& window, Board& board); +}; \ No newline at end of file diff --git a/Game.cpp b/Game.cpp new file mode 100644 index 0000000..653dde9 --- /dev/null +++ b/Game.cpp @@ -0,0 +1,156 @@ +#include + +#include "Game.hpp" + +#include +#include +#include + + +Game::Game(int width, int height) { + width_ = width; + height_ = height; +} + +Board Game::CreateBoard() { + // + + Board board(width_, height_); + board.CreateGems(); + return board; +} + +void Game::Run(Board& board) { + // + + sf::RenderWindow window(sf::VideoMode(width_, height_), "GEMS"); + window.setFramerateLimit(60); + sf::VertexArray lines = board.CreateLines(); + + Gem* selectable_gem = nullptr; + bool selected_gem_exists = false; + + while (window.isOpen()) + { + window.clear(sf::Color::Black); + sf::Event event; + while (window.pollEvent(event)) + { + switch (event.type) { + case sf::Event::Closed: + window.close(); + case sf::Event::MouseButtonPressed: + if (event.mouseButton.button == sf::Mouse::Left) { + int x = event.mouseButton.x / board.GetSizeGem(); + int y = event.mouseButton.y / board.GetSizeGem(); + + if (x >= 0 && x < board.GetGems()[0].size() && y >= 0 && y < board.GetGems().size()) { + Gem& current_gem = board.GetGemAt(x, y); // + if (selectable_gem != nullptr) { + // , + if (selectable_gem == ¤t_gem) { + selectable_gem->SetDeselected(); + selectable_gem = nullptr; + break; + } + // , + else if ((abs(selectable_gem->GetY() - current_gem.GetY()) + abs(selectable_gem->GetX() - current_gem.GetX()) == 1)) { + board.AnimationMove(selectable_gem->GetX(), selectable_gem->GetY(), current_gem.GetX(), current_gem.GetY(), 0.2f, window); + board.SwapGems(selectable_gem->GetX(), selectable_gem->GetY(), current_gem.GetX(), current_gem.GetY()); + current_gem.SetSelected(); + board.Draw(window); + + selectable_gem->SetDeselected(); + current_gem.SetDeselected(); + + // " ", + if (board.IsFoundCombinatioins()) { + board.Update(window); + } + // + else { + board.AnimationMove(selectable_gem->GetX(), selectable_gem->GetY(), current_gem.GetX(), current_gem.GetY(), 0.2f, window); + board.SwapGems(selectable_gem->GetX(), selectable_gem->GetY(), current_gem.GetX(), current_gem.GetY()); + } + selectable_gem = nullptr; + board.Draw(window); + break; + } + else { + selectable_gem->SetDeselected(); + } + } + selectable_gem = ¤t_gem; + selectable_gem->SetSelected(); + board.Draw(window); + } + } + + } + } + + for (int i = 0; i < board.GetGems().size(); i++) { + for (int j = 0; j < board.GetGems()[0].size(); j++) { + Gem& current_gem = board.GetGemAt(j, i); + if (current_gem.GetSelected() && (¤t_gem != selectable_gem)) { + current_gem.SetDeselected(); + } + } + } + + // - + std::vector markers; + for (int i = 0; i < board.GetGems().size(); i++) { + for (int j = 0; j < board.GetGems()[0].size(); j++) { + Gem& current_gem = board.GetGemAt(j, i); + if (current_gem.GetMarker() && !current_gem.GetBomb()) { + current_gem.SetMarker(false); + Marker marker(j, i, current_gem.GetColor()); + markers.push_back(marker); + } + } + } + + // - + for (Marker marker : markers) { + board.Draw(window); + marker.Draw(window, board.GetSizeGem()); + window.draw(lines); + window.display(); + sf::sleep(sf::seconds(1.5f)); + marker.ActionMarker(window, board); + } + + // - + std::vector bombs; + for (int i = 0; i < board.GetGems().size(); i++) { + for (int j = 0; j < board.GetGems()[0].size(); j++) { + Gem& current_gem = board.GetGemAt(j, i); + if (current_gem.GetBomb() && !current_gem.GetMarker()) { + current_gem.SetBomb(false); + Bomb bomb(j, i); + bombs.push_back(bomb); + } + } + } + + // - + for (Bomb bomb : bombs) { + board.Draw(window); + bomb.Draw(window, board.GetSizeGem()); + window.draw(lines); + window.display(); + sf::sleep(sf::seconds(1.5f)); + bomb.ActionBomb(window, board); + } + + // + while (board.IsFoundCombinatioins()) { + board.Update(window); + } + + board.Draw(window); + window.draw(lines); + window.display(); + } +} \ No newline at end of file diff --git a/Game.hpp b/Game.hpp new file mode 100644 index 0000000..d49d167 --- /dev/null +++ b/Game.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include + +#include "Board.hpp" +#include "Gem.hpp" +#include "Marker.hpp" +#include "Bomb.hpp" + +class Game { +private: + int width_; + int height_; + +public: + Game(int width, int height); + Board CreateBoard(); + void Run(Board& board); + +}; + diff --git a/Gem.cpp b/Gem.cpp new file mode 100644 index 0000000..bbb6f9f --- /dev/null +++ b/Gem.cpp @@ -0,0 +1,89 @@ +#include +#include "Gem.hpp" + + +Gem::Gem() {} + +Gem::Gem(int x, int y, sf::Color color) { + x_ = x; + y_ = y; + color_ = color; +} + +void Gem::SetX(int newX) { + x_ = newX; +} + +void Gem::SetY(int newY) { + y_ = newY; +} + +void Gem::SetColor(sf::Color newColor) { + color_ = newColor; +} + +void Gem::SetSelected() { + // ( ) + + isSelected_ = true; + originalColor_ = color_; + color_ = sf::Color(color_.r, color_.g, color_.b, 200); +} + +void Gem::SetDeselected() { + // , + + isSelected_ = false; + color_ = originalColor_; +} + +void Gem::SetBomb(bool isBomb) { + isBomb_ = isBomb; +} + +void Gem::SetMarker(bool isMarker) { + isMarker_ = isMarker; +} + +int Gem::GetX() { + return x_; +} + +int Gem::GetY() { + return y_; +} + +sf::Color Gem::GetColor() { + return color_; +} + +bool Gem::GetSelected() const { return isSelected_; } + +bool Gem::GetBomb() { + return isBomb_; +} + +bool Gem::GetMarker() { + return isMarker_; +} + +sf::Color Gem::ChoiceColor() { + // + + switch (std::rand() % 6) { + case 0: + return sf::Color::Red; + case 1: + return sf::Color::Green; + case 2: + return sf::Color::Blue; + case 3: + return sf::Color::Yellow; + case 4: + return sf::Color::Magenta; + case 5: + return sf::Color::Cyan; + } +} + + diff --git a/Gem.hpp b/Gem.hpp new file mode 100644 index 0000000..67f4545 --- /dev/null +++ b/Gem.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include + + +class Gem { +protected: + sf::Color color_; + sf::Color originalColor_; + int x_; + int y_; + bool isSelected_ = false; + bool isBomb_ = false; + bool isMarker_ = false; + +public: + Gem(); + Gem(int x, int y, sf::Color color); + static sf::Color ChoiceColor(); + + void SetX(int newX); + void SetY(int newY); + void SetColor(sf::Color newColor); + void SetSelected(); + void SetDeselected(); + void SetBomb(bool isBomb); + void SetMarker(bool isMarker); + + int GetX(); + int GetY(); + sf::Color GetColor(); + bool GetSelected() const; + bool GetBomb(); + bool GetMarker(); +}; \ No newline at end of file diff --git a/Gems.vcxproj b/Gems.vcxproj new file mode 100644 index 0000000..97e3760 --- /dev/null +++ b/Gems.vcxproj @@ -0,0 +1,153 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {c6783236-2cd4-42d6-8052-899ebaebf494} + Gems + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + C:\Program Files (x86)\SFML\SFML-2.5.1\include + + + Console + true + C:\Program Files (x86)\SFML\SFML-2.5.1\lib + $(CoreLibraryDependencies);%(AdditionalDependencies);sfml-graphics.lib;sfml-window.lib;sfml-system.lib + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + C:\Program Files (x86)\SFML\SFML-2.5.1\include + + + Console + true + true + true + C:\Program Files (x86)\SFML\SFML-2.5.1\lib + $(CoreLibraryDependencies);%(AdditionalDependencies);sfml-graphics.lib;sfml-window.lib;sfml-system.lib + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Gems.vcxproj.filters b/Gems.vcxproj.filters new file mode 100644 index 0000000..74b93e8 --- /dev/null +++ b/Gems.vcxproj.filters @@ -0,0 +1,54 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Исходные файлы + + + Исходные файлы + + + Исходные файлы + + + Исходные файлы + + + Исходные файлы + + + Исходные файлы + + + + + Файлы заголовков + + + Файлы заголовков + + + Файлы заголовков + + + Файлы заголовков + + + Файлы заголовков + + + \ No newline at end of file diff --git a/Main.cpp b/Main.cpp new file mode 100644 index 0000000..95bf5e7 --- /dev/null +++ b/Main.cpp @@ -0,0 +1,16 @@ +#include +#include +#include "Game.hpp" + +const int WINDOW_WIDTH = 1200; +const int WINDOW_HEIGHT = 800; + +int main() +{ + srand(time(NULL)); + Game game(WINDOW_WIDTH, WINDOW_HEIGHT); + Board board = game.CreateBoard(); + + game.Run(board); + return 0; +} \ No newline at end of file diff --git a/Marker.cpp b/Marker.cpp new file mode 100644 index 0000000..5aeb91e --- /dev/null +++ b/Marker.cpp @@ -0,0 +1,64 @@ +#include + +#include "Marker.hpp" + +#include +#include + + +void Marker::Draw(sf::RenderWindow& window, int sizeGem) { + // + + sf::RectangleShape body(sf::Vector2f(90, 10)); + body.setFillColor(sf::Color(255, 219, 48)); + body.setOutlineThickness(3); + body.setOutlineColor(sf::Color::Black); + body.setPosition((x_+1) * sizeGem - 0.05 * sizeGem, y_ * sizeGem + 0.1 * sizeGem); + body.rotate(135); + + sf::CircleShape tip(7); + tip.setFillColor(sf::Color::White); + tip.setOutlineThickness(2); + tip.setOutlineColor(sf::Color::Black); + tip.setPosition(x_ * sizeGem + 0.19 * sizeGem, (y_+1) * sizeGem - 0.34 * sizeGem); + + window.draw(tip); + window.draw(body); +} + +void Marker::ActionMarker(sf::RenderWindow& window, Board& board) { + // + + std::vector> candidates_painted_gems; + std::vector> painted_gems; + candidates_painted_gems.push_back({ x_ - 1, y_ - 1 }); + candidates_painted_gems.push_back({ x_ + 1, y_ - 1 }); + candidates_painted_gems.push_back({ x_ - 1, y_ + 1 }); + candidates_painted_gems.push_back({ x_ + 1, y_ + 1 }); + + for (std::tuple candidate : candidates_painted_gems) { + int x = std::get<0>(candidate); + int y = std::get<1>(candidate); + if (x > 0 && x < board.GetGems()[0].size() && y > 0 && y < board.GetGems().size()) { + painted_gems.push_back(candidate); + } + + } + + std::mt19937 rng(std::random_device{}()); + std::shuffle(painted_gems.begin(), painted_gems.end(), rng); + + switch (painted_gems.size()) { + case 4: case 3: case 2: { + Gem& first_painted = board.GetGemAt(std::get<0>(painted_gems[0]), std::get<1>(painted_gems[0])); + Gem& second_painted = board.GetGemAt(std::get<0>(painted_gems[1]), std::get<1>(painted_gems[1])); + first_painted.SetColor(color_); + second_painted.SetColor(color_); + break; } + case 1: { + Gem& painted = board.GetGemAt(std::get<0>(painted_gems[0]), std::get<1>(painted_gems[0])); + painted.SetColor(color_); + break; } + } + board.Draw(window); +} \ No newline at end of file diff --git a/Marker.hpp b/Marker.hpp new file mode 100644 index 0000000..f27f07b --- /dev/null +++ b/Marker.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include + +#include "Gem.hpp" +#include "Board.hpp" + + +class Marker : public Gem { +public: + using Gem::Gem; + void Draw(sf::RenderWindow& window, int sizeGem); + void ActionMarker(sf::RenderWindow& window, Board& board); +}; \ No newline at end of file diff --git a/openal32.dll b/openal32.dll new file mode 100644 index 0000000..7760c05 Binary files /dev/null and b/openal32.dll differ diff --git a/sfml-audio-2.dll b/sfml-audio-2.dll new file mode 100644 index 0000000..0662877 Binary files /dev/null and b/sfml-audio-2.dll differ diff --git a/sfml-audio-d-2.dll b/sfml-audio-d-2.dll new file mode 100644 index 0000000..39ef315 Binary files /dev/null and b/sfml-audio-d-2.dll differ diff --git a/sfml-graphics-2.dll b/sfml-graphics-2.dll new file mode 100644 index 0000000..d343470 Binary files /dev/null and b/sfml-graphics-2.dll differ diff --git a/sfml-graphics-d-2.dll b/sfml-graphics-d-2.dll new file mode 100644 index 0000000..c945828 Binary files /dev/null and b/sfml-graphics-d-2.dll differ diff --git a/sfml-network-2.dll b/sfml-network-2.dll new file mode 100644 index 0000000..32f87d2 Binary files /dev/null and b/sfml-network-2.dll differ diff --git a/sfml-network-d-2.dll b/sfml-network-d-2.dll new file mode 100644 index 0000000..c3f3dc8 Binary files /dev/null and b/sfml-network-d-2.dll differ diff --git a/sfml-system-2.dll b/sfml-system-2.dll new file mode 100644 index 0000000..961a0e0 Binary files /dev/null and b/sfml-system-2.dll differ diff --git a/sfml-system-d-2.dll b/sfml-system-d-2.dll new file mode 100644 index 0000000..9ce90a1 Binary files /dev/null and b/sfml-system-d-2.dll differ diff --git a/sfml-window-2.dll b/sfml-window-2.dll new file mode 100644 index 0000000..6a23440 Binary files /dev/null and b/sfml-window-2.dll differ diff --git a/sfml-window-d-2.dll b/sfml-window-d-2.dll new file mode 100644 index 0000000..41eeea0 Binary files /dev/null and b/sfml-window-d-2.dll differ