-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKing.cpp
More file actions
36 lines (30 loc) · 696 Bytes
/
Copy pathKing.cpp
File metadata and controls
36 lines (30 loc) · 696 Bytes
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
/**
* Fichier contenant la classe King qui correspond au roi.
* \file King.cpp
* \author Erreur-404 et Mo-LK
* \date 19 avril 2022
* Cr�� le 8 avril 2022
*/
#include "King.hpp"
namespace model
{
int King::numberOfKings_ = 0;
King::King(int x, int y, const Color& color) :
AbsPiece(x, y, color, "King")
{
if (King::numberOfKings_ < 2)
King::numberOfKings_++;
else
throw TooManyKingsException("Two kings already exist");
}
King::~King()
{
King::numberOfKings_--;
}
bool King::isValidPieceMove(int x, int y) const
{
const bool isValidX = (x_ - 1 <= x) && (x <= x_ + 1);
const bool isValidY = (y_ - 1 <= y) && (y <= y_ + 1);
return isValidX && isValidY;
}
}