-
Notifications
You must be signed in to change notification settings - Fork 0
/
Knight.cpp
29 lines (26 loc) · 852 Bytes
/
Knight.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
#pragma once
#include "Chess.h"
#include"Piece.h"
#include <iostream>
#include <cmath>
using namespace std;
class Knight : public Piece
{
public:
Knight(bool c) : Piece(c, 2) // c indicates whether it is black or white while 2 indicate value of knight
{
PieceImage.setTextureRect(IntRect(ImageSize * 1, ExtractColor(color) * ImageSize, ImageSize, ImageSize));
}
virtual bool isValid(int xfrom, int yfrom, int xto, int yto, Piece* b[8][8])
{
// cout << "\nIN KINGHT" << b[yfrom][xfrom]->getColor();
if ((abs(xfrom - xto) == 2 && abs(yfrom - yto) == 1) || (abs(xfrom - xto) == 1 && abs(yfrom - yto) == 2) && Piece::isValid(xfrom, yfrom, xto, yto, b))
return true;
return false;
}
void Print(int x, int y)
{
PieceImage.setPosition(ImageSize*x, ImageSize*y);
cout << (color ? 'W' : 'B') << 'N';
}
};