diff --git a/Chess/Chess.todo.md b/Chess/Chess.todo.md new file mode 100644 index 0000000..d9d1ebe --- /dev/null +++ b/Chess/Chess.todo.md @@ -0,0 +1,12 @@ +A FAIRE +======= +- [ ] Prevision des cases de destination +- [ ] Timeout pour le jeu + +- [ ] IA +- [ ] Changer l'unicode en fonction du joueur + +FAIT +==== +- [x] Caracteres unicode pour les pieces +- [x] Methode pour texte multicolore \ No newline at end of file diff --git a/Chess/dep/ChessContext.h b/Chess/dep/ChessContext.h index b504d35..ba81009 100644 --- a/Chess/dep/ChessContext.h +++ b/Chess/dep/ChessContext.h @@ -31,6 +31,8 @@ Player* getCurrent(); Player* getEnemy(); + // IA : Intelligence Modulaire + // ATTRIBUTS char _turn; Player *_p1; diff --git a/Chess/dep/Pieces/Cavalier.cpp b/Chess/dep/Pieces/Cavalier.cpp index a90deae..ca7a3d5 100644 --- a/Chess/dep/Pieces/Cavalier.cpp +++ b/Chess/dep/Pieces/Cavalier.cpp @@ -5,6 +5,7 @@ Cavalier::Cavalier(int x, int y) : Piece(CAVALIER, x, y) { } // ABSTRACT -char Cavalier::getchar(){ - return 'C'; +string Cavalier::getchar(){ + return "\u265E"; + return "\u2658"; } diff --git a/Chess/dep/Pieces/Cavalier.h b/Chess/dep/Pieces/Cavalier.h index 38a4db4..030bb40 100644 --- a/Chess/dep/Pieces/Cavalier.h +++ b/Chess/dep/Pieces/Cavalier.h @@ -19,7 +19,7 @@ Cavalier(int x, int y); // ABSTRACT - char getchar(); + string getchar(); }; diff --git a/Chess/dep/Pieces/Fou.cpp b/Chess/dep/Pieces/Fou.cpp index 2cc3774..9774a01 100644 --- a/Chess/dep/Pieces/Fou.cpp +++ b/Chess/dep/Pieces/Fou.cpp @@ -5,6 +5,7 @@ Fou::Fou(int x, int y) : Piece(FOU, x, y) { } // ABSTRACT -char Fou::getchar(){ - return 'F'; +string Fou::getchar(){ + return "\u265D"; + return "\u2657"; } diff --git a/Chess/dep/Pieces/Fou.h b/Chess/dep/Pieces/Fou.h index 698cabd..4955cc1 100644 --- a/Chess/dep/Pieces/Fou.h +++ b/Chess/dep/Pieces/Fou.h @@ -19,7 +19,7 @@ Fou(int x, int y); // ABSTRACT - char getchar(); + string getchar(); }; diff --git a/Chess/dep/Pieces/Piece.cpp b/Chess/dep/Pieces/Piece.cpp index b405305..fe5507c 100644 --- a/Chess/dep/Pieces/Piece.cpp +++ b/Chess/dep/Pieces/Piece.cpp @@ -27,4 +27,4 @@ ostream& operator<<(ostream& o, const Piece& p){ } // ABTRACT -char Piece::getchar(){ return '?'; } \ No newline at end of file +string Piece::getchar(){ return "?"; } \ No newline at end of file diff --git a/Chess/dep/Pieces/Piece.h b/Chess/dep/Pieces/Piece.h index 9f1c1ba..c66c318 100644 --- a/Chess/dep/Pieces/Piece.h +++ b/Chess/dep/Pieces/Piece.h @@ -59,7 +59,7 @@ friend ostream& operator<<(ostream& o, const Piece& p); // ABSTRACT - virtual char getchar(); + virtual string getchar(); protected: diff --git a/Chess/dep/Pieces/Pion.cpp b/Chess/dep/Pieces/Pion.cpp index 3be8128..968faca 100644 --- a/Chess/dep/Pieces/Pion.cpp +++ b/Chess/dep/Pieces/Pion.cpp @@ -5,6 +5,7 @@ Pion::Pion(int x, int y) : Piece(PION, x, y) { } // ABSTRACT -char Pion::getchar(){ - return 'P'; +string Pion::getchar(){ + return "\u265F"; + return "\u2659"; } diff --git a/Chess/dep/Pieces/Pion.h b/Chess/dep/Pieces/Pion.h index cbfe4f4..da268ae 100644 --- a/Chess/dep/Pieces/Pion.h +++ b/Chess/dep/Pieces/Pion.h @@ -19,7 +19,7 @@ Pion(int x, int y); // ABSTRACT - char getchar(); + string getchar(); }; diff --git a/Chess/dep/Pieces/Reine.cpp b/Chess/dep/Pieces/Reine.cpp index 613efba..9dc55bc 100644 --- a/Chess/dep/Pieces/Reine.cpp +++ b/Chess/dep/Pieces/Reine.cpp @@ -5,6 +5,7 @@ Reine::Reine(int x, int y) : Piece(REINE, x, y) { } // ABSTRACT -char Reine::getchar(){ - return 'Q'; +string Reine::getchar(){ + return "\u265B"; + return "\u2655"; } diff --git a/Chess/dep/Pieces/Reine.h b/Chess/dep/Pieces/Reine.h index 3944209..23f3fb7 100644 --- a/Chess/dep/Pieces/Reine.h +++ b/Chess/dep/Pieces/Reine.h @@ -19,7 +19,7 @@ Reine(int x, int y); // ABSTRACT - char getchar(); + string getchar(); }; diff --git a/Chess/dep/Pieces/Roi.cpp b/Chess/dep/Pieces/Roi.cpp index c887778..046e569 100644 --- a/Chess/dep/Pieces/Roi.cpp +++ b/Chess/dep/Pieces/Roi.cpp @@ -5,6 +5,7 @@ Roi::Roi(int x, int y) : Piece(ROI, x, y) { } // ABSTRACT -char Roi::getchar(){ - return 'K'; +string Roi::getchar(){ + return "\u265A"; + return "\u2654"; } diff --git a/Chess/dep/Pieces/Roi.h b/Chess/dep/Pieces/Roi.h index 3dfc81a..9e7696f 100644 --- a/Chess/dep/Pieces/Roi.h +++ b/Chess/dep/Pieces/Roi.h @@ -19,7 +19,7 @@ Roi(int x, int y); // ABSTRACT - char getchar(); + string getchar(); }; diff --git a/Chess/dep/Pieces/Tour.cpp b/Chess/dep/Pieces/Tour.cpp index 79dfed2..8899247 100644 --- a/Chess/dep/Pieces/Tour.cpp +++ b/Chess/dep/Pieces/Tour.cpp @@ -5,6 +5,7 @@ Tour::Tour(int x, int y) : Piece(TOUR, x, y) { } // ABSTRACT -char Tour::getchar(){ - return 'T'; +string Tour::getchar(){ + return "\u265C"; + return "\u2656"; } diff --git a/Chess/dep/Pieces/Tour.h b/Chess/dep/Pieces/Tour.h index ab9f588..6d55dc6 100644 --- a/Chess/dep/Pieces/Tour.h +++ b/Chess/dep/Pieces/Tour.h @@ -19,7 +19,7 @@ Tour(int x, int y); // ABSTRACT - char getchar(); + string getchar(); }; diff --git a/Chess/dep/term.cpp b/Chess/dep/term.cpp index 3c8f288..9c439bc 100644 --- a/Chess/dep/term.cpp +++ b/Chess/dep/term.cpp @@ -2,7 +2,7 @@ /* [1] Operations terminal =========================================================*/ -void clear(){ // efface l'ecran +void clear_screen(){ // efface l'ecran cout << "\033[H\033[2J"; } @@ -22,4 +22,30 @@ void err(string msg){ // On attends l'appui sur une touche setfont(); sleep(1); +} + + +// Affiche un texte avec une couleur par caractere +void multicolor(string str, const TERM_STYLE s){ + srand(time(0)); // initialisation du random + + // On recupere les valeurs possibles (couleurs) + int *colorvalues = TERM_COLOR_VALUES; + int len = sizeof(colorvalues); + int color; + TERM_COLOR tc; + + + // Pour chaque caractere de la string + for( int i = 0 ; i < str.size() ; i++ ){ + color = rand() % len; // on prends une couleur aleatoire + tc = static_cast(colorvalues[color]); // on la met au bon format + setfont(tc, s); + cout << str.at(i); + setfont(); + } + + + + } \ No newline at end of file diff --git a/Chess/dep/term.h b/Chess/dep/term.h index ded27ad..31eeda0 100644 --- a/Chess/dep/term.h +++ b/Chess/dep/term.h @@ -6,6 +6,7 @@ =========================================================*/ /* (1) internes */ #include + #include /* (2) Namespace */ using namespace std; @@ -25,6 +26,8 @@ SKYBLUE = 36 }; + int TERM_COLOR_VALUES[] = {0, 30, 31, 32, 33, 34, 35, 36}; + enum TERM_STYLE{ NORMAL = 0, BOLD = 1, @@ -35,11 +38,15 @@ BACKGROUND = 7 }; + int TERM_STYLE_VALUES[] = {0, 1, 3, 4, 9, 7}; + /* [3] Methodes =========================================================*/ - void clear(); + void clear_screen(); void setfont(const TERM_COLOR c=DEFAULT, const TERM_STYLE s=NORMAL); void err(string msg); + void init_term(); + void multicolor(string str, const TERM_STYLE s=NORMAL); /* [n] Inclusion du corps =========================================================*/ diff --git a/Chess/exe b/Chess/exe index 660cd8c..297db68 100755 Binary files a/Chess/exe and b/Chess/exe differ diff --git a/Chess/main.cpp b/Chess/main.cpp index de1f13b..e917f07 100644 --- a/Chess/main.cpp +++ b/Chess/main.cpp @@ -3,8 +3,15 @@ /* [0] Point d'amorcage =========================================================*/ int main(){ + + // On cree un Jeu ChessContext ctx; + // Message d'accueil + clear_screen(); + cout << "Bievenue sur " << endl; + sleep(1); + // On initialise la partie ctx.init(); @@ -16,7 +23,9 @@ int main(){ }while( ctx._turn != 'x' ); + // On reset les modifications de police setfont(); + return 0; } @@ -26,7 +35,7 @@ int main(){ void display_board(ChessContext& ctx){ /* [1] On efface l'ecran =========================================================*/ - clear(); + clear_screen(); /* [2] On affiche la banniere =========================================================*/ @@ -35,14 +44,8 @@ void display_board(ChessContext& ctx){ cout << " + +" << endl; cout << " + Chess "; - setfont(DARKBLUE, BOLD); cout << "C"; - setfont(SKYBLUE, BOLD); cout << "o"; - setfont(GREEN, BOLD); cout << "l"; - setfont(YELLOW, BOLD); cout << "o"; - setfont(BLUE, BOLD); cout << "r"; - setfont(PURPLE, BOLD); cout << "f"; - setfont(SKYBLUE, BOLD); cout << "u"; - setfont(GREEN, BOLD); cout << "l"; + + multicolor("Colorful", BOLD); setfont(RED, BOLD); cout << " Console Game +" << endl; diff --git a/Chess/main.h b/Chess/main.h index aaa3b6c..e280bd3 100644 --- a/Chess/main.h +++ b/Chess/main.h @@ -21,7 +21,12 @@ /* [2] Enumerations et structures =========================================================*/ - + enum KEYBOARD{ + HAUT = 72, + BAS = 80, + GAUCHE = 75, + DROITE = 77 + }; /* [3] Methodes =========================================================*/ diff --git a/Chess/main.o b/Chess/main.o index e33d928..842c88b 100644 Binary files a/Chess/main.o and b/Chess/main.o differ