commit 955e65bf0b4fc20d9e3186a0c373b4aa1e1bd2da Author: CaNaRdEoS <125059936+CaNaRdEoS@users.noreply.github.com> Date: Wed Jun 26 15:17:53 2024 +0200 Hexagon kakadoigt diff --git a/Basics1.cpp b/Basics1.cpp new file mode 100644 index 0000000..80efdb1 --- /dev/null +++ b/Basics1.cpp @@ -0,0 +1,100 @@ +#include +#include +#include +#include + +//Daylight +//Strangers kenya + +class Student +{ + std::string first_m = "First"; + std::string last_m = "Last"; + float avg_m = 15.8f; + +public: + Student() {} + + Student(const std::string& first, const std::string& last, const float& avg) + : first_m(first) + , last_m(last) + , avg_m(avg) + {} + + void print() const + { + std::cout << first_m << " " << last_m << " " << avg_m << std::endl; + } +}; + +class Classroom +{ + std::string name_m = "classroom"; + std::vector students_m; + +public: + Classroom() {} + + Classroom(const std::string& name) + :name_m(name) + {} + + void add_student(const Student& student) + { + students_m.push_back(student); + } + + void load_file(const std::string& filename) + { + std::ifstream fin(filename); + + std::string first, last; + float avg; + + while (fin >> first) + { + fin >> last >> avg; + add_student(Student(first, last, avg)); + } + } + + void print() + { + std::cout << name_m << std::endl; + for (Student& student : students_m) + { + student.print(); + } + std::cout << std::endl; + } +}; + +float avg(std::vector& notes); + +int main(int argc, char * argv[]) +{ + int x; + int y; + std::vector bulletin_student1; + bulletin_student1.push_back(15.5f); + bulletin_student1.push_back(14.5f); + Student student_1("Liam", "Neeson", avg(bulletin_student1)); + Classroom maths("Maths"); + maths.add_student(student_1); + maths.print(); + + maths.load_file("Students.txt"); + maths.print(); + return 0; + +} + +float avg(std::vector& notes) +{ + float sum = 0.0f; + for (float& note : notes) + { + sum += note; + } + return sum / notes.size(); +} \ No newline at end of file diff --git a/City.cpp b/City.cpp new file mode 100644 index 0000000..17352b5 --- /dev/null +++ b/City.cpp @@ -0,0 +1,14 @@ +#include "City.h" + +City::City() : name_m("C_default") {} + +City::City(const std::string& name) : name_m(name) {} + +std::string City::getName() const { + return name_m; +} + +void City::printCity() const +{ + std::cout << name_m << std::endl; +} \ No newline at end of file diff --git a/City.h b/City.h new file mode 100644 index 0000000..3c0dcab --- /dev/null +++ b/City.h @@ -0,0 +1,23 @@ +#ifndef CITY_H +#define CITY_H + +#include +#include + +class City { +private: + std::string name_m; + +public: + // Constructors + City(); + City(const std::string& name); + + // Getters + std::string getName() const; + + // Others + void printCity() const; +}; + +#endif // CITY_H diff --git a/Decoration.cpp b/Decoration.cpp new file mode 100644 index 0000000..45fd1e7 --- /dev/null +++ b/Decoration.cpp @@ -0,0 +1,14 @@ +#include "Decoration.h" + +Decoration::Decoration() : name_m("C_default") {} + +Decoration::Decoration(const std::string& name) : name_m(name) {} + +std::string Decoration::getName() const { + return name_m; +} + +void Decoration::printDecoration() const +{ + std::cout << name_m << std::endl; +} \ No newline at end of file diff --git a/Decoration.h b/Decoration.h new file mode 100644 index 0000000..93c01f4 --- /dev/null +++ b/Decoration.h @@ -0,0 +1,23 @@ +#ifndef DECORATION_H +#define DECORATION_H + +#include +#include + +class Decoration { +private: + std::string name_m; + +public: + // Constructors + Decoration(); + Decoration(const std::string& name); + + // Getters + std::string getName() const; + + // Others + void printDecoration() const; +}; + +#endif // CITY_H \ No newline at end of file diff --git a/Hexagon.cpp b/Hexagon.cpp new file mode 100644 index 0000000..0fc0027 --- /dev/null +++ b/Hexagon.cpp @@ -0,0 +1,263 @@ +#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; +} \ No newline at end of file diff --git a/Hexagon.h b/Hexagon.h new file mode 100644 index 0000000..0e87513 --- /dev/null +++ b/Hexagon.h @@ -0,0 +1,60 @@ +#ifndef HEXAGON_H +#define HEXAGON_H + +#include + +#include "City.h" +#include "Ressource.h" +#include "Decoration.h" + +class Hexagon { +private: + Hexagon* top_m; + Hexagon* top_right_m; + Hexagon* top_left_m; + Hexagon* bottom_right_m; + Hexagon* bottom_left_m; + Hexagon* bottom_m; + City city_m; + Ressource ressource_m; + Decoration decoration_m; + +public: + // Constructors + Hexagon(); + Hexagon(const City& city); + Hexagon(const Ressource& ressource); + Hexagon(const Decoration& decoration); + + // Getters + Hexagon* getTop() const; + Hexagon* getTopRight() const; + Hexagon* getTopLeft() const; + Hexagon* getBottomRight() const; + Hexagon* getBottomLeft() const; + Hexagon* getBottom() const; + City getCity() const; + Ressource getRessource() const; + + // Setters + void setTop(Hexagon* top); + void setTopRight(Hexagon* top_right); + void setTopLeft(Hexagon* top_left); + void setBottomRight(Hexagon* bottom_right); + void setBottomLeft(Hexagon* bottom_left); + void setBottom(Hexagon* bottom); + void setCity(City city); + void setRessource(Ressource ressource); + + // Others + void printHexagon() const; + void printTopLeft() const; + void printTop() const; + void printTopRight() const; + void printBottomRight() const; + void printBottom() const; + void printBottomLeft() const; + void printAll() const; +}; + +#endif // HEXAGON_H diff --git a/Ressource.cpp b/Ressource.cpp new file mode 100644 index 0000000..10c15c5 --- /dev/null +++ b/Ressource.cpp @@ -0,0 +1,20 @@ +#include "Ressource.h" + +Ressource::Ressource() : name_m("R_default"), pph_m(0) {} + +Ressource::Ressource(const std::string& name, int value) : name_m(name), pph_m(value) {} + +std::string Ressource::getName() const +{ + return name_m; +} + +int Ressource::getValue() const +{ + return pph_m; +} + +void Ressource::printRessource() const +{ + std::cout << name_m << " : " << pph_m << std::endl; +} \ No newline at end of file diff --git a/Ressource.h b/Ressource.h new file mode 100644 index 0000000..0c3222e --- /dev/null +++ b/Ressource.h @@ -0,0 +1,28 @@ +#ifndef RESSOURCE_H +#define RESSOURCE_H + +#include +#include + +class Ressource { +private: + std::string name_m; + int pph_m; + +public: + // Constructors + Ressource(); + Ressource(const std::string& name, int value); + + // Getters + std::string getName() const; + int getValue() const; + + // Print function + void printRessource() const; +}; + +// Operator overload for printing Ressource +std::ostream& operator<<(std::ostream& os, const Ressource& ressource); + +#endif // RESSOURCE_H diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..f844804 --- /dev/null +++ b/main.cpp @@ -0,0 +1,63 @@ +#include +#include + +#include "Ressource.h" +#include "City.h" +#include "Decoration.h" +#include "Hexagon.h" + +int main(int argc, char* argv[]) { + // Init all resources + std::vector woods; + std::vector stones; + std::vector irons; + std::vector wheats; + std::vector ressources_q = {10, 20, 50, 100, 150}; + + for (int i : ressources_q) { + woods.emplace_back("Wood", i); + stones.emplace_back("Stone", i); + irons.emplace_back("Iron", i); + wheats.emplace_back("Wheat", i); + } + + City khamuls_tower_c("Khamûl's Tower"); + City bazylan_c("Bazylan"); + City mordor_c("Mordor"); + + Decoration angmar_banner("Angmar's Banner"); + + Hexagon hexagon_0_1(wheats[1]); + Hexagon hexagon_0_3(irons[2]); + + Hexagon hexagon_1_0(bazylan_c); + Hexagon hexagon_1_2(khamuls_tower_c); + Hexagon hexagon_1_4(wheats[0]); + + Hexagon hexagon_2_1(angmar_banner); + Hexagon hexagon_2_3(stones[0]); + Hexagon hexagon_2_5(mordor_c); + + hexagon_1_0.setBottomRight(&hexagon_2_1); + hexagon_1_0.setBottomLeft(&hexagon_0_1); + + hexagon_1_2.setTop(&hexagon_1_0); + hexagon_1_2.setBottomRight(&hexagon_2_3); + hexagon_1_2.setBottomLeft(&hexagon_0_3); + + hexagon_1_4.setTop(&hexagon_1_2); + hexagon_1_4.setBottomRight(&hexagon_2_5); + + + + hexagon_0_1.printAll(); + hexagon_0_3.printAll(); + hexagon_1_0.printAll(); + hexagon_1_2.printAll(); + hexagon_1_4.printAll(); + hexagon_2_1.printAll(); + hexagon_2_3.printAll(); + hexagon_2_5.printAll(); + + return 0; +} diff --git a/makefile b/makefile new file mode 100644 index 0000000..5455509 --- /dev/null +++ b/makefile @@ -0,0 +1,8 @@ +all: + + +main_hexagon: + + g++ main.cpp Ressource.cpp City.cpp Decoration.cpp Hexagon.cpp -o main + ./main + rm main \ No newline at end of file