Website Summary Files Commits Branches @commit @diff @stats
path: root / DiamondProblemAndPolymorphism / Chess / Knight.hpp
blob: eb2ee9fd5f5ddd25f5ce796ce5ede7d6368d6658 (plain) (blame)
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
#include "Figure.hpp"

class Knight : public Figure
{
public:
	Knight(int xCoordinate, int yCoordinate, bool isWhite) :Figure(xCoordinate, yCoordinate, isWhite)
	{}
	
	bool Move(int xNew, int yNew);
	
	void Print();
};
bool Knight::Move(int xNew, int yNew)
{
	if (!isValidCoord(xNew, yNew))
		return false;
	int possibleX[] = { 1, 1, -1, -1, 2, 2, -2, -2 };
	int possibleY[] = { 2, -2, 2, -2, 1, -1, 1, -1 };
	for (int i = 0; i < 8; ++i)
	{
		if (xNew == xCoord + possibleX[i]
			&& yNew == yCoord + possibleY[i])
		{
			xCoord = xNew;
			yCoord = yNew;
			return  true;
		}

	}
	return false;

}

void Knight::Print()
{
	cout << 'K';
}