fact
This commit is contained in:
parent
49fe932bae
commit
c2e4c8f968
2 changed files with 12 additions and 20 deletions
|
@ -25,7 +25,7 @@ class Dames : private Jeu {
|
||||||
|
|
||||||
// Permet de transformer une Piece en PieceDames
|
// Permet de transformer une Piece en PieceDames
|
||||||
const PieceDames *getPiece(const int x, const int y) const;
|
const PieceDames *getPiece(const int x, const int y) const;
|
||||||
PieceDames *getPiece(Piece *) const;
|
const PieceDames *getPiece(Piece *) const;
|
||||||
|
|
||||||
// Message à chaque tour du joueur
|
// Message à chaque tour du joueur
|
||||||
const std::string msgTonTour() const;
|
const std::string msgTonTour() const;
|
||||||
|
|
|
@ -30,8 +30,8 @@ const PieceDames *Dames::getPiece(const int x, const int y) const {
|
||||||
return dynamic_cast<const PieceDames *>(plateau.getPiece(x, y));
|
return dynamic_cast<const PieceDames *>(plateau.getPiece(x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
PieceDames *Dames::getPiece(Piece *piece) const {
|
const PieceDames *Dames::getPiece(Piece *piece) const {
|
||||||
return dynamic_cast<PieceDames *>(piece);
|
return dynamic_cast<const PieceDames *>(piece);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string Dames::msgTonTour() const {
|
const std::string Dames::msgTonTour() const {
|
||||||
|
@ -122,71 +122,63 @@ bool Dames::prisePossible(Joueur &joueur) const {
|
||||||
const std::vector<Piece *> &pieces = joueur.getPieces();
|
const std::vector<Piece *> &pieces = joueur.getPieces();
|
||||||
const PieceDames *pieceAPrendre;
|
const PieceDames *pieceAPrendre;
|
||||||
for (uint i = 0; i < pieces.size(); i++) {
|
for (uint i = 0; i < pieces.size(); i++) {
|
||||||
const PieceDames *p = dynamic_cast<const PieceDames *>(pieces[i]);
|
const PieceDames *p = getPiece(pieces[i]);
|
||||||
const Position pos = p->getPos();
|
const Position pos = p->getPos();
|
||||||
if (!p) {
|
if (!p) {
|
||||||
throw std::runtime_error("Cette pièce est.. étrange.");
|
throw std::runtime_error("Cette pièce est.. étrange.");
|
||||||
}
|
}
|
||||||
// On regarde si une prise est possible pour chaque coté de la piece
|
// On regarde si une prise est possible pour chaque coté de la piece
|
||||||
if (pos.first > 1) {
|
if (pos.first > 1) {
|
||||||
pieceAPrendre = dynamic_cast<const PieceDames *>(
|
pieceAPrendre = getPiece(plateau.getPiece(pos.first - 1, pos.second));
|
||||||
plateau.getPiece(pos.first - 1, pos.second));
|
|
||||||
if (pieceAPrendre != nullptr &&
|
if (pieceAPrendre != nullptr &&
|
||||||
pieceAPrendre->getCategory() != p->getCategory()) {
|
pieceAPrendre->getCategory() != p->getCategory()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pos.first > 1 && pos.second > 1) {
|
if (pos.first > 1 && pos.second > 1) {
|
||||||
pieceAPrendre = dynamic_cast<const PieceDames *>(
|
pieceAPrendre = getPiece(plateau.getPiece(pos.first - 1, pos.second - 1));
|
||||||
plateau.getPiece(pos.first - 1, pos.second - 1));
|
|
||||||
if (pieceAPrendre != nullptr &&
|
if (pieceAPrendre != nullptr &&
|
||||||
pieceAPrendre->getCategory() != p->getCategory()) {
|
pieceAPrendre->getCategory() != p->getCategory()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pos.first > 1 && pos.second < 8) {
|
if (pos.first > 1 && pos.second < 8) {
|
||||||
pieceAPrendre = dynamic_cast<const PieceDames *>(
|
pieceAPrendre = getPiece(plateau.getPiece(pos.first - 1, pos.second + 1));
|
||||||
plateau.getPiece(pos.first - 1, pos.second + 1));
|
|
||||||
if (pieceAPrendre != nullptr &&
|
if (pieceAPrendre != nullptr &&
|
||||||
pieceAPrendre->getCategory() != p->getCategory()) {
|
pieceAPrendre->getCategory() != p->getCategory()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pos.second > 1) {
|
if (pos.second > 1) {
|
||||||
pieceAPrendre = dynamic_cast<const PieceDames *>(
|
pieceAPrendre = getPiece(plateau.getPiece(pos.first, pos.second - 1));
|
||||||
plateau.getPiece(pos.first, pos.second - 1));
|
|
||||||
if (pieceAPrendre != nullptr &&
|
if (pieceAPrendre != nullptr &&
|
||||||
pieceAPrendre->getCategory() != p->getCategory()) {
|
pieceAPrendre->getCategory() != p->getCategory()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pos.second < 8) {
|
if (pos.second < 8) {
|
||||||
pieceAPrendre = dynamic_cast<const PieceDames *>(
|
pieceAPrendre = getPiece(plateau.getPiece(pos.first, pos.second + 1));
|
||||||
plateau.getPiece(pos.first, pos.second + 1));
|
|
||||||
if (pieceAPrendre != nullptr &&
|
if (pieceAPrendre != nullptr &&
|
||||||
pieceAPrendre->getCategory() != p->getCategory()) {
|
pieceAPrendre->getCategory() != p->getCategory()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pos.first < 8 && pos.second > 1) {
|
if (pos.first < 8 && pos.second > 1) {
|
||||||
pieceAPrendre = dynamic_cast<const PieceDames *>(
|
pieceAPrendre = getPiece(plateau.getPiece(pos.first + 1, pos.second - 1));
|
||||||
plateau.getPiece(pos.first + 1, pos.second - 1));
|
|
||||||
if (pieceAPrendre != nullptr &&
|
if (pieceAPrendre != nullptr &&
|
||||||
pieceAPrendre->getCategory() != p->getCategory()) {
|
pieceAPrendre->getCategory() != p->getCategory()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pos.first < 8 && pos.second < 8) {
|
if (pos.first < 8 && pos.second < 8) {
|
||||||
pieceAPrendre = dynamic_cast<const PieceDames *>(
|
pieceAPrendre = getPiece(plateau.getPiece(pos.first + 1, pos.second + 1));
|
||||||
plateau.getPiece(pos.first + 1, pos.second + 1));
|
|
||||||
if (pieceAPrendre != nullptr &&
|
if (pieceAPrendre != nullptr &&
|
||||||
pieceAPrendre->getCategory() != p->getCategory()) {
|
pieceAPrendre->getCategory() != p->getCategory()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pos.first < 8) {
|
if (pos.first < 8) {
|
||||||
pieceAPrendre = dynamic_cast<const PieceDames *>(
|
pieceAPrendre = getPiece(plateau.getPiece(pos.first + 1, pos.second));
|
||||||
plateau.getPiece(pos.first + 1, pos.second));
|
|
||||||
if (pieceAPrendre != nullptr &&
|
if (pieceAPrendre != nullptr &&
|
||||||
pieceAPrendre->getCategory() != p->getCategory()) {
|
pieceAPrendre->getCategory() != p->getCategory()) {
|
||||||
return true;
|
return true;
|
||||||
|
|
Reference in a new issue