Hexagon kakadoigt

This commit is contained in:
CaNaRdEoS 2024-06-26 15:17:53 +02:00
commit 955e65bf0b
11 changed files with 616 additions and 0 deletions

100
Basics1.cpp Normal file
View File

@ -0,0 +1,100 @@
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
//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<Student> 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<float>& notes);
int main(int argc, char * argv[])
{
int x;
int y;
std::vector<float> 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<float>& notes)
{
float sum = 0.0f;
for (float& note : notes)
{
sum += note;
}
return sum / notes.size();
}

14
City.cpp Normal file
View File

@ -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;
}

23
City.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef CITY_H
#define CITY_H
#include<iostream>
#include <string>
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

14
Decoration.cpp Normal file
View File

@ -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;
}

23
Decoration.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef DECORATION_H
#define DECORATION_H
#include<iostream>
#include <string>
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

263
Hexagon.cpp Normal file
View File

@ -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;
}

60
Hexagon.h Normal file
View File

@ -0,0 +1,60 @@
#ifndef HEXAGON_H
#define HEXAGON_H
#include<iostream>
#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

20
Ressource.cpp Normal file
View File

@ -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;
}

28
Ressource.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef RESSOURCE_H
#define RESSOURCE_H
#include <string>
#include <iostream>
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

63
main.cpp Normal file
View File

@ -0,0 +1,63 @@
#include <iostream>
#include <vector>
#include "Ressource.h"
#include "City.h"
#include "Decoration.h"
#include "Hexagon.h"
int main(int argc, char* argv[]) {
// Init all resources
std::vector<Ressource> woods;
std::vector<Ressource> stones;
std::vector<Ressource> irons;
std::vector<Ressource> wheats;
std::vector<int> 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;
}

8
makefile Normal file
View File

@ -0,0 +1,8 @@
all:
main_hexagon:
g++ main.cpp Ressource.cpp City.cpp Decoration.cpp Hexagon.cpp -o main
./main
rm main