-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pion.cpp
80 lines (71 loc) · 1.49 KB
/
Pion.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
71
72
73
74
75
76
77
78
79
80
/**
* Mise en oeuvre de Pion.h
*
* @file Pion.cxx
*/
#include "Pion.h"
#include "Echiquier.h"
#include <iostream>
using namespace std;
Pion::Pion()
{
this->setFixedSize(Echiquier::SIZE,Echiquier::SIZE);
}
Pion::Pion(int x, int y, bool white,Echiquier* parent) : Piece(x,y,white,parent)
{ }
bool
Pion::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;
}
if(e.getPiece(x,y)==NULL) {
//Cases pas occuppe
//Mouver aligné
if(x == X) {
if(this->isWhite()) {
if(this->y() == 2)
return y == Y+2 || y == Y+1;
else
return y == Y+1;
}
else {
if(this->y() == 7)
return y == Y-2 || y == Y-1;
else
return y == Y-1;
}
}
}
else {
//Cases occuppe par opposite couleur
if ( x==X+1 || x == X-1 ){
if(this->isWhite()) {
return y == Y+1;
}
else {
return y == Y-1;
}
}
}
return false;
}
void
Pion::paintEvent(QPaintEvent *) {
QString name = "";
if(m_white){
name = "WPawn.png";
}
else {
name = "BPawn.png";
}
paintPiece(name);
}
bool
Pion::canPromote(){
if(m_white) return m_y == 8;
else return m_y == 1;
}