-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTour.cpp
70 lines (60 loc) · 1.07 KB
/
Tour.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
59
60
61
62
63
64
65
66
67
68
69
70
/**
* Mise en oeuvre de Tour.h
*
* @file Tour.cxx
*/
#include "Tour.h"
#include "Echiquier.h"
#include <iostream>
using namespace std;
Tour::Tour()
{
this->setFixedSize(Echiquier::SIZE,Echiquier::SIZE);
}
Tour::Tour(int x, int y, bool white,Echiquier* parent) : Piece(x,y,white,parent)
{
}
bool Tour::mouvementValide( Echiquier & e, int x, int y )
{
int X = m_x;
int Y = m_y;
//Dans l'echiquier
if( x<1 || x>8 || y<1 || y>8 ) {
return false;
}
//Valide mouvement
if ( (x!=X && Y!=y) || (x==X && y==Y) ) {
return false;
}
//Pas blocker
//y change
if (x==X) {
int movY = (y>Y? 1:-1);
for (int i=Y+movY; i != y; i += movY) {
if (e.getPiece(x,i) != NULL) {
return false;
}
}
}
//x change
else {
int movX = (x>X? 1:-1);
for (int i=X+movX; i!= x; i+=movX) {
if (e.getPiece(i,y) != NULL) {
return false;
}
}
}
return true;
}
void
Tour::paintEvent(QPaintEvent *) {
QString name = "";
if(m_white){
name = "WRook.png";
}
else {
name = "BRook.png";
}
paintPiece(name);
}