Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <time.h>
  4. #include <windows.h>
  5. #include <string.h>
  6.  
  7. using namespace std;
  8. string pole[9][9];
  9. void wyswietlenie_planszy();
  10. void ustawienie_pionkow();
  11. void wylosowanie_gracza();
  12. void ruszaj(int x,int y);
  13. void system();
  14. int Gracz1,Gracz2;
  15. int wybor1,wybor2;
  16. bool gra=true;
  17. bool ruch_gra1=true,ruch_gra2=true;
  18.  
  19. int main()
  20. {
  21.     for(int y=0; y<=8; y++)
  22.     {
  23.         for(int x=0; x<=8; x++)
  24.         {
  25.         pole[x][y]=" ";
  26.         }
  27.  
  28.     }
  29.     ustawienie_pionkow();
  30.     wyswietlenie_planszy();
  31.     wylosowanie_gracza();
  32.     system();
  33.  
  34.     return 0;
  35. }
  36. void wyswietlenie_planszy()
  37. {
  38.  for(int y=1; y<=8; y++)
  39.  {
  40.      if(y>=2&&y<=8)
  41.      {
  42.          cout<<endl;
  43.          cout<<"------------------------"<<endl;
  44.      }
  45.      for(int x=1; x<=8; x++)
  46.      {
  47.          cout<<"|"<<pole[x][y]<<"|";
  48.      }
  49.  }
  50.  cout<<endl;
  51. }
  52. void ustawienie_pionkow()
  53. {
  54.     for (int x=1; x<=7; x+=2)
  55.     {
  56.         pole[x][1]="x";
  57.         pole[x][3]="x";
  58.         pole[x][7]="W";
  59.     }
  60.     for (int x=2; x<=8; x+=2)
  61.     {
  62.         pole[x][2]="x";
  63.         pole[x][6]="kr1";
  64.         pole[x][8]="W";
  65.     }
  66. }
  67. void wylosowanie_gracza()
  68. {
  69.     srand(time(NULL));
  70.     Gracz1=rand()%2+1;
  71.     if(Gracz1==1)
  72.     {
  73.         cout<<"Gracz 1 zaczyna"<<endl;
  74.         Gracz2=2;
  75.     }
  76.     else {cout<<"Gracz 2 zaczyna"<<endl;Gracz2=1;}
  77.  
  78.  
  79. }
  80. void ruszaj(int x,int y)
  81. {
  82.     int choosenone,choosentwo;// choosenone odpowiada zmiennej x a choosentwo zmiennej y.
  83.     if(pole[x][y]=="x"&&Gracz1==1)
  84.     {
  85.         cout<<"Na ktore pole chcesz sie ruszyc?"<<endl;
  86.         cout<<"wybor wspolrzednej x: ";
  87.         cin>>choosenone;
  88.         cout<<"wybor wspolrzednej y: ";
  89.         cin>>choosentwo;
  90.         if((choosenone-1==x||choosenone+1==x)&&choosentwo-1==y)
  91.         {
  92.         pole[choosenone][choosentwo]=pole[x][y];
  93.         pole[x][y]=" ";
  94.         ruch_gra1=false;
  95.         ruch_gra2=true;
  96.         }
  97.         else if(pole[choosenone][choosentwo]=="x")
  98.         {
  99.          cout<<"Tam stoi pionek!"<<endl;
  100.          ruch_gra1=true;
  101.         }
  102.         else if(pole[x+1][y+1]=="W"&&((choosenone==x+2||choosenone==x-2)&&choosentwo==y+2))
  103.         {
  104.             pole[choosenone][choosentwo]=pole[x][y];
  105.             pole[x][y]=" ";
  106.             pole[x+1][y+1]=" ";
  107.             ruch_gra1=false;
  108.             ruch_gra2=true;
  109.         }
  110.         else if(pole[x-1][y+1]=="W"&&((choosenone==x+2||choosenone==x-2)&&choosentwo==y+2))
  111.         {
  112.             pole[choosenone][choosentwo]=pole[x][y];
  113.             pole[x][y]=" ";
  114.             pole[x-1][y+1]=" ";
  115.             ruch_gra1=false;
  116.             ruch_gra2=true;
  117.         }
  118.         else{cout<<"W warcabach sie tak nie rusza"<<endl;ruch_gra1=true;}
  119.         for(int i=1; i<=8; i++)
  120.         {
  121.         if(pole[choosenone][choosentwo]==pole[i][8]&&pole[i][8]=="x")
  122.         {
  123.             pole[i][8]="kr1";
  124.             ruch_gra1=false;
  125.             ruch_gra2=true;
  126.         }
  127.         }
  128.  
  129.     }
  130.     else if(pole[x][y]=="W"&&Gracz2==1)
  131.     {
  132.        cout<<"Na ktore pole chcesz sie ruszyc?"<<endl;
  133.        cout<<"wybor wspolrzednej x: ";
  134.        cin>>choosenone;
  135.        cout<<"wybor wspolrzednej y: ";
  136.        cin>>choosentwo;
  137.        if((choosenone-1==x||choosenone+1==x)&&choosentwo+1==y)//ograned
  138.        {
  139.        pole[choosenone][choosentwo]=pole[x][y];
  140.        pole[x][y]=" ";
  141.        ruch_gra2=false;
  142.        ruch_gra1=true;
  143.        }
  144.        else if(pole[choosenone][choosentwo]=="W")
  145.         {
  146.          cout<<"Tam stoi pionek!"<<endl;
  147.          ruch_gra2=true;
  148.         }
  149.         else if(pole[x+1][y-1]=="x"&&((choosenone==x+2||choosenone==x-2)&&choosentwo==y-2))
  150.         {
  151.             pole[choosenone][choosentwo]=pole[x][y];
  152.             pole[x][y]=" ";
  153.             pole[x+1][y-1]=" ";
  154.             ruch_gra2=false;
  155.             ruch_gra1=true;
  156.         }
  157.         else if(pole[x-1][y-1]=="x"&&((choosenone==x+2||choosenone==x-2)&&choosentwo==y-2))
  158.         {
  159.             pole[choosenone][choosentwo]=pole[x][y];
  160.             pole[x][y]=" ";
  161.             pole[x-1][y-1]=" ";
  162.             ruch_gra2=false;
  163.             ruch_gra1=true;
  164.         }
  165.        else{cout<<"W warcabach sie tak nie rusza ;-;"<<endl;
  166.        ruch_gra2=true;}
  167.        for(int i=1; i<=8; i++)
  168.         {
  169.         if(pole[choosenone][choosentwo]==pole[i][1]&&pole[i][1]=="W")
  170.         {
  171.             pole[i][1]="kr2";
  172.             ruch_gra1=true;
  173.             ruch_gra2=false;
  174.         }
  175.         }
  176.     }
  177.     else if (pole[x][y]=="x"&&Gracz1!=1)
  178.     {
  179.         if(Gracz1==1)
  180.         {
  181.         cout<<"To pole nie jest twoje!"<<endl;
  182.         ruch_gra1=true;
  183.         }
  184.         else if(Gracz2==1)
  185.         {
  186.         cout<<"To pole nie jest twoje!"<<endl;
  187.         ruch_gra2=true;
  188.         }
  189.     }
  190.     else if (pole[x][y]=="W"&&Gracz2!=1)
  191.     {
  192.         if(Gracz1==1)
  193.         {
  194.         cout<<"To pole nie jest twoje!"<<endl;
  195.         ruch_gra1=true;
  196.         }
  197.         else if(Gracz2==1)
  198.         {
  199.         cout<<"To pole nie jest twoje!"<<endl;
  200.         ruch_gra2=true;
  201.         }
  202.     }
  203.     else if (pole[x][y]==" ")
  204.     {
  205.         if(Gracz1==1)
  206.         {
  207.         cout<<"Tutaj nie ma pionka!"<<endl;
  208.         ruch_gra1=true;
  209.         }
  210.         else if(Gracz2==1)
  211.         {
  212.         cout<<"Tutaj nie ma pionka!"<<endl;
  213.         ruch_gra2=true;
  214.         }
  215.  
  216.     }
  217.     else if(pole[x][y]=="kr1"&&Gracz1==1)//Tutaj stanąłem nie wiem co począć ;(
  218.     {
  219.        cout<<"Na ktore pole chcesz sie ruszyc?"<<endl;
  220.        cout<<"wybor wspolrzednej x: ";
  221.        cin>>choosenone;
  222.        cout<<"wybor wspolrzednej y: ";
  223.        cin>>choosentwo;
  224.        if (choosentwo==y)
  225.        {
  226.          for(int a=1; a<=7; a++)
  227.          {
  228.            if(pole[x-a][y]=="W")
  229.            {
  230.                 if(pole[choosenone-a][choosentwo]=="W")
  231.                {
  232.                   pole[choosenone-a][choosentwo]==" ";
  233.                   pole[choosenone-(a-1)][choosentwo]=="kr1";
  234.                }
  235.            }
  236.            if(pole[x+a][y]=="W")
  237.            {
  238.                 if(pole[choosenone+a][choosentwo]=="W")
  239.                 {
  240.                  pole[choosenone+a][choosentwo]==" ";
  241.                  pole[choosenone+(a+1)][choosentwo]=="kr1";
  242.                 }
  243.            }
  244.          }
  245.        }
  246.     }
  247.     else{cout<<"Co Ty robisz?"<<endl;}
  248.  
  249.  
  250. }
  251. void system()
  252. {
  253.     while (gra==true)
  254.     {
  255.         if(Gracz1==1)
  256.         {
  257.             while(ruch_gra1==true)
  258.             {
  259.             cout<<"Wybor Gracza 1: "<<endl;
  260.             cout<<"Wspolrzedna x: ";
  261.             cin>>wybor1;
  262.             cout<<"Wspolrzedna y: ";
  263.             cin>>wybor2;
  264.             ruszaj(wybor1,wybor2);
  265.             wyswietlenie_planszy();
  266.             system();
  267.             }
  268.             Gracz1=2;
  269.             Gracz2=1;
  270.         }
  271.         else if(Gracz2==1)
  272.         {
  273.             while(ruch_gra2==true)
  274.             {
  275.             cout<<"Wybor Gracza 2: "<<endl;
  276.             cout<<"Wspolrzedna x: ";
  277.             cin>>wybor1;
  278.             cout<<"Wspolrzedna y: ";
  279.             cin>>wybor2;
  280.             ruszaj(wybor1,wybor2);
  281.             wyswietlenie_planszy();
  282.             system();
  283.             }
  284.             Gracz2=2;
  285.             Gracz1=1;
  286.         }
  287.  
  288.     }
  289. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement