-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRook.cpp
More file actions
43 lines (37 loc) · 1 KB
/
Rook.cpp
File metadata and controls
43 lines (37 loc) · 1 KB
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
#include "Rook.h"
using sf::IntRect;
using sf::Texture;
Rook::Rook(int color, int type, int x, int y, sf::Texture& texture) : Piece(color, type, x, y) {
sprite.setTexture(texture);
if (color == 1) {
sprite.setTextureRect(IntRect(1351, 20, 300, 300));
}
else {
sprite.setTextureRect(IntRect(1351, 351, 300, 300));
}
sprite.scale(0.38, 0.38);
}
void Rook::move(int x, int y) {
if (isLegal(x, y)) {
this->updatePosition(x, y);
}
}
bool Rook::isLegal(int xf, int yf) {
//inital position(current position)
int xi = get<0>(this->currPosition);
int yi = get<1>(this->currPosition);
//difference between (currPos - nextPos)
int xDiff = abs(xf - xi);
int yDiff = abs(yf - yi);
if (xf <= 0 && xf > 8 || yf <= 0 && yf > 8) { //checking chessboard parameters
cout << "Illegal Move" << endl;
return false;
}
else if (xf == 0) {
return true;
}
else if (yf == 0) {
return true;
}
return false;
}