forked from Wenfei134/chess
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSquare.cpp
49 lines (41 loc) · 1.47 KB
/
Square.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "Square.hpp"
#include "Pieces/Piece.hpp"
// --------------------------------------------------------------------------------------------------------------------
Square::Square(int row, int col) : ROW{row}, COL{col}, mPiece{nullptr} {}
// --------------------------------------------------------------------------------------------------------------------
void Square::Place(std::shared_ptr<Piece> &pc)
{
Empty();
mPiece = pc;
mPiece->SetPosition(this);
}
// --------------------------------------------------------------------------------------------------------------------
void Square::Empty()
{
if (!IsEmpty())
{
mPiece->SetPosition(nullptr);
mPiece = nullptr;
}
}
// --------------------------------------------------------------------------------------------------------------------
bool Square::IsEmpty()
{
return mPiece == nullptr;
}
// --------------------------------------------------------------------------------------------------------------------
std::shared_ptr<Piece> Square::GetPiece()
{
return mPiece;
}
// --------------------------------------------------------------------------------------------------------------------
int Square::GetRow()
{
return ROW;
}
// --------------------------------------------------------------------------------------------------------------------
int Square::GetCol()
{
return COL;
}
// --------------------------------------------------------------------------------------------------------------------