diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e017f05 --- /dev/null +++ b/.gitignore @@ -0,0 +1,36 @@ +# Compiled Object files + +*.slo +*.lo +*.o + + +# Compiled Dynamic libraries + +*.so + + +# Compiled Static libraries + +*.lai +*.la +*.a + + +# Output files + +*.exe +*.d + + +#Eclipse Folder + +.settings +Debug +.cproject +.project +.metadata + +#Bilder +*.bmp + diff --git a/Chess/.gitignore b/Chess/.gitignore new file mode 100644 index 0000000..e017f05 --- /dev/null +++ b/Chess/.gitignore @@ -0,0 +1,36 @@ +# Compiled Object files + +*.slo +*.lo +*.o + + +# Compiled Dynamic libraries + +*.so + + +# Compiled Static libraries + +*.lai +*.la +*.a + + +# Output files + +*.exe +*.d + + +#Eclipse Folder + +.settings +Debug +.cproject +.project +.metadata + +#Bilder +*.bmp + diff --git a/Chess/Interface/interface.cpp b/Chess/Interface/interface.cpp new file mode 100644 index 0000000..908b527 --- /dev/null +++ b/Chess/Interface/interface.cpp @@ -0,0 +1,54 @@ +/* + * interface.cpp + * + * Created on: 30.05.2012 + * Author: Thomas + */ + +#include "interface.h" +#include "../game/brett.h" +#include +#include +#include + +void Interface::einlesen(int p) +{ + do + { + std::cout << "Spieler " << p << ": Bitte Zug eingeben: "; + std::cin >> p1a >> p1b >> p2a >> p2b; + + if (std::cin.fail()==false) + { + break; + } + else + { + std::cin.clear(); + std::cin.ignore(std::numeric_limits::max(), '\n'); + } + } + while (true); + +} + +void Interface::ausgabe(brett* b) +{ + std::cout << " a b c d e f g h" << std::endl << " ---------------" << std::endl; + for (int i=0;i<8;i++) + { + std::cout << 8-i << "|"; + for (int j=0;j<8;j++) + { + std::cout << b->lese(j,i) << " "; + } + std::cout << std::endl; + } + +} + +void Interface::winner(int player) +{ + +} + diff --git a/Chess/Interface/interface.h b/Chess/Interface/interface.h new file mode 100644 index 0000000..1bd603b --- /dev/null +++ b/Chess/Interface/interface.h @@ -0,0 +1,26 @@ +/* + * interface.h + * + * Created on: 30.05.2012 + * Author: Thomas + */ + +#ifndef INTERFACE_H_ +#define INTERFACE_H_ + +#include +#include "../game/brett.h" + +class Interface +{ +public: + void ausgabe(brett* b); + void einlesen(int p); + void winner(int player); + + char p1a,p2a; + int p1b,p2b; +}; + + +#endif /* INTERFACE_H_ */ diff --git a/Chess/Interface/interfaceb.cpp b/Chess/Interface/interfaceb.cpp new file mode 100644 index 0000000..b6ee25d --- /dev/null +++ b/Chess/Interface/interfaceb.cpp @@ -0,0 +1,265 @@ +/* + * interfaceb.cpp + * + * Created on: 30.05.2012 + * Author: Thomas + */ + +#include "interfaceb.h" +#include "../game/brett.h" +#include +#include +#include +#include +#include +#include +#include + +Interfaceb::Interfaceb() +{ + + //Initalisiere SDL + int res=SDL_Init(SDL_INIT_VIDEO); + if (res!=0) + { + std::cout << "Fehler bei Initalisieren von SDL." << std::endl; + std::cin.get(); + std::exit(-1); + + } + + display=SDL_SetVideoMode(630,670,24,SDL_SWSURFACE); + if (display==NULL) + { + std::cout << "Fehler beim Erzeugen der Oberfläche." << std::endl; + std::cin.get(); + std::exit(-1); + } + + SDL_WM_SetCaption("Schach", "Schach"); + +} + +Interfaceb::~Interfaceb() +{ + if (display!=NULL) + { + SDL_FreeSurface(display); + } + SDL_Quit(); + +} + +void Interfaceb::einlesen(int p) +{ + if (TTF_Init()==-1) + { + std::cout << "Fehler beim Starten der Textausgabe." << std::endl; + std::cin.get(); + std::exit(-1); + } + + TTF_Font* font; + font=TTF_OpenFont("font/JOURNAL.ttf",24); + if (font==NULL) + { + std::cout << "Schrift konnte nicht geladen werden." << std::endl; + std::cin.get(); + std::exit(-1); + } + + char text[]="Spieler 1 am Zug!"; + text[8]=48+p; + + SDL_Color textcolor; + textcolor.r=0; + textcolor.g=0; + textcolor.b=0; + + SDL_Surface* nachricht=TTF_RenderText_Blended(font,text,textcolor); + + SDL_Rect bereich; + bereich.x=0; + bereich.y=0; + bereich.w=630; + bereich.h=20; + + SDL_BlitSurface(nachricht,NULL,display,&bereich); + SDL_UpdateRects(display,1,&bereich); + SDL_FreeSurface(nachricht); + + + bool exitLoop=false; + SDL_Rect mouse,start,ende; + + while (!exitLoop) + { + SDL_Event event; + + if (0==SDL_WaitEvent(&event)) + { + std::cout << "Fehler beim Warten auf Event." << std::endl; + std::cin.get(); + exitLoop=true; + } + + switch(event.type) + { + case SDL_MOUSEMOTION: + mouse.x=event.motion.x; + mouse.y=event.motion.y; + break; + case SDL_MOUSEBUTTONDOWN: + start=mouse; + break; + case SDL_MOUSEBUTTONUP: + ende=mouse; + exitLoop=true; + break; + case SDL_QUIT: + exitLoop=true; + std::exit(-1); + break; + default: + break; + } + } + + //std::cout << start.x << "-" << start.y << std::endl; + //std::cout << ende.x << "-" << ende.y << std::endl; + + int sx=(int) ((start.x-51)/66); if (start.x<51) { sx=10; } + int sy=(int) ((start.y-81)/66); if (start.y<81) { sy=10; } + int ex=(int) ((ende.x-51)/66); if (ende.x<51) { ex=10; } + int ey=(int) ((ende.y-81)/66); if (ende.y<81) { ey=10; } + + //std::cout << sx << "-" << sy << std::endl; + //std::cout << ex << "-" << ey << std::endl; + + p1a=char(int('a')+sx); + p1b=8-sy; + + p2a=char(int('a')+ex); + p2b=8-ey; + +} + + +void Interfaceb::winner(int player) +{ + if (TTF_Init()==-1) + { + std::cout << "Fehler beim Starten der Textausgabe." << std::endl; + std::cin.get(); + std::exit(-1); + } + + TTF_Font* font; + font=TTF_OpenFont("font/JOURNAL.ttf",90); + if (font==NULL) + { + std::cout << "Schrift konnte nicht geladen werden." << std::endl; + std::cin.get(); + std::exit(-1); + } + + char text[]="Spieler 1 hat gewonnen!"; + text[8]=48+player; + + SDL_Color textcolor; + textcolor.r=0; + textcolor.g=0; + textcolor.b=0; + + SDL_Surface* nachricht=TTF_RenderText_Blended(font,text,textcolor); + + SDL_Rect bereich; + bereich.x=50; + bereich.y=300; + bereich.w=530; + bereich.h=70; + + SDL_BlitSurface(nachricht,NULL,display,&bereich); + SDL_UpdateRects(display,1,&bereich); + SDL_FreeSurface(nachricht); + + bool exitLoop=false; + while (!exitLoop) + { + SDL_Event event; + + if (0==SDL_WaitEvent(&event)) + { + std::cout << "Fehler beim Warten auf Event." << std::endl; + std::cin.get(); + exitLoop=true; + } + + switch(event.type) + { + case SDL_QUIT: + exitLoop=true; + std::exit(-1); + break; + default: + break; + } + } +} + +void Interfaceb::ausgabe(brett* b) +{ + SDL_Surface* image=NULL; + + //Hintergrund einfügen + image = IMG_Load("image/feld.png"); + if (image==NULL) + { + std::cout << "Grafik nicht verfuegbar." << std::endl; + std::cin.get(); + std::exit(-1); + } + + SDL_BlitSurface(image,NULL,display,NULL); + SDL_FreeSurface(image); + for (int i=0;i<8;i++) + { + for (int j=0;j<8;j++) + { + char l=b->lese(j,i); + + if (l!=' ') + { + SDL_Surface* figur; + SDL_Rect bereich; + + char datei[]="image/bs.png"; + datei[6]=tolower(l); + + if (tolower(l)!=l) //Großbuchstabe->weiße Figur + { + datei[7]='w'; + } + + figur = IMG_Load(datei); + + if (figur==NULL) + { + std::cout << "Grafik nicht verfuegbar." << std::endl; + std::cin.get(); + std::exit(-1); + } + + bereich.x=59+j*66; + bereich.y=89+i*66; + bereich.w=50; + bereich.h=50; + + SDL_BlitSurface(figur,NULL,display,&bereich); + } + } + } + + SDL_Flip(display); + +} diff --git a/Chess/Interface/interfaceb.h b/Chess/Interface/interfaceb.h new file mode 100644 index 0000000..03d2243 --- /dev/null +++ b/Chess/Interface/interfaceb.h @@ -0,0 +1,34 @@ +/* + * interface.h + * + * Created on: 30.05.2012 + * Author: Thomas + */ + +#ifndef INTERFACEb_H_ +#define INTERFACEb_H_ + + +#include +#include +#include "../game/brett.h" + +class Interfaceb +{ +public: + void ausgabe(brett* b); + void einlesen(int p); + void winner(int player); + Interfaceb(); + ~Interfaceb(); + + char p1a,p2a; + int p1b,p2b; + +private: + SDL_Surface* display; + +}; + + +#endif /* INTERFACE_H_ */ diff --git a/Chess/Piece/bauer.cpp b/Chess/Piece/bauer.cpp new file mode 100644 index 0000000..b4ede86 --- /dev/null +++ b/Chess/Piece/bauer.cpp @@ -0,0 +1,67 @@ +/* + * bauer.cpp + * + * Created on: 31.05.2012 + * Author: Thomas + */ + +#include +#include +#include "bauer.h" + + +Bauer::~Bauer() +{ + +} + +bool Bauer::bewegungmoeglich(int a,int b,brett* brett) +{ + int deltay=std::abs(b-y); + int deltax=std::abs(a-x); + + + if (besitzer==1) + { + if ((bbesitzer(a,b)==0)) { return true;} + if ((y==6) && (deltax==0) && (deltay==2) && (brett->besitzer(a,b-1)==0) && (brett->besitzer(a,b)==0)) { return true; } + if ((bbesitzer(a,b)==2)) { return true; } + } + else + { + if ((b>y) && (deltax==0) && (deltay==1) && (brett->besitzer(a,b)==0)) { return true; } + if ((y==1) && (deltax==0) && (deltay==2) && (brett->besitzer(a,b-1)==0) && (brett->besitzer(a,b)==0)) { return true; } + if ((b>y) && (deltax==1) && (deltay==1) && (brett->besitzer(a,b)==1)) { return true; } + } + +return false; +} + /* + int deltay=std::abs(b-y); + int deltax=std::abs(a-x); + int yZugrichtung = (besitzer == 1) ? (-1) : (1); + int anderer = (besitzer ==1) ? (2) : (1); + + if ((b-y)*yZugrichtung>0) + { + if (deltax==0) + { + if ((deltay==1) && (brett->besitzer(a,b)==0)) { return true;} + if ((deltay==2) && ((y==6) || (y==1)) && (brett->besitzer(a,b-1)==0) && (brett->besitzer(a,b)==0)) { return true; } + } + + if ((deltax==1) && (deltay==1) && (brett->besitzer(a,b)==2)) + { + return true; + } + } + + return false; +}*/ + +Bauer::Bauer(int a,int b,int c):Piece(a,b,c) +{ + +} + + diff --git a/Chess/Piece/bauer.h b/Chess/Piece/bauer.h new file mode 100644 index 0000000..1dae39a --- /dev/null +++ b/Chess/Piece/bauer.h @@ -0,0 +1,22 @@ +/* + * bauer.h + * + * Created on: 31.05.2012 + * Author: Thomas + */ + +#ifndef BAUER_H_ +#define BAUER_H_ + +#include "piece.h" + +class Bauer : public Piece +{ +public: + Bauer(int a,int b,int c); + virtual bool bewegungmoeglich(int a,int b,brett* brett); + virtual ~Bauer(); +}; + + +#endif /* BAUER_H_ */ diff --git a/Chess/Piece/dame.cpp b/Chess/Piece/dame.cpp new file mode 100644 index 0000000..7002892 --- /dev/null +++ b/Chess/Piece/dame.cpp @@ -0,0 +1,66 @@ +/* + * dame.cpp + * + * Created on: 31.05.2012 + * Author: Thomas + */ + +#include +#include + +#include "dame.h" + + +Dame::~Dame() +{ + +} + +bool Dame::bewegungmoeglich(int a,int b,brett* brett) +{ + int deltay=std::abs(b-y); + int deltax=std::abs(a-x); + + //links-rechts + if ((deltax!=0) && (deltay==0)) + { + int richtung=(a-x)/deltax; + for (int j=1;jbesitzer(x+richtung*j,y)!=0) { return false; } + } + if (brett->besitzer(a,b)!=besitzer) { return true; } else { return false;} + } + + //vor-zurück + if ((deltax==0) && (deltay!=0)) + { + int richtung=(b-y)/deltay; + for (int j=1;jbesitzer(x,y+richtung*j)!=0) { return false; } + } + if (brett->besitzer(a,b)!=besitzer) { return true; } else { return false;} + } + + //diagonal + if (deltax==deltay) + { + int richtungx=(a-x)/deltax; + int richtungy=(b-y)/deltay; + for (int j=1;jbesitzer(x+richtungx*j,y+richtungy*j)!=0) { return false; } + } + if (brett->besitzer(a,b)!=besitzer) { return true; } else { return false;} + } + + return false; +} + +Dame::Dame(int a,int b,int c):Piece(a,b,c) +{ + +} + + diff --git a/Chess/Piece/dame.h b/Chess/Piece/dame.h new file mode 100644 index 0000000..7a9c251 --- /dev/null +++ b/Chess/Piece/dame.h @@ -0,0 +1,22 @@ +/* + * dame.h + * + * Created on: 31.05.2012 + * Author: Thomas + */ + +#ifndef DAME_H_ +#define DAME_H_ + +#include "piece.h" + +class Dame : public Piece +{ +public: + Dame(int a,int b,int c); + virtual bool bewegungmoeglich(int a,int b,brett* brett); + virtual ~Dame(); +}; + + +#endif /* DAME_H_ */ diff --git a/Chess/Piece/koenig.cpp b/Chess/Piece/koenig.cpp new file mode 100644 index 0000000..59f1558 --- /dev/null +++ b/Chess/Piece/koenig.cpp @@ -0,0 +1,34 @@ +/* + * koenig.cpp + * + * Created on: 31.05.2012 + * Author: Thomas + */ + +#include +#include + + +#include "koenig.h" + + +Koenig::~Koenig() +{ + +} + +bool Koenig::bewegungmoeglich(int a,int b,brett* brett) +{ + int deltay=std::abs(b-y); + int deltax=std::abs(a-x); + + if ((deltax<=1) && (deltay<=1) && (brett->besitzer(a,b)!=besitzer)) { return true; } +return false; +} + +Koenig::Koenig(int a,int b,int c):Piece(a,b,c) +{ + +} + + diff --git a/Chess/Piece/koenig.h b/Chess/Piece/koenig.h new file mode 100644 index 0000000..8175dcd --- /dev/null +++ b/Chess/Piece/koenig.h @@ -0,0 +1,22 @@ +/* + * koenig.h + * + * Created on: 31.05.2012 + * Author: Thomas + */ + +#ifndef KOENIG_H_ +#define KOENIG_H_ + +#include "piece.h" + +class Koenig : public Piece +{ +public: + Koenig(int a,int b,int c); + virtual bool bewegungmoeglich(int a,int b,brett* brett); + virtual ~Koenig(); +}; + + +#endif /* KOENIG_H_ */ diff --git a/Chess/Piece/lauefer.cpp b/Chess/Piece/lauefer.cpp new file mode 100644 index 0000000..1d2123e --- /dev/null +++ b/Chess/Piece/lauefer.cpp @@ -0,0 +1,45 @@ +/* + * lauefer.cpp + * + * Created on: 31.05.2012 + * Author: Thomas + */ + +#include +#include + + +#include "lauefer.h" + + +Laeufer::~Laeufer() +{ + +} + +bool Laeufer::bewegungmoeglich(int a,int b,brett* brett) +{ + int deltay=std::abs(b-y); + int deltax=std::abs(a-x); + + //diagonal + if (deltax==deltay) + { + int richtungx=(a-x)/deltax; + int richtungy=(b-y)/deltay; + for (int j=1;jbesitzer(x+richtungx*j,y+richtungy*j)!=0) { return false; } + } + if (brett->besitzer(a,b)!=besitzer) { return true; } else { return false;} + } + + return false; +} + +Laeufer::Laeufer(int a,int b,int c):Piece(a,b,c) +{ + +} + + diff --git a/Chess/Piece/lauefer.h b/Chess/Piece/lauefer.h new file mode 100644 index 0000000..a0c49c8 --- /dev/null +++ b/Chess/Piece/lauefer.h @@ -0,0 +1,22 @@ +/* + * lauefer.h + * + * Created on: 31.05.2012 + * Author: Thomas + */ + +#ifndef LAUEFER_H_ +#define LAUEFER_H_ + +#include "piece.h" + +class Laeufer : public Piece +{ +public: + Laeufer(int a,int b,int c); + virtual bool bewegungmoeglich(int a,int b,brett* brett); + virtual ~Laeufer(); +}; + + +#endif /* LAUEFER_H_ */ diff --git a/Chess/Piece/piece.cpp b/Chess/Piece/piece.cpp new file mode 100644 index 0000000..d31dc38 --- /dev/null +++ b/Chess/Piece/piece.cpp @@ -0,0 +1,52 @@ +/* + * piece.cpp + * + * Created on: 31.05.2012 + * Author: Thomas + */ + +#include + +#include "piece.h" +#include "../game/brett.h" + +Piece::Piece(int a,int b,int c) +{ + x=a; + y=b; + besitzer=c; + active=true; +} + +void Piece::geschlagen() +{ + active=false; +} + +bool Piece::IsPosition(int a,int b,int c) +{ + //std::cout << a << "=" << x << ";" << b << "=" << y << ";" << c << "=" << besitzer << std::endl; + + if ((a==x) && (b==y) && (c==besitzer) && (active==true)) + { + return true; + } + return false; +} + + +Piece::~Piece() +{ + +} + +typedef char foo[8]; +typedef foo bar[8]; +void Piece::move(int xn,int yn, brett* b) +{ + b->schreibe(xn,yn,b->lese(x,y)); + b->schreibe(x,y,' '); + x=xn; + y=yn; +} + diff --git a/Chess/Piece/piece.h b/Chess/Piece/piece.h new file mode 100644 index 0000000..de7fb6b --- /dev/null +++ b/Chess/Piece/piece.h @@ -0,0 +1,31 @@ +/* + * piece.h + * + * Created on: 31.05.2012 + * Author: Thomas + */ + +#ifndef PIECE_H_ +#define PIECE_H_ + +#include "../game/brett.h" + +class Piece +{ +public: + Piece(int a,int b,int c); + bool IsPosition(int a, int b, int c); + void move(int xn, int yn,brett* b); + void geschlagen(); + virtual bool bewegungmoeglich(int a,int b,brett* brett)=0; + virtual ~Piece(); +protected: + int x; + int y; + int besitzer; + bool active; + +}; + + +#endif /* PIECE_H_ */ diff --git a/Chess/Piece/springer.cpp b/Chess/Piece/springer.cpp new file mode 100644 index 0000000..1914a7a --- /dev/null +++ b/Chess/Piece/springer.cpp @@ -0,0 +1,34 @@ +/* + * bauer.cpp + * + * Created on: 31.05.2012 + * Author: Thomas + */ + +#include +#include + +#include "springer.h" + + +Springer::~Springer() +{ + +} + +bool Springer::bewegungmoeglich(int a,int b,brett* brett) +{ + int deltay=std::abs(b-y); + int deltax=std::abs(a-x); + + if ((deltax==2) && (deltay==1) && (brett->besitzer(a,b)!=besitzer)) { return true; } + if ((deltax==1) && (deltay==2) && (brett->besitzer(a,b)!=besitzer)) { return true; } +return false; +} + +Springer::Springer(int a,int b,int c):Piece(a,b,c) +{ + +} + + diff --git a/Chess/Piece/springer.h b/Chess/Piece/springer.h new file mode 100644 index 0000000..0e9138e --- /dev/null +++ b/Chess/Piece/springer.h @@ -0,0 +1,22 @@ +/* + * springer.h + * + * Created on: 31.05.2012 + * Author: Thomas + */ + +#ifndef SPRINGER_H_ +#define SPRINGER_H_ + +#include "piece.h" + +class Springer : public Piece +{ +public: + Springer(int a,int b,int c); + virtual bool bewegungmoeglich(int a,int b,brett* brett); + virtual ~Springer(); +}; + + +#endif /* BAUER_H_ */ diff --git a/Chess/Piece/turm.cpp b/Chess/Piece/turm.cpp new file mode 100644 index 0000000..9ca58ba --- /dev/null +++ b/Chess/Piece/turm.cpp @@ -0,0 +1,54 @@ +/* + * turm.cpp + * + * Created on: 31.05.2012 + * Author: Thomas + */ + +#include +#include + +#include "turm.h" + + +Turm::~Turm() +{ + +} + +bool Turm::bewegungmoeglich(int a,int b,brett* brett) +{ + int deltay=std::abs(b-y); + int deltax=std::abs(a-x); + + //links-rechts + if ((deltax!=0) && (deltay==0)) + { + int richtung=(a-x)/deltax; + for (int j=1;jbesitzer(x+richtung*j,y)!=0) { return false; } + } + if (brett->besitzer(a,b)!=besitzer) { return true; } else { return false;} + } + + //vor-zurück + if ((deltax==0) && (deltay!=0)) + { + int richtung=(b-y)/deltay; + for (int j=1;jbesitzer(x,y+richtung*j)!=0) { return false; } + } + if (brett->besitzer(a,b)!=besitzer) { return true; } else { return false;} + } + + return false; +} + +Turm::Turm(int a,int b,int c):Piece(a,b,c) +{ + +} + + diff --git a/Chess/Piece/turm.h b/Chess/Piece/turm.h new file mode 100644 index 0000000..3d8b2fd --- /dev/null +++ b/Chess/Piece/turm.h @@ -0,0 +1,22 @@ +/* + * turm.h + * + * Created on: 31.05.2012 + * Author: Thomas + */ + +#ifndef TURM_H_ +#define TURM_H_ + +#include "piece.h" + +class Turm : public Piece +{ +public: + Turm(int a,int b,int c); + virtual bool bewegungmoeglich(int a,int b,brett* brett); + virtual ~Turm(); +}; + + +#endif /* TURM_H_ */ diff --git a/Chess/chess.cpp b/Chess/chess.cpp new file mode 100644 index 0000000..53f6c37 --- /dev/null +++ b/Chess/chess.cpp @@ -0,0 +1,24 @@ +/* + * chess.cpp + * + * Created on: 30.05.2012 + * Author: Thomas + */ +#include +#include + +#include "Interface/interface.h" +#include "Interface/interfaceb.h" +#include "Game/game.h" + + +#ifdef _WIN32 +#include +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCMd) { +#else +int main() { +#endif + Game Spiel; + Spiel.zug(); + return true; +} diff --git a/Chess/font/JOURNAL.TTF b/Chess/font/JOURNAL.TTF new file mode 100644 index 0000000..7d88dad Binary files /dev/null and b/Chess/font/JOURNAL.TTF differ diff --git a/Chess/game/brett.cpp b/Chess/game/brett.cpp new file mode 100644 index 0000000..9b02a5b --- /dev/null +++ b/Chess/game/brett.cpp @@ -0,0 +1,65 @@ +/* + * brett.cpp + * + * Created on: 02.06.2012 + * Author: Thomas + */ + +#include +#include "brett.h" + +brett::brett() { + + for (int i=0;i<8;i++) + { + for (int j=0;j<8;j++) + { + f[8*i+j]=' '; + } + } +} + + +brett::~brett() { + +} + +char brett::lese(int x,int y) +{ + if ((x>=0) && (x<8) && (y>=0) && (y<8)) + { + int val=x+8*y; + char z=f[val]; + return z; + } + return '-'; +} + +bool brett::schreibe(int x,int y,char value) +{ + if ((x>=0) && (x<8) && (y>=0) && (y<8)) + { + f[x+8*y]=value; + return true; + } + return false; +} + +int brett::besitzer(int x,int y) +{ + // 0==> feld frei + // 1==> Spieler 1 + // 2==> Spieler 2 + // -1 ==> nicht auf Spielfeld + + if ((x>=0) && (x<8) && (y>=0) && (y<8)) + { + if (f[x+8*y]==' ') { return 0; } + if ((int(f[x+8*y])>='A') && (int(f[x+8*y]<='Z'))) { return 1; } + if ((int(f[x+8*y])>='a') && (int(f[x+8*y]<='z'))) { return 2; } + } + return -1; + +} + + diff --git a/Chess/game/brett.h b/Chess/game/brett.h new file mode 100644 index 0000000..5eaae38 --- /dev/null +++ b/Chess/game/brett.h @@ -0,0 +1,24 @@ +/* + * brett.h + * + * Created on: 02.06.2012 + * Author: Thomas + */ + +#ifndef BRETT_H_ +#define BRETT_H_ + +#include "../game/brett.h" + +class brett { +private: + char f[64]; +public: + brett(); + ~brett(); + char lese(int x,int y); + bool schreibe(int x,int y,char value); + int besitzer(int x,int y); +}; + +#endif /* BRETT_H_ */ diff --git a/Chess/game/game.cpp b/Chess/game/game.cpp new file mode 100644 index 0000000..c2de051 --- /dev/null +++ b/Chess/game/game.cpp @@ -0,0 +1,153 @@ +/* + * game.cpp + * + * Created on: 30.05.2012 + * Author: Thomas + */ + +#include + +#include "game.h" +#include "brett.h" +#include "../Piece/piece.h" +#include "../Piece/bauer.h" +#include "../Piece/dame.h" +#include "../Piece/koenig.h" +#include "../Piece/lauefer.h" +#include "../Piece/springer.h" +#include "../Piece/turm.h" + + + +Game::Game() +{ + b=new brett(); + for (int i=0;i<8;i++) + { + b->schreibe(i,1,'b'); + figur[i]=new Bauer(i,1,2); + b->schreibe(i,6,'B'); + figur[i+8]=new Bauer(i,6,1); + } + + b->schreibe(0,0,'t'); figur[16]=new Turm(0,0,2); + b->schreibe(1,0,'s'); figur[17]=new Springer(1,0,2); + b->schreibe(2,0,'l'); figur[18]=new Laeufer(2,0,2); + b->schreibe(3,0,'d'); figur[19]=new Dame(3,0,2); + b->schreibe(4,0,'k'); figur[20]=new Koenig(4,0,2); + b->schreibe(5,0,'l'); figur[21]=new Laeufer(5,0,2); + b->schreibe(6,0,'s'); figur[22]=new Springer(6,0,2); + b->schreibe(7,0,'t'); figur[23]=new Turm(7,0,2); + + b->schreibe(0,7,'T'); figur[24]=new Turm(0,7,1); + b->schreibe(1,7,'S'); figur[25]=new Springer(1,7,1); + b->schreibe(2,7,'L'); figur[26]=new Laeufer(2,7,1); + b->schreibe(3,7,'D'); figur[27]=new Dame(3,7,1); + b->schreibe(4,7,'K'); figur[28]=new Koenig(4,7,1); + b->schreibe(5,7,'L'); figur[29]=new Laeufer(5,7,1); + b->schreibe(6,7,'S'); figur[30]=new Springer(6,7,1); + b->schreibe(7,7,'T'); figur[31]=new Turm(7,7,1); + + end=false; + activeplayer=1; + + aus.ausgabe(b); + return; +} + +Game::~Game() +{ + delete b; +} + +void Game::zug() +{ + do + { + do + { + aus.einlesen(activeplayer); + } + while (aendern(aus.p1a,aus.p1b,aus.p2a,aus.p2b)==false); + + aus.ausgabe(b); + + //Überprüfe,ob König vorhanden + bool k1=false; + bool k2=false; + + for (int i=0;i<8;i++) + { + for (int j=0;j<8;j++) + { + if (b->lese(i,j)=='K') { k1=true; } + if (b->lese(i,j)=='k') { k2=true; } + } + } + + if ((k1==false) || (k2==false)) + { + end=true; + aus.winner(activeplayer); + std::cout << "Spieler " << activeplayer << " hat gewonnen." << std::endl; + } + + //Spieler ändern + activeplayer++; + if (activeplayer==3) { activeplayer=1; } + + } + while (end==false); +} + +int Game::aendern(char a,int be,char c,int d) +{ + int x1=int(a)-'a'; + int x2=int(c)-'a'; + int y1=8-be; + int y2=8-d; + + //std::cout << x1 << "/" << y1 << " to " << x2 << "/" << y2 << std::endl; + + int nummer=-1; + for (int i=0;i<32;i++) + { + if (figur[i]->IsPosition(x1,y1,activeplayer)==true) + { + nummer=i; + } + } + //std::cout << "Nummer: " << nummer << std::endl; + if (nummer==-1) { return false; } + + if ((x1==x2) && (y1==y2)) { return false; } + + if ((x1<0) || (x1>7)) { return false; } + if ((x2<0) || (x2>7)) { return false; } + if ((y1<0) || (y1>7)) { return false; } + if ((y2<0) || (y2>7)) { return false; } + + if (figur[nummer]->bewegungmoeglich(x2,y2,b)==false) + { + return false; + } + + //Auf geschlagene Figuren untersuchen + int anderer; + if (activeplayer==1) { anderer=2; } else { anderer=1; } + for (int i=0;i<32;i++) + { + if (figur[i]->IsPosition(x2,y2,anderer)==true) + { + figur[i]->geschlagen(); + } + } + + + figur[nummer]->move(x2,y2,b); + return true; +} + + + + diff --git a/Chess/game/game.h b/Chess/game/game.h new file mode 100644 index 0000000..551cd93 --- /dev/null +++ b/Chess/game/game.h @@ -0,0 +1,33 @@ +/* + * game.h + * + * Created on: 30.05.2012 + * Author: Thomas + */ + +#ifndef GAME_H_ +#define GAME_H_ + +#include "../Interface/interface.h" +#include "../Interface/interfaceb.h" +#include "../Piece/piece.h" +#include "brett.h" + +class Game +{ +private: + brett* b; + Interfaceb aus; + int activeplayer; + bool end; + int besitzer(int x,int y); + Piece *figur[32]; + +public: + Game(); + void zug(); + int aendern(char a,int b,char c,int d); + ~Game(); +}; + +#endif /* GAME_H_ */ diff --git a/Chess/image/bs.png b/Chess/image/bs.png new file mode 100644 index 0000000..f97f7b5 Binary files /dev/null and b/Chess/image/bs.png differ diff --git a/Chess/image/bw.png b/Chess/image/bw.png new file mode 100644 index 0000000..d96c849 Binary files /dev/null and b/Chess/image/bw.png differ diff --git a/Chess/image/ds.png b/Chess/image/ds.png new file mode 100644 index 0000000..57dcc7b Binary files /dev/null and b/Chess/image/ds.png differ diff --git a/Chess/image/dw.png b/Chess/image/dw.png new file mode 100644 index 0000000..0d84523 Binary files /dev/null and b/Chess/image/dw.png differ diff --git a/Chess/image/feld.png b/Chess/image/feld.png new file mode 100644 index 0000000..d74c5e9 Binary files /dev/null and b/Chess/image/feld.png differ diff --git a/Chess/image/ks.png b/Chess/image/ks.png new file mode 100644 index 0000000..51318df Binary files /dev/null and b/Chess/image/ks.png differ diff --git a/Chess/image/kw.png b/Chess/image/kw.png new file mode 100644 index 0000000..0a8ffc0 Binary files /dev/null and b/Chess/image/kw.png differ diff --git a/Chess/image/ls.png b/Chess/image/ls.png new file mode 100644 index 0000000..ea92b13 Binary files /dev/null and b/Chess/image/ls.png differ diff --git a/Chess/image/lw.png b/Chess/image/lw.png new file mode 100644 index 0000000..6c93058 Binary files /dev/null and b/Chess/image/lw.png differ diff --git a/Chess/image/ss.png b/Chess/image/ss.png new file mode 100644 index 0000000..e55edae Binary files /dev/null and b/Chess/image/ss.png differ diff --git a/Chess/image/sw.png b/Chess/image/sw.png new file mode 100644 index 0000000..7c8a102 Binary files /dev/null and b/Chess/image/sw.png differ diff --git a/Chess/image/ts.png b/Chess/image/ts.png new file mode 100644 index 0000000..18e80ab Binary files /dev/null and b/Chess/image/ts.png differ diff --git a/Chess/image/tw.png b/Chess/image/tw.png new file mode 100644 index 0000000..6a2119d Binary files /dev/null and b/Chess/image/tw.png differ diff --git a/planung.jpg b/planung.jpg new file mode 100644 index 0000000..f2308e7 Binary files /dev/null and b/planung.jpg differ