2023-11-12 16:05:42 +01:00
|
|
|
#include "../includes/Plateau.hpp"
|
2023-12-01 16:36:50 +01:00
|
|
|
#include "../includes/Ecran.hpp"
|
2023-12-01 15:26:34 +01:00
|
|
|
#include "../includes/PieceDames.hpp"
|
2023-11-26 17:53:37 +01:00
|
|
|
|
2023-12-01 20:22:56 +01:00
|
|
|
Plateau::Plateau(int t) : taille(t), plateau(new Piece **[t]) {
|
2023-11-24 20:34:22 +01:00
|
|
|
// Création du plateau vide
|
2023-11-21 18:07:13 +01:00
|
|
|
for (int i = 0; i < t; i++) {
|
|
|
|
plateau[i] = new Piece *[t];
|
|
|
|
for (int j = 0; j < t; j++) {
|
2023-11-21 12:33:04 +01:00
|
|
|
plateau[i][j] = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-12 16:05:42 +01:00
|
|
|
|
2023-11-24 20:34:22 +01:00
|
|
|
Plateau::~Plateau() {
|
|
|
|
for (int i = 0; i < taille; i++) {
|
|
|
|
delete[] plateau[i];
|
|
|
|
}
|
|
|
|
delete[] plateau;
|
|
|
|
}
|
2023-11-12 16:05:42 +01:00
|
|
|
|
2023-11-26 17:53:37 +01:00
|
|
|
void Plateau::initialiserPlateau(Joueur &j1, Joueur &j2) {
|
2023-12-01 15:06:20 +01:00
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
for (int j = 0; j < 10; j++) {
|
|
|
|
if ((i % 2 == 0 && j % 2 == 1) || (i % 2 == 1 && j % 2 == 0)) {
|
2023-12-01 12:32:45 +01:00
|
|
|
plateau[i][j] = new PieceDames("noire");
|
|
|
|
j1.ajoutPiece(plateau[i][j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-12-01 15:26:34 +01:00
|
|
|
|
2023-12-01 15:06:20 +01:00
|
|
|
for (int i = 6; i < 10; i++) {
|
|
|
|
for (int j = 0; j < 10; j++) {
|
|
|
|
if ((i % 2 == 0 && j % 2 == 1) || (i % 2 == 1 && j % 2 == 0)) {
|
2023-12-01 12:32:45 +01:00
|
|
|
plateau[i][j] = new PieceDames("blanche");
|
|
|
|
j2.ajoutPiece(plateau[i][j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-26 17:53:37 +01:00
|
|
|
}
|
2023-11-24 20:14:05 +01:00
|
|
|
|
2023-12-01 16:36:50 +01:00
|
|
|
void Plateau::afficherPlateau(const bool d) {
|
2023-12-01 20:22:56 +01:00
|
|
|
const float tailleCellule =
|
|
|
|
static_cast<float>(Ecran::window.getSize().x) / taille;
|
2023-12-01 16:36:50 +01:00
|
|
|
|
2023-12-01 20:21:54 +01:00
|
|
|
// Adapte la vue pour le redimensionnement
|
|
|
|
const float tailleFenetre = taille * tailleCellule;
|
|
|
|
Ecran::window.setView(
|
|
|
|
sf::View(sf::FloatRect(0, 0, tailleFenetre, tailleFenetre)));
|
2023-12-01 16:36:50 +01:00
|
|
|
|
2023-12-01 20:21:54 +01:00
|
|
|
// Cellule
|
|
|
|
sf::RectangleShape cell(sf::Vector2f(tailleCellule, tailleCellule));
|
2023-12-01 16:36:50 +01:00
|
|
|
for (int i = 0; i < taille; i++) {
|
|
|
|
for (int j = 0; j < taille; j++) {
|
2023-12-01 20:22:56 +01:00
|
|
|
const float x = i * tailleCellule;
|
|
|
|
const float y = j * tailleCellule;
|
2023-12-01 16:36:50 +01:00
|
|
|
|
|
|
|
// 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";
|
|
|
|
}
|
|
|
|
}
|
2023-11-24 20:14:05 +01:00
|
|
|
|
|
|
|
void Plateau::modifierPlateau(int x, int y, Piece *piece) {
|
|
|
|
if (x >= 0 && x < taille && y >= 0 && y < taille) {
|
|
|
|
plateau[x][y] = piece;
|
|
|
|
} else {
|
|
|
|
throw std::invalid_argument("Coordonnées invalides");
|
|
|
|
}
|
|
|
|
}
|