Gestion des dependances cycliques (utilisaation de pointeurs)
This commit is contained in:
parent
e702d54b48
commit
d6a4152ac4
|
@ -1,4 +1,4 @@
|
|||
#include "ChessContext.h"
|
||||
// #include "ChessContext.h"
|
||||
|
||||
/* [1] Initialisation de la partie
|
||||
=========================================================*/
|
||||
|
@ -15,13 +15,6 @@ void ChessContext::init(){
|
|||
/* [0] Constructeur
|
||||
=========================================================*/
|
||||
ChessContext::ChessContext(){
|
||||
_p1 = new Player(true);
|
||||
_p2 = new Player(false);
|
||||
|
||||
_turn = '1';
|
||||
|
||||
_p1->initPieces();
|
||||
_p2->initPieces();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -33,6 +33,6 @@
|
|||
|
||||
/* [n] Inclusion du corps
|
||||
=========================================================*/
|
||||
// #include "ChessContext.cpp"
|
||||
#include "ChessContext.cpp"
|
||||
|
||||
#endif
|
Binary file not shown.
|
@ -1,11 +1,11 @@
|
|||
#include "Cavalier.h"
|
||||
// #include "Cavalier.h"
|
||||
|
||||
Cavalier::Cavalier(int x, int y) : Piece(CAVALIER, x, y) {
|
||||
|
||||
}
|
||||
|
||||
// ABSTRACT
|
||||
bool Cavalier::can(const ChessContext& ctx, int x, int y){
|
||||
bool Cavalier::can(int x, int y){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
Cavalier(int x, int y);
|
||||
|
||||
// ABSTRACT
|
||||
bool can(const ChessContext& ctx, int x, int y);
|
||||
bool can(int x, int y);
|
||||
char getchar();
|
||||
|
||||
};
|
||||
|
||||
/* [n] Inclusion du corps
|
||||
=========================================================*/
|
||||
// #include "Cavalier.cpp"
|
||||
#include "Cavalier.cpp"
|
||||
|
||||
#endif
|
|
@ -1,11 +1,11 @@
|
|||
#include "Fou.h"
|
||||
// #include "Fou.h"
|
||||
|
||||
Fou::Fou(int x, int y) : Piece(FOU, x, y) {
|
||||
|
||||
}
|
||||
|
||||
// ABSTRACT
|
||||
bool Fou::can(const ChessContext& ctx, int x, int y){
|
||||
bool Fou::can(int x, int y){
|
||||
bool inDiag = abs( _x-x ) == abs( _y-y );
|
||||
|
||||
// Si deplacement pas en diagonale, on retourne faux
|
||||
|
@ -15,8 +15,8 @@ bool Fou::can(const ChessContext& ctx, int x, int y){
|
|||
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;
|
||||
// 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;
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
Fou(int x, int y);
|
||||
|
||||
// ABSTRACT
|
||||
bool can(const ChessContext& ctx, int x, int y);
|
||||
bool can(int x, int y);
|
||||
char getchar();
|
||||
|
||||
};
|
||||
|
||||
/* [n] Inclusion du corps
|
||||
=========================================================*/
|
||||
// #include "Fou.cpp"
|
||||
#include "Fou.cpp"
|
||||
|
||||
#endif
|
|
@ -1,4 +1,4 @@
|
|||
#include "Piece.h"
|
||||
// #include "Piece.h"
|
||||
|
||||
Piece::Piece(PIECE_TYPE t, int x, int y) : _t(t), _x(x), _y(y){
|
||||
}
|
||||
|
@ -27,5 +27,6 @@ ostream& operator<<(ostream& o, const Piece& p){
|
|||
}
|
||||
|
||||
// ABTRACT
|
||||
bool Piece::can(const ChessContext& ctx, int x, int y){ return false; }
|
||||
bool Piece::can(int x, int y){ return false; }
|
||||
bool Piece::can(ChessContext *c, int x, int y){ return false; }
|
||||
char Piece::getchar(){ return '?'; }
|
|
@ -11,7 +11,7 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
/* (2) Externes */
|
||||
#include "../ChessContext.h"
|
||||
class ChessContext;
|
||||
|
||||
/* (3) Namespace */
|
||||
using namespace std;
|
||||
|
@ -59,9 +59,11 @@
|
|||
friend ostream& operator<<(ostream& o, const Piece& p);
|
||||
|
||||
// ABSTRACT
|
||||
virtual bool can(const ChessContext& ctx, int x, int y);
|
||||
virtual bool can(int x, int y);
|
||||
virtual bool can(ChessContext *c, int x, int y);
|
||||
virtual char getchar();
|
||||
|
||||
|
||||
protected:
|
||||
PIECE_TYPE _t;
|
||||
int _x;
|
||||
|
@ -70,6 +72,6 @@
|
|||
|
||||
/* [n] Inclusion du corps
|
||||
=========================================================*/
|
||||
// #include "Piece.cpp"
|
||||
#include "Piece.cpp"
|
||||
|
||||
#endif
|
Binary file not shown.
|
@ -1,4 +1,4 @@
|
|||
#include "PieceFactory.h"
|
||||
// #include "PieceFactory.h"
|
||||
|
||||
Piece& PieceFactory::create(PIECE_TYPE t, int x, int y){
|
||||
Piece *p;
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
/* [1] Libs
|
||||
=========================================================*/
|
||||
/* (1) Externes */
|
||||
#include "../term.h"
|
||||
|
||||
#include "Roi.h"
|
||||
#include "Reine.h"
|
||||
#include "Cavalier.h"
|
||||
|
@ -25,6 +27,6 @@
|
|||
|
||||
/* [n] Inclusion du corps
|
||||
=========================================================*/
|
||||
// #include "PieceFactory.cpp"
|
||||
#include "PieceFactory.cpp"
|
||||
|
||||
#endif
|
|
@ -1,10 +1,11 @@
|
|||
// #include "Pion.h"
|
||||
|
||||
Pion::Pion(int x, int y) : Piece(PION, x, y) {
|
||||
|
||||
}
|
||||
|
||||
// ABSTRACT
|
||||
bool Pion::can(const ChessContext& ctx, const int x, const int y) const{
|
||||
bool Pion::can(int x, int y){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
Pion(int x, int y);
|
||||
|
||||
// ABSTRACT
|
||||
bool can(const ChessContext& ctx, const int x, const int y) const;
|
||||
bool can(int x, int y);
|
||||
char getchar();
|
||||
|
||||
};
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include "Reine.h"
|
||||
// #include "Reine.h"
|
||||
|
||||
Reine::Reine(int x, int y) : Piece(REINE, x, y) {
|
||||
|
||||
}
|
||||
|
||||
// ABSTRACT
|
||||
bool Reine::can(const ChessContext& ctx, int x, int y){
|
||||
bool Reine::can(int x, int y){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
Reine(int x, int y);
|
||||
|
||||
// ABSTRACT
|
||||
bool can(const ChessContext& ctx, int x, int y);
|
||||
bool can(int x, int y);
|
||||
char getchar();
|
||||
|
||||
};
|
||||
|
||||
/* [n] Inclusion du corps
|
||||
=========================================================*/
|
||||
// #include "Reine.cpp"
|
||||
#include "Reine.cpp"
|
||||
|
||||
#endif
|
|
@ -1,11 +1,11 @@
|
|||
#include "Roi.h"
|
||||
// #include "Roi.h"
|
||||
|
||||
Roi::Roi(int x, int y) : Piece(ROI, x, y) {
|
||||
|
||||
}
|
||||
|
||||
// ABSTRACT
|
||||
bool Roi::can(const ChessContext& ctx, int x, int y){
|
||||
bool Roi::can(int x, int y){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
Roi(int x, int y);
|
||||
|
||||
// ABSTRACT
|
||||
bool can(const ChessContext& ctx, int x, int y);
|
||||
bool can(int x, int y);
|
||||
char getchar();
|
||||
|
||||
};
|
||||
|
||||
/* [n] Inclusion du corps
|
||||
=========================================================*/
|
||||
// #include "Roi.cpp"
|
||||
#include "Roi.cpp"
|
||||
|
||||
#endif
|
|
@ -1,11 +1,11 @@
|
|||
#include "Tour.h"
|
||||
// #include "Tour.h"
|
||||
|
||||
Tour::Tour(int x, int y) : Piece(TOUR, x, y) {
|
||||
|
||||
}
|
||||
|
||||
// ABSTRACT
|
||||
bool Tour::can(const ChessContext& ctx, int x, int y){
|
||||
bool Tour::can(int x, int y){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
Tour(int x, int y);
|
||||
|
||||
// ABSTRACT
|
||||
bool can(const ChessContext& ctx, int x, int y);
|
||||
bool can(int x, int y);
|
||||
char getchar();
|
||||
|
||||
};
|
||||
|
||||
/* [n] Inclusion du corps
|
||||
=========================================================*/
|
||||
// #include "Tour.cpp"
|
||||
#include "Tour.cpp"
|
||||
|
||||
#endif
|
|
@ -1,4 +1,4 @@
|
|||
#include "Player.h"
|
||||
// #include "Player.h"
|
||||
|
||||
// CONSTRUCTEUR
|
||||
Player::Player(bool first) : _first(first){
|
||||
|
|
|
@ -40,6 +40,6 @@
|
|||
|
||||
/* [n] Inclusion du corps
|
||||
=========================================================*/
|
||||
// #include "Player.cpp"
|
||||
#include "Player.cpp"
|
||||
|
||||
#endif
|
|
@ -1,3 +1,4 @@
|
|||
// #include "term.h"
|
||||
|
||||
/* [1] Operations terminal
|
||||
=========================================================*/
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
=========================================================*/
|
||||
int main(){
|
||||
ChessContext ctx;
|
||||
|
||||
cout << typeid(ctx).name() << endl;
|
||||
|
||||
|
||||
// On initialise la partie
|
||||
ctx.init();
|
||||
|
@ -143,7 +142,7 @@ void game_routine(ChessContext& ctx){
|
|||
|
||||
/* [4] On verifie qu'il peut atteindre la destination
|
||||
=========================================================*/
|
||||
cout << "Can move to dest : " << toMove->can(ctx, dest[0], dest[1]) << endl;
|
||||
cout << "Can move to dest : " << toMove->can(dest[0], dest[1]) << endl;
|
||||
|
||||
|
||||
/* [5] On gere le deplacement
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
#include <stdlib.h>
|
||||
#include <typeinfo>
|
||||
|
||||
/* (2) Externes */
|
||||
#include "dep/term.h"
|
||||
|
|
Binary file not shown.
106
Chess/makefile
106
Chess/makefile
|
@ -1,20 +1,94 @@
|
|||
.PHONY: init, clean, mrproper
|
||||
|
||||
# INIT > STRUCTURE DE FICHIERS POUR LES EXECUTABLES
|
||||
begin:
|
||||
init: clean
|
||||
mkdir dep.o
|
||||
mkdir dep.o/Pieces.o
|
||||
mkdir dep.o/Pieces
|
||||
|
||||
|
||||
# TERM < OPERATION SUR LE TERMINAL
|
||||
dep/term.o: dep/term.cpp
|
||||
g++ -c dep/term.h -o term.o
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# RESET > SUPPRESSION DE LA STRUCTURE DE FICHIERS
|
||||
# RESET > SUPPRESSION DES FICHIERS
|
||||
clean:
|
||||
rm -r dep.o
|
||||
touch init.o
|
||||
rm -r *.o
|
||||
|
||||
# RESET FOR REBUILD > SUPPRESSION DE L'EXECUTABLE
|
||||
mrproper:
|
||||
rm exe
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# EXECUTABLE > DEPENDANCES DE L'EXECUTABLE
|
||||
all: init main.o
|
||||
g++ main.o -o exe
|
||||
|
||||
# AMORCE > PROGRAMME PRINCIPAL
|
||||
main.o: main.cpp dep/term.h dep/ChessContext.h
|
||||
g++ -c $< -o main.o
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# ###############################################
|
||||
# #### HAUT NIVEAU GESTION TERMINAL LINUX ####
|
||||
# ###############################################
|
||||
# # TERM < OPERATION SUR LE TERMINAL
|
||||
# dep.o/term.o: dep/term.cpp
|
||||
# g++ -c $< -o dep.o/term.o
|
||||
|
||||
|
||||
|
||||
# ###############################################
|
||||
# #### CONTEXTE DU JEU D'ECHEC ####
|
||||
# ###############################################
|
||||
# # CONTEXTE > CONTEXTE DU JEU D'ECHEC
|
||||
# dep.o/ChessContext.o: dep/ChessContext.cpp dep.o/term.o dep.o/Player.o
|
||||
# g++ -c $< -o dep.o/ChessContext.o
|
||||
|
||||
# # JOUEUR > JOUEUR DU JEU D'ECHEC
|
||||
# dep.o/Player.o: dep/Player.cpp dep.o/term.o dep.o/Pieces/PieceFactory.o
|
||||
# g++ -c $< -o dep.o/Player.o
|
||||
|
||||
|
||||
# ###############################################
|
||||
# #### PIECES DU JEU D'ECHEC ####
|
||||
# ###############################################
|
||||
# # PIECES > ENGLOBE LES PIECES DU JEU
|
||||
# dep.o/Pieces/Piece.o: dep/Pieces/Piece.cpp
|
||||
# g++ -c $< -o dep.o/Pieces/Piece.o
|
||||
|
||||
# # USINE A PIECES > FACTORY_PATTERN POUR L'INSTANCIATION DE PIECES
|
||||
# dep.o/Pieces/PieceFactory.o: dep/Pieces/PieceFactory.cpp dep.o/term.o dep.o/Pieces/Roi.o dep.o/Pieces/Reine.o dep.o/Pieces/Cavalier.o dep.o/Pieces/Fou.o dep.o/Pieces/Tour.o dep.o/Pieces/Pion.o
|
||||
# g++ -c $< -o dep.o/Pieces/PieceFactory.o
|
||||
|
||||
# # ROI > UN TYPE DE PIECE DU JEU D'ECHECS
|
||||
# dep.o/Pieces/Roi.o: dep/Pieces/Roi.cpp dep.o/Pieces/Piece.o
|
||||
# g++ -c $< -o dep.o/Pieces/Roi.o
|
||||
|
||||
# # REINE > UN TYPE DE PIECE DU JEU D'ECHECS
|
||||
# dep.o/Pieces/Reine.o: dep/Pieces/Reine.cpp dep.o/Pieces/Piece.o
|
||||
# g++ -c $< -o dep.o/Pieces/Reine.o
|
||||
|
||||
# # CAVALIER > UN TYPE DE PIECE DU JEU D'ECHECS
|
||||
# dep.o/Pieces/Cavalier.o: dep/Pieces/Cavalier.cpp dep.o/Pieces/Piece.o
|
||||
# g++ -c $< -o dep.o/Pieces/Cavalier.o
|
||||
|
||||
# # FOU > UN TYPE DE PIECE DU JEU D'ECHECS
|
||||
# dep.o/Pieces/Fou.o: dep/Pieces/Fou.cpp dep.o/Pieces/Piece.o
|
||||
# g++ -c $< -o dep.o/Pieces/Fou.o
|
||||
|
||||
# # TOUR > UN TYPE DE PIECE DU JEU D'ECHECS
|
||||
# dep.o/Pieces/Tour.o: dep/Pieces/Tour.cpp dep.o/Pieces/Piece.o
|
||||
# g++ -c $< -o dep.o/Pieces/Tour.o
|
||||
|
||||
# # PION > UN TYPE DE PIECE DU JEU D'ECHECS
|
||||
# dep.o/Pieces/Pion.o: dep/Pieces/Pion.cpp dep.o/Pieces/Piece.o
|
||||
# g++ -c $< -o dep.o/Pieces/Pion.o
|
Loading…
Reference in New Issue