Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 15 / Chess / ChessBoard
diff options
context:
space:
mode:
Commit50444e86ea5048e05b8eb74055e0f7c4d2c5d7b7 (patch)
Author
 angeld55 <angel_dimitriev@abv.bg>
2021-06-10 18:54:25 +0300
Committer
 angeld55 <angel_dimitriev@abv.bg>
2021-06-10 18:54:25 +0300
Files098cf947bc45b4b747d3da5259fc8044c5724d8b /Sem. 15/Chess/ChessBoard
Object-oriented_programming_FMI-50444e86ea5048e05b8eb74055e0f7c4d2c5d7b7.tar
Object-oriented_programming_FMI-50444e86ea5048e05b8eb74055e0f7c4d2c5d7b7.tar.gz
Object-oriented_programming_FMI-50444e86ea5048e05b8eb74055e0f7c4d2c5d7b7.zip
Parentd1e6ffd0fef9ebc7a8baae5e0b75b468ad8ed11a (diff)
sem 15
2 files changed, 86 insertions, 0 deletions
-rw-r--r--Sem. 15/Chess/ChessBoard/ChessBoard.cpp46
-rw-r--r--Sem. 15/Chess/ChessBoard/ChessBoard.h40
diff --git a/Sem. 15/Chess/ChessBoard/ChessBoard.cpp b/Sem. 15/Chess/ChessBoard/ChessBoard.cpp
new file mode 100644
index 0000000..dc809cc
--- /dev/null
+++ b/Sem. 15/Chess/ChessBoard/ChessBoard.cpp
@@ -0,0 +1,46 @@
+#include "ChessBoard.h"
+#include "../FigureFactory/FigureFactory.h"
+
+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[0][0].f = factory.createRook(false);
+ board[0][7].f = factory.createRook(false);
+
+ board[7][0].f = factory.createRook(true);
+ board[7][7].f = factory.createRook(true);
+
+
+ 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][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][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);
+}
+
+void ChessBoard::print() const
+{
+ for (int i = 0; i < BOARD_SIZE; i++)
+ {
+ for (int j = 0; j < BOARD_SIZE; j++)
+ {
+ board[i][j].print();
+ }
+ std::cout << std::endl;
+ }
+} \ No newline at end of file
diff --git a/Sem. 15/Chess/ChessBoard/ChessBoard.h b/Sem. 15/Chess/ChessBoard/ChessBoard.h
new file mode 100644
index 0000000..1825119
--- /dev/null
+++ b/Sem. 15/Chess/ChessBoard/ChessBoard.h
@@ -0,0 +1,40 @@
+#pragma once
+#include "../Figures/FigureBase/Figure.h"
+
+const size_t BOARD_SIZE = 8;
+class ChessBoard
+{
+ struct Cell
+ {
+ Figure* f = nullptr;
+ Cell() = default;
+
+ Cell(const Cell& other) = delete;
+ Cell& operator=(const Cell& other) = delete;
+ bool isEmpty()
+ {
+ return f == nullptr;
+ }
+
+ void print() const
+ {
+ if (f != nullptr)
+ f->print();
+ else
+ std::cout << ' ';
+ }
+
+ ~Cell()
+ {
+ delete f;
+ }
+ };
+ Cell board[BOARD_SIZE][BOARD_SIZE];
+
+public:
+ ChessBoard();
+ ChessBoard(const ChessBoard& other) = delete;
+ ChessBoard& operator=(const ChessBoard&) = delete;
+
+ void print() const;
+}; \ No newline at end of file