Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int a,b;
- void bicie(char plansza[][8],char wybor,int a, int b);
- void rysuj_plansze(char plansza[][8], char wybor)
- {
- for(int i=0; i<8; i++)
- {
- cout << " " << i+1;
- }
- cout << " Ruch "<<wybor <<endl ;
- for(int i=0; i<8; i++)
- {
- cout << i+1;
- if(plansza[i][0]=='C')
- {
- cout << "[C]";
- }
- else if(plansza[i][0]=='B')
- {
- cout << "[B]";
- }
- else if (plansza[i][0]==' ')
- {
- cout<< "[ ]";
- }
- else if (plansza[i][0]=='a')
- {
- cout<< "[1]";
- }
- else if (plansza[i][0]=='b')
- {
- cout<< "[2]";
- }
- else if (plansza[i][0]=='c')
- {
- cout<< "[3]";
- }
- else if (plansza[i][0]=='d')
- {
- cout<< "[4]";
- }
- for(int j=1; j<8; j++)
- {
- if(plansza[i][j]=='C')
- {
- cout << "[C]";
- }
- else if(plansza[i][j]=='B')
- {
- cout << "[B]";
- }
- else if(plansza[i][j]==' ')
- {
- cout << "[ ]";
- }
- else if (plansza[i][j]=='a')
- {
- cout << "[1]";
- }
- else if (plansza[i][j]=='b')
- {
- cout << "[2]";
- }
- else if (plansza[i][j]=='c')
- {
- cout << "[3]";
- }
- else if (plansza[i][j]=='d')
- {
- cout << "[4]";
- }
- }
- cout <<endl;
- }
- }
- void biale(char plansza[][8])
- {
- int i,j,k=0;
- for( i=0,j=0; k<12;)
- {
- plansza[i][j]='B';
- j+=2;
- if(j==8)
- {
- j=1;
- i++;
- }
- else if(j==9)
- {
- j=0;
- i++;
- }
- k++;
- }
- }
- void czarne(char plansza[][8])
- {
- int i,j,k=0;
- for( i=7,j=7; k<12;)
- {
- plansza[i][j]='C';
- j=j-2;
- if(j==-2)
- {
- j=7;
- i--;
- }
- else if(j==-1)
- {
- j=6;
- i--;
- }
- k++;
- }
- }
- void nowa_gra(char plansza[][8])
- {
- for(int i=0; i<8; i++)
- {
- plansza[i][0]=' ';
- for(int j=1; j<8; j++)
- {
- plansza[i][j]=' ';
- }
- }
- //biale(plansza);
- //czarne(plansza);
- plansza[3][3]='B';
- plansza[3][5]='B';
- plansza[4][4]='C';
- }
- void sprawdz_plansze(char plansza[][8]) // ta funkcja sprawdza jaka wartosc przyjmuje poszczegolna plansza[][].
- {
- for(int i=0; i<8;i++)
- {
- char ocb;
- ocb=plansza[i][0];
- cout<< " plansza["<<i<<"][0]= "<< ocb;
- cout<< endl;
- for(int j=1; j<8;j++)
- {
- ocb=plansza[i][j];
- cout<< " plansza["<<i<<"]["<<j<<"]= "<< ocb;
- cout << endl;
- }
- }
- }
- void wybor_kapsla(char plansza[][8],char wybor) // ta funkcja jest zaimplementowana bezposrednio w ruchu, na ta chwile nie potrafie korzystac z niej bezposrednio w innej funkcji.
- {
- int a,b;
- if(wybor=='B')
- {
- cout << "Wybierz kapsel: Ruch: Bia³y" ;
- }
- if(wybor=='C')
- {
- cout << "Wybierz kapsel: Ruch: Czerwony" ;
- }
- cin >> a >> b;
- a-=1;
- b-=1;
- plansza[a][b]=wybor;
- }
- void ruch_B(char plansza[][8],char wybor)
- {
- /////////////////wybor kapsla/////////////////////////////////////
- int a,b;
- char tymczas_a,tymczas_b;
- do
- {
- cout << "Wybierz kapsel: ";
- cin >> a >> b;
- a-=1;
- b-=1;
- if(plansza[a+1][b-1]!=' '&& plansza[a+1][b-1]==wybor && plansza[a+1][b+1]!=' ' && plansza[a+1][b+1]==wybor ||
- b==0 && plansza[a+1][b+1]!=' ' && plansza[a+1][b+1]==wybor || b==7 && plansza[a+1][b-1]!=' ' && plansza[a+1][b-1]==wybor)
- {
- cout<< "Nie mozesz ruszyc sie tym kapslem..." << endl;
- }
- else if(plansza[a][b]==' ')
- {
- cout << "Wybrales puste pole" <<endl;
- }
- }
- while(plansza[a+1][b-1]!=' ' && plansza[a+1][b-1]==wybor && plansza[a+1][b+1]!=' ' && plansza[a+1][b+1]==wybor ||
- b==0 && plansza[a+1][b+1]!=' ' && plansza[a+1][b+1]==wybor ||
- b==7 && plansza[a+1][b-1]!=' ' && plansza[a+1][b-1]==wybor ||
- plansza[a][b]==' ');
- plansza[a][b]=wybor;
- ////zajmuje tymczasowe miejsce miejsc na planszy zeby pozniej je oddac //////
- tymczas_a=plansza[a+1][b-1];
- tymczas_b=plansza[a+1][b+1];
- //////////Jeśli bedzie bicie to ta komedna pomija zaznaczanie ruchu pionka//////
- if(plansza[a-1][b-1]!=wybor && plansza[a-1][b-1]!=' '||plansza[a-1][b+1]!=wybor && plansza[a-1][b+1]!=' ' ||
- plansza[a+1][b-1]!=wybor && plansza[a+1][b-1]!=' ' ||plansza[a+1][b+1]!=wybor && plansza[a+1][b+1]!=' ' )
- {
- if(plansza[a-2][b-2]==' ' ||plansza[a-2][b+2]==' ' ||
- plansza[a+2][b-2]==' ' ||plansza[a+2][b+2]==' ' )
- {
- return;
- }
- }
- //////Zaznaczamy na planszy jak moze ruszac sie kapsel/////////////////////////////
- if(plansza[a+1][b-1]==' ' && plansza[a+1][b+1]==' ' && b>0 && b<7)
- {
- plansza[a+1][b-1]='a';
- plansza[a+1][b+1]='b';
- }
- else if(plansza[a+1][b-1]!=' '|| b==0)
- {
- plansza[a+1][b+1]='b';
- }
- else if(plansza[a+1][b+1]!=' ' || b==7)
- {
- plansza[a+1][b-1]='a';
- }
- //////////////////////
- /////////////////ruch/////////////////////////////////////////////
- int rusz_sie;
- cout << "gdzie chcesz sie ruszyc? "<< endl;
- rysuj_plansze(plansza, wybor);
- ////////// oddaje tymczasowe //////////////
- plansza[a+1][b-1]=tymczas_a;
- plansza[a+1][b+1]=tymczas_b;
- //////////////////////////////////////////
- cin>> rusz_sie;
- ////////////////wybiera pole ktore nie jest zajete///////////////////////////////////////
- if(plansza[a+1][b-1]!=' ' || b==0)
- {
- switch (rusz_sie)
- {
- case 2:
- {
- plansza[a][b]=' ';
- plansza[a+1][b+1]=wybor;
- }
- break;
- default: cout << "nie mozesz tego zrobic." << endl;
- }
- }
- else if(plansza[a+1][b+1]!=' ' || b==7)
- {
- switch (rusz_sie)
- {
- case 1:
- {
- plansza[a][b]=' ';
- plansza[a+1][b-1]=wybor;
- }
- break;
- }
- }
- else
- {
- switch (rusz_sie)
- {
- case 2:
- if (plansza[a+1][b+1]==' ')
- {
- plansza[a][b]=' ';
- plansza[a+1][b+1]=wybor;
- }
- else cout << "Nie mozesz tego zrobic.";
- break;
- case 1:
- if (plansza[a+1][b-1]==' ')
- {
- plansza[a][b]=' ';
- plansza[a+1][b-1]=wybor;
- }
- else cout << "Nie mozesz tego zrobic.";
- break;
- }
- }
- /////////////////////////////////////////////////////////////////////////
- }
- void ruch_C(char plansza[][8],char wybor)
- {
- /////////////////wybor kapsla/////////////////////////////////////
- //int a,b;
- char tymczas_a,tymczas_b;
- do
- {
- cout << "Wybierz kapsel: ";
- cin >> a >> b;
- a-=1;
- b-=1;
- if(plansza[a-1][b-1]!=' '&& plansza[a-1][b-1]==wybor && plansza[a-1][b+1]!=' ' && plansza[a-1][b+1]==wybor ||
- b==0 && plansza[a-1][b+1]!=' ' && plansza[a-1][b+1]==wybor || b==7 && plansza[a-1][b-1]!=' ' && plansza[a-1][b-1]==wybor)
- {
- cout<< "Nie mozesz ruszyc sie tym kapslem..." << endl;
- }
- else if(plansza[a][b]==' ')
- {
- cout << "Wybrales puste pole" <<endl;
- }
- }
- while(plansza[a-1][b-1]!=' '&& plansza[a-1][b-1]==wybor && plansza[a-1][b+1]!=' '&& plansza[a-1][b+1]==wybor ||
- b==0 && plansza[a-1][b+1]!=' '&& plansza[a-1][b+1]==wybor||
- b==7 && plansza[a-1][b-1]!=' '&& plansza[a-1][b-1]==wybor||
- plansza[a][b]==' ');
- plansza[a][b]=wybor;
- ////zajmuje tymczasowe miejsce miejsc na planszy zeby pozniej je oddac //////
- tymczas_a=plansza[a-1][b-1];
- tymczas_b=plansza[a-1][b+1];
- //////////Jeśli bedzie bicie to ta komedna pomija zaznaczanie ruchu pionka//////
- if(plansza[a-1][b-1]!=wybor && plansza[a-1][b-1]!=' '||plansza[a-1][b+1]!=wybor && plansza[a-1][b+1]!=' ' ||
- plansza[a+1][b-1]!=wybor && plansza[a+1][b-1]!=' ' ||plansza[a+1][b+1]!=wybor && plansza[a+1][b+1]!=' ' )
- {
- if(plansza[a-2][b-2]==' ' ||plansza[a-2][b+2]==' ' ||
- plansza[a+2][b-2]==' ' ||plansza[a+2][b+2]==' ' )
- {
- return;
- }
- }
- //////Zaznaczamy na planszy jak moze ruszac sie kapsel/////////////////////////////
- if(plansza[a-1][b-1]==' ' && plansza[a-1][b+1]==' ' && b>0 && b<7)
- {
- plansza[a-1][b-1]='a';
- plansza[a-1][b+1]='b';
- }
- else if(plansza[a-1][b-1]!=' '|| b==0)
- {
- plansza[a-1][b+1]='b';
- }
- else if(plansza[a-1][b+1]!=' ' || b==7)
- {
- plansza[a-1][b-1]='a';
- }
- //////////////////////
- /////////////////ruch/////////////////////////////////////////////
- int rusz_sie;
- cout << "gdzie chcesz sie ruszyc? "<< endl;
- rysuj_plansze(plansza,wybor);
- ////////// oddaje tymczasowe //////////////
- plansza[a-1][b-1]=tymczas_a;
- plansza[a-1][b+1]=tymczas_b;
- //////////////////////////////////////////
- cin>> rusz_sie;
- ////////////////wybiera pole ktore nie jest zajete///////////////////////////////////////
- if(plansza[a-1][b-1]!=' ' || b==0)
- {
- switch (rusz_sie)
- {
- case 2:
- {
- plansza[a][b]=' ';
- plansza[a-1][b+1]=wybor;
- }
- break;
- default: cout << "nie mozesz tego zrobic." << endl;
- }
- }
- else if(plansza[a-1][b+1]!=' ' || b==7)
- {
- switch (rusz_sie)
- {
- case 1:
- {
- plansza[a][b]=' ';
- plansza[a-1][b-1]=wybor;
- }
- break;
- }
- }
- else
- {
- switch (rusz_sie)
- {
- case 2:
- if (plansza[a-1][b+1]==' ')
- {
- plansza[a][b]=' ';
- plansza[a-1][b+1]=wybor;
- }
- else cout << "Nie mozesz tego zrobic.";
- break;
- case 1:
- if (plansza[a-1][b-1]==' ')
- {
- plansza[a][b]=' ';
- plansza[a-1][b-1]=wybor;
- }
- else cout << "Nie mozesz tego zrobic.";
- break;
- }
- }
- /////////////////////////////////////////////////////////////////////////
- }
- void bicie(char plansza[][8],char wybor,int a, int b)
- {
- int ruch;
- if(plansza[a-1][b-1]!=wybor ||plansza[a-1][b+1]!=wybor ||
- plansza[a+1][b-1]!=wybor ||plansza[a+1][b+1]!=wybor )
- {
- if(plansza[a-2][b-2]==' ' ||plansza[a-2][b+2]==' ' ||
- plansza[a+2][b-2]==' ' ||plansza[a+2][b+2]==' ' )
- {
- char tymczas_a,tymczas_b,tymczas_c,tymczas_d;
- tymczas_a = plansza[a-2][b-2];
- tymczas_b = plansza[a-2][b+2];
- tymczas_c = plansza[a+2][b-2];
- tymczas_d = plansza[a+2][b+2];
- if(b>0 && b<7 && plansza[a-2][b-2]==' ' && plansza[a-1][b-1]!=wybor && plansza[a-1][b-1]!=' ')
- {
- plansza[a-2][b-2]='a';
- }
- if(b>0 && b<7 && plansza[a-2][b+2]==' ' && plansza[a-1][b+1]!=wybor && plansza[a-1][b+1]!=' ')
- {
- plansza[a-2][b+2]='b';
- }
- if(b>0 && b<7 && plansza[a+2][b-2]==' ' && plansza[a+1][b-1]!=wybor && plansza[a+1][b-1]!=' ')
- {
- plansza[a+2][b-2]='c';
- }
- if(b>0 && b<7 && plansza[a+2][b+2]==' ' && plansza[a+1][b+1]!=wybor && plansza[a+1][b+1]!=' ')
- {
- plansza[a+2][b+2]='d';
- }
- rysuj_plansze(plansza,wybor);
- cout << "gdzie bicie? "<< endl;
- //// oddaje tymczasowe ////////////////////
- // plansza[a-2][b-2] = tymczas_a;
- // plansza[a-2][b+2] = tymczas_b;
- // plansza[a+2][b-2] = tymczas_c;
- // plansza[a+2][b+2] = tymczas_d;
- /////////////////////////////////////////////
- // cin >> ruch;
- /*
- switch (ruch)
- {
- case 1:
- if(plansza[a-2][b-2]==' ')
- {
- plansza[a-2][b-2]=wybor;
- }
- case 2:
- if(plansza[a-2][b+2]==' ')
- {
- plansza[a-2][b+2]=wybor;
- }
- case 3:
- if(plansza[a+2][b-2]==' ')
- {
- plansza[a+2][b-2]=wybor;
- }
- case 4:
- if(plansza[a+2][b+2]==' ')
- {
- plansza[a+2][b+2]=wybor;
- }
- break;
- }*/
- }
- }
- }
- int main()
- {
- char plansza [8][8];
- char wybor='B';
- nowa_gra(plansza);
- //biale(plansza);
- //rysuj_plansze(plansza, wybor);
- //wybor_kapsla(plansza,wybor);
- while(1)
- {
- wybor='B';
- rysuj_plansze(plansza, wybor);
- ruch_B(plansza,wybor);
- bicie(plansza,wybor,a,b);
- rysuj_plansze(plansza, wybor);
- wybor='C';
- rysuj_plansze(plansza, wybor);
- ruch_C(plansza,wybor);
- bicie(plansza,wybor,a,b);
- rysuj_plansze(plansza, wybor);
- //sprawdz_plansze(plansza);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment