diff --git a/includes/Ecran.hpp b/includes/Ecran.hpp index 8df1905..15f82b5 100644 --- a/includes/Ecran.hpp +++ b/includes/Ecran.hpp @@ -3,11 +3,10 @@ #include #include -class Ecran { +struct Ecran { // Fenêtre - sf::RenderWindow window; + static sf::RenderWindow window; -public: Ecran(const uint width = 800, const uint height = 800, const std::string name = "Projet"); // constructor ~Ecran(); // destructor diff --git a/includes/Plateau.hpp b/includes/Plateau.hpp index a3dfa75..428769a 100644 --- a/includes/Plateau.hpp +++ b/includes/Plateau.hpp @@ -15,16 +15,13 @@ public: Plateau(int taille); // constructor virtual ~Plateau(); // destructor - Plateau(const Plateau &); // copy constructor - const Plateau &operator=(const Plateau &); // copy assignement - // Fonction pour initialiser le plateau (selon le jeu) // Seulement deux joueurs pour le jeu de dame uniquement, je suis pas sûre de // comment initialiser la fonction autrement virtual void initialiserPlateau(Joueur &j1, Joueur &j2); // Fonction pour afficher le plateau (selon le jeu) - void afficherPlateau(); + void afficherPlateau(const bool debug = false); // Fonction pour modifier le plateau void modifierPlateau(int x, int y, Piece *piece); diff --git a/src/Ecran.cpp b/src/Ecran.cpp index 67806b9..61ccc83 100644 --- a/src/Ecran.cpp +++ b/src/Ecran.cpp @@ -1,5 +1,7 @@ #include "../includes/Ecran.hpp" +sf::RenderWindow Ecran::window; + Ecran::Ecran(const uint w, const uint h, const std::string n) { // Création de la fenêtre SFML window.create(sf::VideoMode(w, h), n); diff --git a/src/Plateau.cpp b/src/Plateau.cpp index d658ea8..f1eb9e6 100644 --- a/src/Plateau.cpp +++ b/src/Plateau.cpp @@ -1,7 +1,8 @@ #include "../includes/Plateau.hpp" +#include "../includes/Ecran.hpp" #include "../includes/PieceDames.hpp" -Plateau::Plateau(int t) { +Plateau::Plateau(int t) : taille(t) { // Création du plateau vide plateau = new Piece **[t]; for (int i = 0; i < t; i++) { @@ -19,16 +20,6 @@ Plateau::~Plateau() { delete[] plateau; } -Plateau::Plateau(const Plateau &) {} - -const Plateau &Plateau::operator=(const Plateau &src) { - if (this == &src) { - return *this; - } - - return *this; -} - void Plateau::initialiserPlateau(Joueur &j1, Joueur &j2) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 10; j++) { @@ -49,7 +40,47 @@ void Plateau::initialiserPlateau(Joueur &j1, Joueur &j2) { } } -void Plateau::afficherPlateau() {} +void Plateau::afficherPlateau(const bool d) { + float taille_cellule = static_cast(Ecran::window.getSize().x) / taille; + + // Cellule + sf::RectangleShape cell(sf::Vector2f(taille_cellule, taille_cellule)); + + for (int i = 0; i < taille; i++) { + for (int j = 0; j < taille; j++) { + float x = i * taille_cellule; + float y = j * taille_cellule; + + // Position de la cellule + cell.setPosition(x, y); + if (d) { + std::cout << "(" << x << ", " << y; + } + + // Alternation des couleurs + if ((i + j) % 2 == 0) { + cell.setFillColor(sf::Color::White); + if (d) { + std::cout << ", B), "; + } + } else { + cell.setFillColor(sf::Color::Black); + if (d) { + std::cout << ", N), "; + } + } + + // Dessine la cellule + Ecran::window.draw(cell); + } + if (d) { + std::cout << "\n"; + } + } + if (d) { + std::cout << "---\n"; + } +} void Plateau::modifierPlateau(int x, int y, Piece *piece) { if (x >= 0 && x < taille && y >= 0 && y < taille) { diff --git a/src/main.cpp b/src/main.cpp index f47c1bb..1da3353 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,10 @@ #include "../includes/Ecran.hpp" +#include "../includes/Plateau.hpp" int main() { + Plateau p(10); Ecran e; - e.afficher(); + e.afficher(std::bind(&Plateau::afficherPlateau, &p, true)); return 0; }