You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.6 KiB
C

3 years ago
#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
};
//////////////////////////////////
3 years ago
class Board
{
public:
explicit Board();
3 years ago
~Board();
// Output current graphical state on application window
3 years ago
void draw(sf::RenderWindow& window);
// Move cursor to next tile by given direction
3 years ago
bool moveSelection(const DIRECTION& direction);
// Go to or leave from selection mode
3 years ago
void onSelectionMode();
// Did player win the game
3 years ago
bool isWinCondition() const;
// Set play image
3 years ago
bool init(const std::string& path, int splitting, const sf::RenderWindow& window);
3 years ago
private:
// Game tile
3 years ago
struct Cell
{
std::vector<Cell*>::size_type inital_index;
std::vector<Cell*>::size_type current_index;
3 years ago
sf::Sprite *sprite;
static int side_length;
3 years ago
};
using Cells = std::vector<Cell*>;
3 years ago
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
3 years ago
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
3 years ago
void setSelectionVertex(Cells::size_type index);
};