Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <iomanip>
- using namespace std;
- void help ()
- {
- int c=0;
- c=getchar();
- if (c == '?')
- {
- cout<<"Dostepne operacje:"<<endl;
- cout<<"ESC-wyjscie z gry"<<endl;
- cout<<"'?' - pomoc"<<endl;
- }
- }
- void plansza (char t[30][30], int szer, int wys)
- {
- for(int a=1; a<=szer; a++)
- {
- cout<<a<<" ";
- }
- cout<<endl;
- for (int i=1; i<=wys; i++)
- {
- for(int j=1; j<=szer; j++)
- {
- cout<<t[i][j]<<"|";
- }
- cout<<endl;
- }
- }
- void ruch (char t[30][30], int szer, int wys, char gracz)
- {
- plansza(t, szer, wys);
- int r=0;
- if (gracz=='O')
- {
- cout<<"Ruch gracza O"<<" ";
- }
- else
- {
- cout<<"Ruch gracza X"<<" ";
- }
- cin>>r;
- if((r>=1)&&(r<=szer)&&(t[1][r]!='X')&&(t[1][r]!='O'))
- {
- for(int j=wys; j>0; j--)
- {
- if (t[j][r]==' ')
- {
- t[j][r] = gracz;
- break;
- }
- }
- }
- else
- {
- cout<<"Zly ruch"<<endl;
- ruch(t, szer, wys, gracz);
- }
- cout<<endl<<endl;
- }
- bool winPozX(char t[30][30], int lp, int szer, int wys)
- {
- int a=0;
- for (int i=1; i<=wys; i++)
- {
- for(int j=1; j<=szer; j++)
- {
- for(int b=1; b<lp; b++)
- {
- if ((t[i][j]=='X')&&(t[i][j+b]=='X'))
- {
- a++;
- }
- else
- {
- break;
- }
- }
- }
- }
- if (a>=lp)
- {
- cout<<"Zwyciestwo gracza X!"<<endl;
- return true;
- }
- return false;
- }
- bool winPozO(char t[30][30], int lp, int szer, int wys)
- {
- int a=0;
- for (int i=1; i<=wys; i++)
- {
- for(int j=1; j<=szer; j++)
- {
- for(int b=1; b<lp; b++)
- {
- if ((t[i][j]=='O')&&(t[i][j+b]=='O'))
- {
- a++;
- }
- else
- {
- break;
- }
- }
- }
- }
- if (a>=lp)
- {
- cout<<"Zwyciestwo gracza O!"<<endl;
- return true;
- }
- return false;
- }
- bool winPionX(char t[30][30], int lp, int szer, int wys)
- {
- int a=0;
- for (int i=0; i<wys; i++)
- {
- for(int j=0; j<szer; j++)
- {
- for(int b=1; b<lp; b++)
- {
- if ((t[i][j]=='X')&&(t[i+b][j]=='X'))
- {
- a++;
- }
- else break;
- }
- }
- }
- if (a>=lp)
- {
- cout<<"Zwyciestwo gracza X!"<<endl;
- return true;
- }
- return false;
- }
- bool winPionO(char t[30][30], int lp, int szer, int wys)
- {
- int a=0;
- for (int i=0; i<wys; i++)
- {
- for(int j=0; j<szer; j++)
- {
- for(int b=1; b<lp; b++)
- if ((t[i][j]=='O')&&(t[i+b][j]=='O'))
- {
- a++;
- }
- else break;
- }
- }
- if (a>=lp)
- {
- cout<<"Zwyciestwo gracza O!"<<endl;
- return true;
- }
- return false;
- }
- bool winSkosDolX(char t[30][30], int lp, int szer, int wys)
- {
- int a=0;
- for (int i=0; i<wys; i++)
- {
- for(int j=0; j<szer; j++)
- {
- for(int b=1; b<lp; b++)
- {
- if ((t[i][j]=='X')&&(t[i+b][j+b]=='X'))
- {
- a++;
- }
- else break;
- }
- }
- }
- if (a>=lp)
- {
- cout<<"Zwyciestwo gracza X!"<<endl;
- return true;
- }
- return false;
- }
- bool winSkosDolO(char t[30][30], int lp, int szer, int wys)
- {
- int a=0;
- for (int i=0; i<wys; i++)
- {
- for(int j=0; j<szer; j++)
- {
- for(int b=1; b<lp; b++)
- {
- if ((t[i][j]=='O')&&(t[i+b][j+b]=='O'))
- {
- a++;
- }
- else break;
- }
- }
- }
- if (a>=lp)
- {
- cout<<"Zwyciestwo gracza O!"<<endl;
- return true;
- }
- return false;
- }
- bool winSkosGoraX(char t[30][30], int lp, int szer, int wys)
- {
- int a=0;
- for (int i=0; i<wys; i++)
- {
- for(int j=0; j<szer; j++)
- {
- for(int b=1; b<lp; b++)
- {
- if ((t[i][j]=='X')&&(t[i-b][j+b]=='X'))
- {
- a++;
- }
- else break;
- }
- }
- }
- if (a>=lp)
- {
- cout<<"Zwyciestwo gracza X!"<<endl;
- return true;
- }
- return false;
- }
- bool winSkosGoraO(char t[30][30], int lp, int szer, int wys)
- {
- int a=0;
- for (int i=0; i<wys; i++)
- {
- for(int j=0; j<szer; j++)
- {
- for(int b=1; b<lp; b++)
- {
- if ((t[i][j]=='O')&&(t[i-b][j+b]=='O'))
- {
- a++;
- }
- else break;
- }
- }
- }
- if (a>=lp)
- {
- cout<<"Zwyciestwo gracza O!"<<endl;
- return true;
- }
- return false;
- }
- bool remis (char t[30][30], int lp, int szer, int wys)
- {
- if ((winPozX(t, lp, szer, wys)==false)&&(winPozO(t, lp, szer, wys)==false)&&(winPionX(t, lp, szer, wys)==false)&&(winPionO(t, lp, szer, wys)==false)
- &&(winSkosDolX(t, lp, szer, wys)==false)&&(winSkosDolO(t, lp, szer, wys)==false)&&(winSkosGoraX(t, lp, szer, wys)==false)&&(winSkosGoraO(t, lp, szer, wys)==false))
- {
- cout<<"Remis!"<<endl;
- return true;
- }
- else return false;
- }
- int main()
- {
- do
- {
- int wys, szer, lp;
- int c;
- char t[30][30];
- char g;
- int liczbar=0;
- int k=0;
- while
- cout<<"Witaj w tej prostej grze, zanim zaczniemy nalezy podac nastepujace dane:"<<endl;
- cout<<"Wysokosc planszy (1,30)"<<" ";
- cin>>wys;
- cout<<endl;
- cout<<"Szerokosc planszy(1,30)"<<" ";
- cin>>szer;
- cout<<endl;
- cout<<"Liczba punktow potrzebna do zwyciestwa"<<" ";
- cin>>lp;
- cout<<endl;
- liczbar=szer*wys;
- if((szer>=1)&&(szer<=30)&&(wys>=1)&&(wys<=30)&&(lp>=1)&&(lp<=liczbar))
- {
- for (int i=1; i<=wys; i++)
- {
- for(int j=1; j<=szer; j++)
- {
- t[i][j]=' ';
- }
- cout<<endl;
- }
- for (int a=0; a<liczbar; a++)
- {
- if (a%2==1) g='X';
- else g='O';
- if((winPozX(t, lp, szer, wys)==false)&&(winPozO(t, lp, szer, wys)==false)&&(winPionX(t, lp, szer, wys)==false)&&(winPionO(t, lp, szer, wys)==false)
- &&(winSkosDolX(t, lp, szer, wys)==false)&&(winSkosDolO(t, lp, szer, wys)==false)&&(winSkosGoraX(t, lp, szer, wys)==false)&&(winSkosGoraO(t, lp, szer, wys)==false))
- {
- ruch(t, szer, wys, g);
- }
- else
- {
- plansza(t, szer, wys);
- return 0;
- }
- }
- remis(t, lp, szer, wys);
- } while
- cout<<"Koniec gry"<<endl;
- }
- else cout<<"Zle dane"<<endl;
- koniec:
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement