lab.cpp/Chess/dep/Pieces/Fou.cpp

27 lines
563 B
C++
Raw Normal View History

2016-03-06 21:51:07 +00:00
Fou::Fou(int x, int y) : Piece(FOU, x, y) {
}
// ABSTRACT
2016-03-08 18:23:35 +00:00
bool Fou::can(const ChessContext& ctx, int x, int y){
bool inDiag = abs( _x-x ) == abs( _y-y );
// Si deplacement pas en diagonale, on retourne faux
if( !inDiag ) return false;
// On verifie que la diagonale est degagee
int xstep = ( x-_x ) / abs( x-_x );
int ystep = ( y-_y ) / abs( y-_y );
for( int i = _x+xstep, j = _y+ystep ; i != x && j != y ; i+=xstep, j+=ystep )
if( ctx._p1->at(i, j) != NULL ) return false;
return true;
2016-03-06 21:51:07 +00:00
}
char Fou::getchar(){
2016-03-08 18:23:35 +00:00
return 'F';
2016-03-06 21:51:07 +00:00
}