-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRook.cpp
58 lines (54 loc) · 1.83 KB
/
Rook.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
50
51
52
53
54
55
56
57
58
#include "Rook.h"
#include "Game.h"
extern Game *game;
Rook::Rook(QString side,QGraphicsItem *parent):ChessPiece(side,parent) {
setImage();
}
void Rook::setImage() {
if(side == "WHITE")
setPixmap(QPixmap(":/res/Res/c_wr.png").scaled(60,60));
else
setPixmap(QPixmap(":/res/Res/c_br.png").scaled(60,60));
}
void Rook::moves() {
// Clear previous locations if any
location.clear();
// get the coordinates of current piece selected
int row = this->getCurrentBox()->rowLoc;
int col = this->getCurrentBox()->colLoc;
// Get the side/team of current piece
QString team = this->getSide();
// For Going Upward
for(int i = row-1,j = col; i >= 0 ; i--) {
// Check if it some box has our teams piece (Some piece is blocking the path)
if(game->ChessBoard[i][j]->getChessPieceColor() == team ) break;
else {
location.append(game->ChessBoard[i][j]);
if(boxSetting(location.last())) break;
}
}
//For Going Downward
for(int i = row+1,j = col; i <= 7 ; i++) {
if(game->ChessBoard[i][j]->getChessPieceColor() == team ) break;
else {
location.append(game->ChessBoard[i][j]);
if(boxSetting(location.last())) break;
}
}
//For Going left side
for(int i = row,j = col-1; j >= 0 ; j--) {
if(game->ChessBoard[i][j]->getChessPieceColor() == team ) break;
else{
location.append(game->ChessBoard[i][j]);
if(boxSetting(location.last())) break;
}
}
//For Going Right side
for(int i = row,j = col+1; j <= 7 ; j++){
if(game->ChessBoard[i][j]->getChessPieceColor() == team ) break;
else{
location.append(game->ChessBoard[i][j]);
if(boxSetting(location.last())) break;
}
}
}