Corrections mais tjs pb dans implementation avec utilisation d'un ChessContext meme en pointeur

This commit is contained in:
xdrm-brackets 2016-03-08 23:53:11 +01:00
parent d6a4152ac4
commit 8c2f003941
8 changed files with 42 additions and 21 deletions

View File

@ -1,5 +1,14 @@
// #include "ChessContext.h" // #include "ChessContext.h"
/* [0] Constructeur
=========================================================*/
ChessContext::ChessContext(){
setfont(GREEN, BOLD);
cout << "[+] ChessContext" << endl;
setfont();
}
/* [1] Initialisation de la partie /* [1] Initialisation de la partie
=========================================================*/ =========================================================*/
void ChessContext::init(){ void ChessContext::init(){
@ -12,11 +21,6 @@ void ChessContext::init(){
_p2->initPieces(); _p2->initPieces();
} }
/* [0] Constructeur
=========================================================*/
ChessContext::ChessContext(){
}
/* [2] Renvoie le pion qui est en case (x, y) /* [2] Renvoie le pion qui est en case (x, y)
=========================================================*/ =========================================================*/

View File

@ -8,20 +8,34 @@ Fou::Fou(int x, int y) : Piece(FOU, x, y) {
bool Fou::can(int x, int y){ bool Fou::can(int x, int y){
bool inDiag = abs( _x-x ) == abs( _y-y ); bool inDiag = abs( _x-x ) == abs( _y-y );
// Si deplacement pas en diagonale, on retourne faux // Si deplacement pas en diagonale, on retourne faux
if( !inDiag ) return false; if( !inDiag ) return false;
// On verifie que la diagonale est degagee // On verifie que la diagonale est degagee
int xstep = ( x-_x ) / abs( x-_x ); int xstep = ( x-_x ) / abs( x-_x );
int ystep = ( y-_y ) / abs( y-_y ); int ystep = ( y-_y ) / abs( y-_y );
// for( int i = _x+xstep, j = _y+ystep ; i != x && j != y ; i+=xstep, j+=ystep ) return true;
// if( ctx._p1->at(i, j) != NULL ) return false;
return true;
} }
/*bool Fou::can(ChessContext *c, 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( c->_p1->at(i, j) != NULL ) return false;
return true;
}*/
char Fou::getchar(){ char Fou::getchar(){
return 'F'; return 'F';
} }

View File

@ -8,6 +8,7 @@
/* (2) Externes */ /* (2) Externes */
#include "Piece.h" #include "Piece.h"
class ChessContext;
/* (3) Namespace */ /* (3) Namespace */
using namespace std; using namespace std;
@ -20,6 +21,7 @@
// ABSTRACT // ABSTRACT
bool can(int x, int y); bool can(int x, int y);
//bool can(ChessContext *c, int x, int y);
char getchar(); char getchar();
}; };

View File

@ -15,7 +15,7 @@ Piece& PieceFactory::create(PIECE_TYPE t, int x, int y){
/* DEBUG */ /* DEBUG */
setfont(SKYBLUE, NORMAL); setfont(SKYBLUE, NORMAL);
cout << "\t[+] " << p->gett() << " at (" << p->getx() << "," << p->gety() << ")"; cout << " [+] " << p->gett() << " at (" << p->getx() << "," << p->gety() << ")";
setfont(); setfont();
cout << endl; cout << endl;

View File

@ -4,7 +4,7 @@
Player::Player(bool first) : _first(first){ Player::Player(bool first) : _first(first){
setfont(GREEN, BOLD); setfont(GREEN, BOLD);
cout << "[+] Player " << (_first?1:2); cout << " [+] Player " << (_first?1:2);
setfont(); setfont();
cout << endl; cout << endl;
@ -33,7 +33,7 @@ void Player::addPiece(Piece& p){
/* DEBUG */ /* DEBUG */
setfont(BLUE, ITALIC); setfont(BLUE, ITALIC);
cout << "\t\t[+] linked to Player " << (_first?1:2); cout << " [+] linked to Player " << (_first?1:2);
setfont(); setfont();
cout << endl; cout << endl;

BIN
Chess/exe

Binary file not shown.

Binary file not shown.

View File

@ -24,7 +24,8 @@ mrproper:
# EXECUTABLE > DEPENDANCES DE L'EXECUTABLE # EXECUTABLE > DEPENDANCES DE L'EXECUTABLE
all: init main.o all: init main.o clean
rm -r dep.o
g++ main.o -o exe g++ main.o -o exe
# AMORCE > PROGRAMME PRINCIPAL # AMORCE > PROGRAMME PRINCIPAL