69 lines
1.5 KiB
C++
69 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include <SFML/Graphics/RenderWindow.hpp>
|
|
#include <SFML/Graphics/VertexArray.hpp>
|
|
#include <SFML/Graphics/Texture.hpp>
|
|
#include <SFML/Graphics/Sprite.hpp>
|
|
#include <array>
|
|
|
|
using pos = std::pair<int, int>;
|
|
|
|
enum class DIRECTION
|
|
{
|
|
UP,
|
|
DOWN,
|
|
RIGHT,
|
|
LEFT,
|
|
|
|
NONE
|
|
};
|
|
|
|
//////////////////////////////////
|
|
|
|
class Board
|
|
{
|
|
public:
|
|
explicit Board(int splitting = 1);
|
|
~Board();
|
|
|
|
// Output current graphical state on application window
|
|
void draw(sf::RenderWindow& window);
|
|
|
|
// Move cursor to next tile by given direction
|
|
bool moveSelection(const DIRECTION& direction);
|
|
|
|
// Go to or leave from selection mode
|
|
void onSelectionMode();
|
|
|
|
// Did player win the game
|
|
bool isWinCondition() const;
|
|
|
|
private:
|
|
|
|
// Game tile
|
|
struct Cell
|
|
{
|
|
std::vector<Cell>::size_type inital_index;
|
|
std::vector<Cell>::size_type current_index;
|
|
sf::Sprite *sprite;
|
|
static int side_length;
|
|
};
|
|
|
|
using Cells = std::vector<Cell*>;
|
|
using RefCells = std::vector<Cells::size_type>;
|
|
|
|
sf::VertexArray rect_selection;
|
|
Cells::size_type selection_index;
|
|
|
|
Cells::size_type cells_on_width; // amount of cells on horizontal side of board
|
|
Cells::size_type cells_on_height; // amount of cells on vertical side of board
|
|
Cells vec_field;
|
|
sf::Texture global_texture;
|
|
bool on_selection;
|
|
|
|
void swapCells(Cells::size_type curr_index, Cells::size_type swap_index);
|
|
|
|
// Draw selection cursor on given tile
|
|
void setSelectionVertex(Cells::size_type index);
|
|
};
|