#include <cstdint>
#include <SFML/Graphics.hpp>
const uint8_t ALL_WALLS = 0b1111;
const uint8_t LEFT_WALL = 0b1000;
const uint8_t DOWN_WALL = 0b0100;
const uint8_t RIGHT_WALL = 0b0010;
const uint8_t UP_WALL = 0b0001;
class Cell {
private:
int column;
int row;
sf::RectangleShape cell;
sf::RectangleShape walls[4];
sf::Texture background;
uint8_t activeWalls;
public:
Cell(sf::Vector2f position, sf::Vector2f size, int column, int row, float wallWidth,
sf::Color backgroundColor, sf::Color wallColor);
void draw(sf::RenderWindow *window);
uint8_t getActiveWalls();
int getColumn();
int getRow();
void setActiveWalls(uint8_t walls);
void setBackgroundColor(sf::Color backgroundColor);
void setTexture(const std::string &texturePath);
void removeWalls(uint8_t walls);
bool isVisited = false;
};
Cell::Cell(sf::Vector2f position, sf::Vector2f size, int column, int row, float wallWidth, sf::Color backgroundColor, sf::Color wallColor) {
this->cell = sf::RectangleShape(size);
this->cell.setPosition(position);
this->cell.setFillColor(backgroundColor);
this->column = column;
this->row = row;
this->activeWalls = ALL_WALLS;
this->walls[0] = sf::RectangleShape(sf::Vector2f(size.x, wallWidth));
this->walls[0].setPosition(sf::Vector2f(position.x, position.y));
this->walls[0].setFillColor(wallColor);
this->walls[1] = sf::RectangleShape(sf::Vector2f(wallWidth, size.y));
this->walls[1].setPosition(sf::Vector2f(position.x + size.x - wallWidth, position.y));
this->walls[1].setFillColor(wallColor);
this->walls[2] = sf::RectangleShape(sf::Vector2f(size.x, wallWidth));
this->walls[2].setPosition(sf::Vector2f(position.x, position.y + size.y - wallWidth));
this->walls[2].setFillColor(wallColor);
this->walls[3] = sf::RectangleShape(sf::Vector2f(wallWidth, size.y));
this->walls[3].setPosition(sf::Vector2f(position.x, position.y));
this->walls[3].setFillColor(wallColor);
}
void Cell::draw(sf::RenderWindow *window) {
if(this->isVisited)
window->draw(this->cell);
if(this->activeWalls & 0b1)
window->draw(this->walls[0]);
if((this->activeWalls >> 1) & 0b1)
window->draw(this->walls[1]);
if((this->activeWalls >> 2) & 0b1)
window->draw(this->walls[2]);
if((this->activeWalls >> 3) & 0b1)
window->draw(this->walls[3]);
}
uint8_t Cell::getActiveWalls() {
if (this->activeWalls)
return this->activeWalls;
}
void Cell::setActiveWalls(uint8_t walls) {
this->activeWalls = walls;
}
void Cell::setBackgroundColor(sf::Color backgroundColor) {
this->cell.setFillColor(backgroundColor);
}
void Cell::setTexture(const std::string &texturePath) {
if (this->background.loadFromFile(texturePath)) {
this->cell.setTexture(&background, true);
}
}
void Cell::removeWalls(uint8_t walls) {
this->activeWalls &= (walls ^ 0b1111);
}
int Cell::getColumn() {
return this->column;
}
int Cell::getRow() {
return this->row;
}