Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 15 / Chess / ChessBoard
diff options
context:
space:
mode:
Commitd489848bab395aea447bf6fe462f7c4f603dee1a (patch)
Author
 angeld55 <angel_dimitriev@abv.bg>
2021-06-12 17:01:20 +0300
Committer
 angeld55 <angel_dimitriev@abv.bg>
2021-06-12 17:01:20 +0300
Files1bf68497f483098888dc1f94eadbf1d50894569a /Sem. 15/Chess/ChessBoard
Object-oriented_programming_FMI-d489848bab395aea447bf6fe462f7c4f603dee1a.tar
Object-oriented_programming_FMI-d489848bab395aea447bf6fe462f7c4f603dee1a.tar.gz
Object-oriented_programming_FMI-d489848bab395aea447bf6fe462f7c4f603dee1a.zip
Parentd060147c32ecebaecb31cf5a93aae75318dc7ca6 (diff)
sem 16
2 files changed, 41 insertions, 20 deletions
-rw-r--r--Sem. 15/Chess/ChessBoard/ChessBoard.cpp58
-rw-r--r--Sem. 15/Chess/ChessBoard/ChessBoard.h3
diff --git a/Sem. 15/Chess/ChessBoard/ChessBoard.cpp b/Sem. 15/Chess/ChessBoard/ChessBoard.cpp
index dc809cc..2c618bd 100644
--- a/Sem. 15/Chess/ChessBoard/ChessBoard.cpp
+++ b/Sem. 15/Chess/ChessBoard/ChessBoard.cpp
@@ -3,34 +3,34 @@
ChessBoard::ChessBoard()
{
- FigureFactory factory;
+
for (int i = 0; i < BOARD_SIZE; i++)
{
- board[1][i].f = factory.createPawn(false);
- board[6][i].f = factory.createPawn(true);
+ board[1][i].f = FigureFactory::createFigure(false, PawnFigure);
+ board[6][i].f = FigureFactory::createFigure(true, PawnFigure);
}
- board[0][0].f = factory.createRook(false);
- board[0][7].f = factory.createRook(false);
+ board[0][0].f = FigureFactory::createFigure(false, RookFigure);
+ board[0][7].f = FigureFactory::createFigure(false, RookFigure);
- board[7][0].f = factory.createRook(true);
- board[7][7].f = factory.createRook(true);
+ board[7][0].f = FigureFactory::createFigure(true, RookFigure);
+ board[7][7].f = FigureFactory::createFigure(true, RookFigure);
- board[0][1].f = factory.createKnight(false);
- board[0][6].f = factory.createKnight(false);
- board[7][1].f = factory.createKnight(true);
- board[7][6].f = factory.createKnight(true);
+ board[0][1].f = FigureFactory::createFigure(false, KnightFigure);
+ board[0][6].f = FigureFactory::createFigure(false, KnightFigure);
+ board[7][1].f = FigureFactory::createFigure(true, KnightFigure);;
+ board[7][6].f = FigureFactory::createFigure(true, KnightFigure);
- board[0][2].f = factory.createBishop(false);
- board[0][5].f = factory.createBishop(false);
- board[7][2].f = factory.createBishop(true);
- board[7][5].f = factory.createBishop(true);
+ board[0][2].f = FigureFactory::createFigure(false, BishopFigure);
+ board[0][5].f = FigureFactory::createFigure(false, BishopFigure);;
+ board[7][2].f = FigureFactory::createFigure(true, BishopFigure);
+ board[7][5].f = FigureFactory::createFigure(true, BishopFigure);
- board[0][3].f = factory.createKnig(false);
- board[0][4].f = factory.createQueen(false);
- board[7][4].f = factory.createQueen(true);
- board[7][3].f = factory.createKnig(true);
+ board[0][3].f = FigureFactory::createFigure(false, KingFigure);
+ board[0][4].f = FigureFactory::createFigure(false, QueenFigure);
+ board[7][4].f = FigureFactory::createFigure(true, QueenFigure);
+ board[7][3].f = FigureFactory::createFigure(true, KingFigure);
}
void ChessBoard::print() const
@@ -43,4 +43,24 @@ void ChessBoard::print() const
}
std::cout << std::endl;
}
+}
+
+void ChessBoard::move(size_t x, size_t y, size_t destX, size_t destY)
+{
+
+ Figure* current = board[x][y].f;
+
+ if (current->getType() == PawnFigure)
+ {
+ //Some logic.....
+ }
+ else
+ {
+ if (board[x][y].f && board[x][y].f->canBeMoved(x, y, destX, destY))
+ {
+ board[destX][destY].f = board[x][y].f;
+ board[x][y].f = nullptr;
+ }
+ }
+
} \ No newline at end of file
diff --git a/Sem. 15/Chess/ChessBoard/ChessBoard.h b/Sem. 15/Chess/ChessBoard/ChessBoard.h
index d2bf81f..e38acd5 100644
--- a/Sem. 15/Chess/ChessBoard/ChessBoard.h
+++ b/Sem. 15/Chess/ChessBoard/ChessBoard.h
@@ -37,6 +37,7 @@ public:
ChessBoard& operator=(const ChessBoard&) = delete;
void print() const;
+
+ void move(size_t x, size_t y, size_t destX, size_t destY);
- //TODO. Free memory?
};