This commit is contained in:
xdrm-brackets 2016-03-06 22:51:07 +01:00
parent d01c4eb135
commit 6245298626
23 changed files with 547 additions and 0 deletions

0
Chess/dep/Grid.cpp Normal file
View File

37
Chess/dep/Grid.h Normal file
View File

@ -0,0 +1,37 @@
#ifndef DEF_GRID
#define DEF_GRID
/* [1] Libs
=========================================================*/
/* (1) Internes */
#include <iostream>
#include <string>
#include <vector>
/* (2) Externes */
#include "term.h"
#include "Pieces/PieceFactory.h"
/* (3) Namespace */
using namespace std;
/* [2] Definition
=========================================================*/
class Grid{
public:
Grid(const int w=8, const int h=8);
// GETTERS
Piece pieceAt(const int x, const int y) const;
private:
// vector<Cell> _cells;
};
/* [n] Inclusion du corps
=========================================================*/
#include "Grid.cpp"
#endif

View File

@ -0,0 +1,13 @@
Cavalier::Cavalier(int x, int y) : Piece(CAVALIER, x, y) {
}
// ABSTRACT
bool Cavalier::can(const int x, const int y) const{
return true;
}
char Cavalier::getchar(){
return 'P';
}

View File

@ -0,0 +1,31 @@
#ifndef DEF_CAVALIER
#define DEF_CAVALIER
/* [1] Libs
=========================================================*/
/* (1) Internes */
/* (2) Externes */
#include "Piece.h"
/* (3) Namespace */
using namespace std;
/* [2] Definition
=========================================================*/
class Cavalier : public Piece{
public:
Cavalier(int x, int y);
// ABSTRACT
bool can(const int x, const int y) const;
char getchar();
};
/* [n] Inclusion du corps
=========================================================*/
#include "Cavalier.cpp"
#endif

13
Chess/dep/Pieces/Fou.cpp Normal file
View File

@ -0,0 +1,13 @@
Fou::Fou(int x, int y) : Piece(FOU, x, y) {
}
// ABSTRACT
bool Fou::can(const int x, const int y) const{
return true;
}
char Fou::getchar(){
return 'P';
}

31
Chess/dep/Pieces/Fou.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef DEF_FOU
#define DEF_FOU
/* [1] Libs
=========================================================*/
/* (1) Internes */
/* (2) Externes */
#include "Piece.h"
/* (3) Namespace */
using namespace std;
/* [2] Definition
=========================================================*/
class Fou : public Piece{
public:
Fou(int x, int y);
// ABSTRACT
bool can(const int x, const int y) const;
char getchar();
};
/* [n] Inclusion du corps
=========================================================*/
#include "Fou.cpp"
#endif

View File

@ -0,0 +1,23 @@
Piece::Piece(PIECE_TYPE t, int x, int y) : _t(t), _x(x), _y(y){
}
// GETTERS
PIECE_TYPE Piece::gett() const{ return _t; }
int Piece::getx() const{ return _x; }
int Piece::gety() const{ return _y; }
// SETTERS
void Piece::move(const int x, const int y){
_x = x;
_y = y;
}
// OPERATEURS (SURCHARGE)
ostream& operator<<(ostream& o, const Piece& p){
return o << p._t << " at (" << p._x << "," << p._y << ")";
}
// ABTRACT
bool Piece::can(const int x, const int y){ return false; }
char Piece::getchar(){ return '?'; }

72
Chess/dep/Pieces/Piece.h Normal file
View File

@ -0,0 +1,72 @@
#ifndef DEF_PIECE
#define DEF_PIECE
/* [1] Libs
=========================================================*/
/* (1) Internes */
#include <iostream>
#include <string>
#include <vector>
/* (2) Externes */
/* (3) Namespace */
using namespace std;
/* [2] Enumerations
=========================================================*/
enum PIECE_TYPE{
ROI,
REINE,
CAVALIER,
TOUR,
FOU,
PION
};
ostream& operator<<(ostream& o, const PIECE_TYPE& t){
switch(t){
case ROI: return o << "Roi"; break;
case REINE: return o << "Reine"; break;
case CAVALIER: return o << "Cavalier"; break;
case FOU: return o << "Fou"; break;
case TOUR: return o << "Tour"; break;
case PION: return o << "Pion"; break;
}
return o << "UNKNOWN";
}
/* [2] Definition
=========================================================*/
class Piece{
public:
Piece(PIECE_TYPE t, int x, int y);
// GETTERS
PIECE_TYPE gett() const;
int getx() const;
int gety() const;
// SETTERS
void move(const int x, const int y);
// OPERATEURS (SURCHARGE)
friend ostream& operator<<(ostream& o, const Piece& p);
// ABSTRACT
virtual bool can(const int x, const int y);
virtual char getchar();
protected:
PIECE_TYPE _t;
int _x;
int _y;
};
/* [n] Inclusion du corps
=========================================================*/
#include "Piece.cpp"
#endif

View File

@ -0,0 +1,14 @@
Piece& PieceFactory::create(PIECE_TYPE t, int x, int y){
Piece *p;
switch(t){
case ROI: p = new Roi(x, y); break;
case REINE: p = new Reine(x, y); break;
case CAVALIER: p = new Cavalier(x, y); break;
case FOU: p = new Fou(x, y); break;
case TOUR: p = new Tour(x, y); break;
case PION: p = new Pion(x, y); break;
}
return *p;
}

View File

@ -0,0 +1,30 @@
#ifndef DEF_PIECEFACTORY
#define DEF_PIECEFACTORY
/* [1] Libs
=========================================================*/
/* (1) Externes */
#include "Roi.h"
#include "Reine.h"
#include "Cavalier.h"
#include "Tour.h"
#include "Fou.h"
#include "Pion.h"
/* (2) Namespace */
using namespace std;
/* [2] Definition
=========================================================*/
class PieceFactory{
public:
static Piece& create(PIECE_TYPE t, int x, int y);
};
/* [n] Inclusion du corps
=========================================================*/
#include "PieceFactory.cpp"
#endif

13
Chess/dep/Pieces/Pion.cpp Normal file
View File

@ -0,0 +1,13 @@
Pion::Pion(int x, int y) : Piece(PION, x, y) {
}
// ABSTRACT
bool Pion::can(const int x, const int y) const{
return true;
}
char Pion::getchar(){
return 'P';
}

31
Chess/dep/Pieces/Pion.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef DEF_PION
#define DEF_PION
/* [1] Libs
=========================================================*/
/* (1) Internes */
/* (2) Externes */
#include "Piece.h"
/* (3) Namespace */
using namespace std;
/* [2] Definition
=========================================================*/
class Pion : public Piece{
public:
Pion(int x, int y);
// ABSTRACT
bool can(const int x, const int y) const;
char getchar();
};
/* [n] Inclusion du corps
=========================================================*/
#include "Pion.cpp"
#endif

View File

@ -0,0 +1,13 @@
Reine::Reine(int x, int y) : Piece(REINE, x, y) {
}
// ABSTRACT
bool Reine::can(const int x, const int y) const{
return true;
}
char Reine::getchar(){
return 'P';
}

31
Chess/dep/Pieces/Reine.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef DEF_REINE
#define DEF_REINE
/* [1] Libs
=========================================================*/
/* (1) Internes */
/* (2) Externes */
#include "Piece.h"
/* (3) Namespace */
using namespace std;
/* [2] Definition
=========================================================*/
class Reine : public Piece{
public:
Reine(int x, int y);
// ABSTRACT
bool can(const int x, const int y) const;
char getchar();
};
/* [n] Inclusion du corps
=========================================================*/
#include "Reine.cpp"
#endif

13
Chess/dep/Pieces/Roi.cpp Normal file
View File

@ -0,0 +1,13 @@
Roi::Roi(int x, int y) : Piece(ROI, x, y) {
}
// ABSTRACT
bool Roi::can(const int x, const int y) const{
return true;
}
char Roi::getchar(){
return 'R';
}

31
Chess/dep/Pieces/Roi.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef DEF_Roi
#define DEF_Roi
/* [1] Libs
=========================================================*/
/* (1) Internes */
/* (2) Externes */
#include "Piece.h"
/* (3) Namespace */
using namespace std;
/* [2] Definition
=========================================================*/
class Roi : public Piece{
public:
Roi(int x, int y);
// ABSTRACT
bool can(const int x, const int y) const;
char getchar();
};
/* [n] Inclusion du corps
=========================================================*/
#include "Roi.cpp"
#endif

13
Chess/dep/Pieces/Tour.cpp Normal file
View File

@ -0,0 +1,13 @@
Tour::Tour(int x, int y) : Piece(TOUR, x, y) {
}
// ABSTRACT
bool Tour::can(const int x, const int y) const{
return true;
}
char Tour::getchar(){
return 'P';
}

31
Chess/dep/Pieces/Tour.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef DEF_TOUR
#define DEF_TOUR
/* [1] Libs
=========================================================*/
/* (1) Internes */
/* (2) Externes */
#include "Piece.h"
/* (3) Namespace */
using namespace std;
/* [2] Definition
=========================================================*/
class Tour : public Piece{
public:
Tour(int x, int y);
// ABSTRACT
bool can(const int x, const int y) const;
char getchar();
};
/* [n] Inclusion du corps
=========================================================*/
#include "Tour.cpp"
#endif

10
Chess/dep/term.cpp Normal file
View File

@ -0,0 +1,10 @@
/* [1] Operations terminal
=========================================================*/
void clear(){ // efface l'ecran
cout << "\033[H\033[2J";
}
void setfont(const TERM_COLOR c, const TERM_STYLE s){
cout << "\033[" << s << ";" << c << "m";
}

47
Chess/dep/term.h Normal file
View File

@ -0,0 +1,47 @@
#ifndef DEF_TERM
#define DEF_TERM
/* [1] Libs
=========================================================*/
/* (1) internes */
#include <iostream>
/* (2) Namespace */
using namespace std;
/* [2] Enumerations et structures
=========================================================*/
enum TERM_COLOR{
DEFAULT = 0,
DARKBLUE = 30,
RED = 31,
GREEN = 32,
YELLOW = 33,
BLUE = 34,
PURPLE = 35,
SKYBLUE = 36
};
enum TERM_STYLE{
NORMAL = 0,
BOLD = 1,
ITALIC = 3,
UNDERLINE = 4,
DASHED = 9,
BACKGROUND = 7
};
/* [3] Methodes
=========================================================*/
void clear();
void setfont(const TERM_COLOR c=DEFAULT, const TERM_STYLE s=NORMAL);
/* [n] Inclusion du corps
=========================================================*/
#include "term.cpp"
#endif

BIN
Chess/e Executable file

Binary file not shown.

22
Chess/main.cpp Normal file
View File

@ -0,0 +1,22 @@
#include "main.h"
/* [0] Point d'amorcage
=========================================================*/
int main(){
Piece *a = new Roi(1, 12);
Piece *b = new Pion(1, 12);
setfont(RED);
cout << *a << endl;
setfont(SKYBLUE);
cout << *b << endl;
cout << *b << endl;
setfont();
return 0;
}

28
Chess/main.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef DEF_HEADER
#define DEF_HEADER
/* [1] Libs
=========================================================*/
/* (1) internes */
#include <iostream>
#include <string>
#include <vector>
/* (2) Externes */
#include "dep/term.h"
#include "dep/Grid.h"
/* (3) Namespace */
using namespace std;
/* [2] Enumerations et structures
=========================================================*/
/* [3] Methodes
=========================================================*/
int main();
#endif