88 lines
1.9 KiB
C++
88 lines
1.9 KiB
C++
// #include "Player.h"
|
|
|
|
// CONSTRUCTEUR
|
|
Player::Player(bool first) : _first(first){
|
|
setfont(GREEN, BOLD);
|
|
|
|
cout << "[+] Player " << (_first?1:2);
|
|
|
|
setfont();
|
|
cout << endl;
|
|
}
|
|
|
|
// GETTERS
|
|
bool Player::owns(Piece& p) const{
|
|
for( int i = 0 ; i < _pieces.size() ; i++ )
|
|
if( _pieces.at(i) == &p ) return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
Piece* Player::at(const int x, const int y){
|
|
for( int i = 0 ; i < _pieces.size() ; i++ )
|
|
if( _pieces[i]->getx() == x && _pieces[i]->gety() == y )
|
|
return _pieces[i];
|
|
|
|
return NULL;
|
|
|
|
}
|
|
// SETTERS
|
|
void Player::addPiece(Piece& p){
|
|
_pieces.push_back( &p );
|
|
|
|
/* DEBUG */
|
|
setfont(BLUE, ITALIC);
|
|
|
|
cout << "\t\t[+] linked to Player " << (_first?1:2);
|
|
|
|
setfont();
|
|
cout << endl;
|
|
}
|
|
|
|
void Player::remPiece(Piece& p){
|
|
int index = -1;
|
|
|
|
// On cherche la piece
|
|
for( int i = 0 ; i < _pieces.size() ; i++ )
|
|
if( _pieces.at(i) == &p )
|
|
index = i;
|
|
|
|
// On ajoute au cimetiere
|
|
if( index > -1 ){
|
|
_cimetery.push_back( &p );
|
|
_pieces.erase(_pieces.begin() + index );
|
|
}
|
|
|
|
/* DEBUG */
|
|
setfont(BLUE, ITALIC);
|
|
|
|
cout << "\t\t[-] " << p << " to cimetery of Player " << (_first?1:2);
|
|
|
|
setfont();
|
|
cout << endl;
|
|
}
|
|
|
|
// INITIALISATION DES PIECES DE BASE
|
|
void Player::initPieces(){
|
|
int y1 = _first ? 0 : 7; // ligne forte
|
|
int y2 = _first ? 1 : 6; // ligne de pions
|
|
|
|
|
|
// Premier ligne
|
|
this->addPiece( PieceFactory::create(TOUR, 0, y1) );
|
|
this->addPiece( PieceFactory::create(CAVALIER, 1, y1) );
|
|
this->addPiece( PieceFactory::create(FOU, 2, y1) );
|
|
|
|
this->addPiece( PieceFactory::create(REINE, 3, y1) );
|
|
this->addPiece( PieceFactory::create(ROI, 4, y1) );
|
|
|
|
this->addPiece( PieceFactory::create(FOU, 5, y1) );
|
|
this->addPiece( PieceFactory::create(CAVALIER, 6, y1) );
|
|
this->addPiece( PieceFactory::create(TOUR, 7, y1) );
|
|
|
|
for( int i = 0 ; i < 8 ; i++ )
|
|
this->addPiece( PieceFactory::create(PION, i, y2) );
|
|
|
|
}
|
|
|