diff options
sem 16
7 files changed, 17 insertions, 24 deletions
| -rw-r--r-- | Sem. 15/Chess/Figures/Bishop/Bishop.cpp | 2 | ||||
| -rw-r--r-- | Sem. 15/Chess/Figures/FigureBase/Figure.h | 6 | ||||
| -rw-r--r-- | Sem. 15/Chess/Figures/King/King.cpp | 2 | ||||
| -rw-r--r-- | Sem. 15/Chess/Figures/Knight/Knight.cpp | 2 | ||||
| -rw-r--r-- | Sem. 15/Chess/Figures/Pawn/Pawn.cpp | 25 | ||||
| -rw-r--r-- | Sem. 15/Chess/Figures/Queen/Queen.cpp | 2 | ||||
| -rw-r--r-- | Sem. 15/Chess/Figures/Rook/Rook.cpp | 2 |
diff --git a/Sem. 15/Chess/Figures/Bishop/Bishop.cpp b/Sem. 15/Chess/Figures/Bishop/Bishop.cpp index 80121e2..786c9eb 100644 --- a/Sem. 15/Chess/Figures/Bishop/Bishop.cpp +++ b/Sem. 15/Chess/Figures/Bishop/Bishop.cpp @@ -1,7 +1,7 @@ #include "Bishop.h" #include <cmath> -Bishop::Bishop(bool isWhite) : Figure(isWhite) +Bishop::Bishop(bool isWhite) : Figure(isWhite, RookFigure) {} bool Bishop::canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const { diff --git a/Sem. 15/Chess/Figures/FigureBase/Figure.h b/Sem. 15/Chess/Figures/FigureBase/Figure.h index c0a84a5..3e0bc07 100644 --- a/Sem. 15/Chess/Figures/FigureBase/Figure.h +++ b/Sem. 15/Chess/Figures/FigureBase/Figure.h @@ -1,16 +1,20 @@ #pragma once #include <iostream> +#include "../../ConfigEnums/ConfigEnums.h" class Figure { bool isWhite; + FigureType type; + public: - Figure(bool isWhite) :isWhite(isWhite) + Figure(bool isWhite, FigureType type) :isWhite(isWhite), type(type) {} virtual bool canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const = 0; virtual void print() const = 0; bool getIsWhite() const { return isWhite; }; + FigureType getType() const { return type; } virtual ~Figure(){}; };
\ No newline at end of file diff --git a/Sem. 15/Chess/Figures/King/King.cpp b/Sem. 15/Chess/Figures/King/King.cpp index 9d323f3..8ca67e8 100644 --- a/Sem. 15/Chess/Figures/King/King.cpp +++ b/Sem. 15/Chess/Figures/King/King.cpp @@ -1,7 +1,7 @@ #include "King.h" #include <cmath> -King::King(bool isWhite) : Figure(isWhite) +King::King(bool isWhite) : Figure(isWhite, KingFigure) {} bool King::canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const { diff --git a/Sem. 15/Chess/Figures/Knight/Knight.cpp b/Sem. 15/Chess/Figures/Knight/Knight.cpp index e6db119..5713d7c 100644 --- a/Sem. 15/Chess/Figures/Knight/Knight.cpp +++ b/Sem. 15/Chess/Figures/Knight/Knight.cpp @@ -1,7 +1,7 @@ #include "Knight.h" #include <cmath> -Knight::Knight(bool isWhite) : Figure(isWhite) +Knight::Knight(bool isWhite) : Figure(isWhite, KnightFigure) {} bool Knight::canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const { diff --git a/Sem. 15/Chess/Figures/Pawn/Pawn.cpp b/Sem. 15/Chess/Figures/Pawn/Pawn.cpp index fd04dad..347032b 100644 --- a/Sem. 15/Chess/Figures/Pawn/Pawn.cpp +++ b/Sem. 15/Chess/Figures/Pawn/Pawn.cpp @@ -1,27 +1,16 @@ #include "Pawn.h" #include <cmath> -Pawn::Pawn(bool isWhite) : Figure(isWhite), isFirstMove(true) +Pawn::Pawn(bool isWhite) : Figure(isWhite, PawnFigure), isFirstMove(true) {} + bool Pawn::canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const { - /*if (currentX != destX) - return false; - - int diff = destY - currentY; - - if (abs(diff) > 2) - return false; - - if (diff < 0 && getIsWhite() || diff > 0 && !getIsWhite()) - return false; - - if (!abs(diff) == 2 || isFirstMove) - { - return true; - } - return false;*/ - return false; + if (getIsWhite()) + return currentY - 1 == destY && abs((int)currentX - (int)destX) <= 1; + else + return currentY + 1 == destY && abs((int)currentX - (int)destX) <= 1; } + void Pawn::print() const { if (getIsWhite()) diff --git a/Sem. 15/Chess/Figures/Queen/Queen.cpp b/Sem. 15/Chess/Figures/Queen/Queen.cpp index da49c1c..0e33198 100644 --- a/Sem. 15/Chess/Figures/Queen/Queen.cpp +++ b/Sem. 15/Chess/Figures/Queen/Queen.cpp @@ -1,6 +1,6 @@ #include "Queen.h" -Queen::Queen(bool isWhite) : Bishop(isWhite), Rook(isWhite), Figure(isWhite) +Queen::Queen(bool isWhite) : Bishop(isWhite), Rook(isWhite), Figure(isWhite, QueenFigure) {} bool Queen::canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const diff --git a/Sem. 15/Chess/Figures/Rook/Rook.cpp b/Sem. 15/Chess/Figures/Rook/Rook.cpp index 19e84a6..2cb96a3 100644 --- a/Sem. 15/Chess/Figures/Rook/Rook.cpp +++ b/Sem. 15/Chess/Figures/Rook/Rook.cpp @@ -1,6 +1,6 @@ #include "Rook.h" -Rook::Rook(bool isWhite) : Figure(isWhite) +Rook::Rook(bool isWhite) : Figure(isWhite, RookFigure) {} bool Rook::canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const { |
