ThePowerOfTheRings/Hexagon.cpp

240 lines
5.6 KiB
C++

//#include "Hexagon.h"
Hexagon::Hexagon()
: top_m(nullptr), top_right_m(nullptr), top_left_m(nullptr),
bottom_right_m(nullptr), bottom_left_m(nullptr), bottom_m(nullptr),
city_m(), ressource_m(), decoration_m() {}
Hexagon::Hexagon(const City& city)
: top_m(nullptr), top_right_m(nullptr), top_left_m(nullptr),
bottom_right_m(nullptr), bottom_left_m(nullptr), bottom_m(nullptr),
city_m(city), ressource_m(), decoration_m() {}
Hexagon::Hexagon(const Ressource& ressource)
: top_m(nullptr), top_right_m(nullptr), top_left_m(nullptr),
bottom_right_m(nullptr), bottom_left_m(nullptr), bottom_m(nullptr),
city_m(), ressource_m(ressource), decoration_m() {}
Hexagon::Hexagon(const Decoration& decoration)
: top_m(nullptr), top_right_m(nullptr), top_left_m(nullptr),
bottom_right_m(nullptr), bottom_left_m(nullptr), bottom_m(nullptr),
city_m(), ressource_m(), decoration_m(decoration) {}
//--------------------- Getters ---------------------\\
Hexagon* Hexagon::getTop() const {
return top_m;
}
Hexagon* Hexagon::getTopRight() const {
return top_right_m;
}
Hexagon* Hexagon::getTopLeft() const {
return top_left_m;
}
Hexagon* Hexagon::getBottomRight() const {
return bottom_right_m;
}
Hexagon* Hexagon::getBottomLeft() const {
return bottom_left_m;
}
Hexagon* Hexagon::getBottom() const {
return bottom_m;
}
City Hexagon::getCity() const {
return city_m;
}
Ressource Hexagon::getRessource() const {
return ressource_m;
}
//--------------------- Setters ---------------------\\
void Hexagon::setTop(Hexagon* top)
{
if (Hexagon::getTop() == nullptr)
{
top_m = top;
top->setBottom(this);
if (Hexagon::getTopRight() != nullptr)
{
Hexagon::getTopRight()->setTopLeft(top);
}
if (Hexagon::getTopLeft() != nullptr)
{
Hexagon::getTopLeft()->setTopRight(top);
}
}
}
void Hexagon::setTopRight(Hexagon* top_right) {
if (Hexagon::getTopRight() == nullptr) {
top_right_m = top_right;
top_right->setBottomLeft(this);
if (Hexagon::getBottomRight() != nullptr) {
Hexagon::getBottomRight()->setTop(top_right);
}
if (Hexagon::getTop() != nullptr) {
Hexagon::getTop()->setBottomRight(top_right);
}
}
}
void Hexagon::setTopLeft(Hexagon* top_left) {
if (Hexagon::getTopLeft() == nullptr) {
top_left_m = top_left;
top_left->setBottomRight(this);
if (Hexagon::getTop() != nullptr) {
Hexagon::getTop()->setBottomLeft(top_left);
}
if (Hexagon::getBottomLeft() != nullptr) {
Hexagon::getBottomLeft()->setTop(top_left);
}
}
}
void Hexagon::setBottomRight(Hexagon* bottom_right) {
if (Hexagon::getBottomRight() == nullptr) {
bottom_right_m = bottom_right;
bottom_right->setTopLeft(this);
if (Hexagon::getTopRight() != nullptr) {
Hexagon::getTopRight()->setBottom(bottom_right);
}
if (Hexagon::getBottom() != nullptr) {
Hexagon::getBottom()->setTopRight(bottom_right);
}
}
}
void Hexagon::setBottomLeft(Hexagon* bottom_left) {
if (Hexagon::getBottomLeft() == nullptr) {
bottom_left_m = bottom_left;
bottom_left->setTopRight(this);
if (Hexagon::getTopLeft() != nullptr) {
Hexagon::getTopLeft()->setBottom(bottom_left);
}
if (Hexagon::getBottom() != nullptr) {
Hexagon::getBottom()->setTopLeft(bottom_left);
}
}
}
void Hexagon::setBottom(Hexagon* bottom) {
if (Hexagon::getBottom() == nullptr) {
bottom_m = bottom;
bottom->setTop(this);
if (Hexagon::getBottomLeft() != nullptr) {
Hexagon::getBottomLeft()->setBottomRight(bottom);
}
if (Hexagon::getBottomRight() != nullptr) {
Hexagon::getBottomRight()->setBottomLeft(bottom);
}
}
}
void Hexagon::setCity(City city) {
city_m = city;
}
void Hexagon::setRessource(Ressource ressource) {
ressource_m = ressource;
}
//--------------------- Others ---------------------\\
void Hexagon::printHexagon() const {
if(ressource_m.getValue() != 0)
{
std::cout << "Ressource : ";
ressource_m.printRessource();
}
else if (city_m.getName() != "C_default")
{
std::cout << "City : ";
city_m.printCity();
}
}
void Hexagon::printTopLeft() const
{
if (top_left_m != nullptr)
{
std::cout << "Top left : ";
top_left_m->printHexagon();
}
}
void Hexagon::printTop() const
{
if (top_m != nullptr)
{
std::cout << "Top : ";
top_m->printHexagon();
}
}
void Hexagon::printTopRight() const
{
if (top_right_m != nullptr)
{
std::cout << "Top right : ";
top_right_m->printHexagon();
}
}
void Hexagon::printBottomRight() const
{
if (bottom_right_m != nullptr)
{
std::cout << "Bottom right : ";
bottom_right_m->printHexagon();
}
}
void Hexagon::printBottom() const
{
if (bottom_m != nullptr)
{
std::cout << "Bottom : ";
bottom_m->printHexagon();
}
}
void Hexagon::printBottomLeft() const
{
if (bottom_left_m != nullptr)
{
std::cout << "Bottom left : ";
bottom_left_m->printHexagon();
}
}
void Hexagon::printAll() const
{
Hexagon::printHexagon();
Hexagon::printTopLeft();
Hexagon::printTop();
Hexagon::printTopRight();
Hexagon::printBottomRight();
Hexagon::printBottom();
Hexagon::printBottomLeft();
std::cout << std::endl;
}