Advertisement
TroubleMaker84

Untitled

Jan 3rd, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 16.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <graphics.h>
  3. #include <winbgim.h>
  4. #include <conio.h>
  5. #include <windows.h>
  6. #include <math.h>
  7. using namespace std;
  8. #define pod_p1 10
  9. #define pod_p2 20
  10. int radius;
  11. int window_lenght =1000;
  12. int window_height=600;
  13. int teren[120][120];
  14. int n;
  15.  
  16. void initMatrice(int teren[120][120],int n)
  17. {
  18.     int i,j;
  19.     for(i=1; i<=2*n-1; i++)
  20.         for (j=1; j<=2*n-1; j++)
  21.         {
  22.             if(j%2==1 && i%2==0)
  23.             {
  24.                 teren[i][j]=1;
  25.                 teren[j][i]=2;
  26.             }
  27.         }
  28.     for(i=0; i<2*n+1; i++)
  29.         teren[i][0]=teren[0][i]=teren[2*n][i]=teren[i][2*n]=-1;
  30. }
  31.  
  32.  
  33. void creazaPod(int i, int j, char *dir)
  34. {
  35.  
  36.  
  37.     if (strcmp(dir, "sus")==0)
  38.     {
  39.         if (teren[i-1][j]==0 )
  40.         {
  41.             if(j%2==1 && i%2==0 && i!=1)
  42.             {
  43.                 teren[i-1][j]=pod_p1;
  44.                 setcolor(BLUE);
  45.                 line(window_lenght/4 + ((window_lenght/2)/n)*(j/2) +window_lenght/(4*n),window_height/4 + ((window_height/2)/n)*(i/2), window_lenght/4 + ((window_lenght/2)/n)*(j/2) + window_lenght/(4*n),window_height/4 + ((window_height/2)/n)*(i/2-1));
  46.                 line(-1 +window_lenght/4 + ((window_lenght/2)/n)*(j/2) +window_lenght/(4*n),window_height/4 + ((window_height/2)/n)*(i/2), -1 + window_lenght/4 + ((window_lenght/2)/n)*(j/2) + window_lenght/(4*n),window_height/4 + ((window_height/2)/n)*(i/2-1));
  47.                 line(1 + window_lenght/4 + ((window_lenght/2)/n)*(j/2) +window_lenght/(4*n),window_height/4 + ((window_height/2)/n)*(i/2),1 + window_lenght/4 + ((window_lenght/2)/n)*(j/2) + window_lenght/(4*n),window_height/4 + ((window_height/2)/n)*(i/2-1));
  48.             }
  49.             else if(j%2==0 && i%2==1 && i!=2)
  50.             {
  51.                 teren[i-1][j]=pod_p2;
  52.                 setcolor(RED);
  53.                 line(window_lenght/4 + ((window_lenght/2)/n)*(j/2),window_height/4 + ((window_height/2)/n)*(i/2) + (window_height/4)/n, window_lenght/4 + ((window_lenght/2)/n)*(j/2),window_height/4 + ((window_height/2)/n)*(i/2-1) +(window_height/4)/n);
  54.                 line(-1 +window_lenght/4 + ((window_lenght/2)/n)*(j/2),window_height/4 + ((window_height/2)/n)*(i/2) + (window_height/4)/n, -1 + window_lenght/4 + ((window_lenght/2)/n)*(j/2),window_height/4 + ((window_height/2)/n)*(i/2-1)+(window_height/4)/n);
  55.                 line(1 + window_lenght/4 + ((window_lenght/2)/n)*(j/2),window_height/4 + ((window_height/2)/n)*(i/2) + (window_height/4)/n,1 + window_lenght/4 + ((window_lenght/2)/n)*(j/2),window_height/4 + ((window_height/2)/n)*(i/2-1)+  (window_height/4)/n );
  56.             }
  57.         }
  58.  
  59.     }
  60.     if (strcmp(dir, "jos")==0)
  61.     {
  62.         if (teren[i+1][j]==0)
  63.         {
  64.             if(j%2==1 && i%2==0 && i!=2*n-2)
  65.             {
  66.                 teren[i+1][j]=pod_p1;
  67.                 setcolor(BLUE);
  68.                 line(window_lenght/4 + ((window_lenght/2)/n)*(j/2) +window_lenght/(4*n),window_height/4 + ((window_height/2)/n)*(i/2), window_lenght/4 + ((window_lenght/2)/n)*(j/2) + window_lenght/(4*n),window_height/4 + ((window_height/2)/n)*(i/2+1));
  69.                 line(-1 +window_lenght/4 + ((window_lenght/2)/n)*(j/2) +window_lenght/(4*n),window_height/4 + ((window_height/2)/n)*(i/2), -1 + window_lenght/4 + ((window_lenght/2)/n)*(j/2) + window_lenght/(4*n),window_height/4 + ((window_height/2)/n)*(i/2+1));
  70.                 line(1 + window_lenght/4 + ((window_lenght/2)/n)*(j/2) +window_lenght/(4*n),window_height/4 + ((window_height/2)/n)*(i/2),1 + window_lenght/4 + ((window_lenght/2)/n)*(j/2) + window_lenght/(4*n),window_height/4 + ((window_height/2)/n)*(i/2+1));
  71.             }
  72.             else if(j%2==0 && i%2==1 && i!=2*n-1)
  73.             {
  74.                 teren[i+1][j]=pod_p2;
  75.                 setcolor(RED);
  76.                 line(window_lenght/4 + ((window_lenght/2)/n)*(j/2),window_height/4 + ((window_height/2)/n)*(i/2) + (window_height/4)/n, window_lenght/4 + ((window_lenght/2)/n)*(j/2),window_height/4 + ((window_height/2)/n)*(i/2+1) +(window_height/4)/n);
  77.                 line(-1 +window_lenght/4 + ((window_lenght/2)/n)*(j/2),window_height/4 + ((window_height/2)/n)*(i/2) + (window_height/4)/n, -1 + window_lenght/4 + ((window_lenght/2)/n)*(j/2),window_height/4 + ((window_height/2)/n)*(i/2+1)+(window_height/4)/n);
  78.                 line(1 + window_lenght/4 + ((window_lenght/2)/n)*(j/2),window_height/4 + ((window_height/2)/n)*(i/2) + (window_height/4)/n,1 + window_lenght/4 + ((window_lenght/2)/n)*(j/2),window_height/4 + ((window_height/2)/n)*(i/2+1)+  (window_height/4)/n );
  79.             }
  80.         }
  81.     }
  82.     if (strcmp(dir, "st")==0)
  83.     {
  84.         if (teren[i][j-1]==0 )
  85.             if(j%2==1 && i%2==0 && j!=1)
  86.             {
  87.                 teren[i][j-1]=pod_p1;
  88.                 setcolor(BLUE);
  89.                 line(window_lenght/4 + ((window_lenght/2)/n)*(j/2) +window_lenght/(4*n),window_height/4 + ((window_height/2)/n)*(i/2 ), window_lenght/4 + ((window_lenght/2)/n)*(j/2-1) + window_lenght/(4*n),window_height/4 + ((window_height/2)/n)*(i/2));
  90.                 line(window_lenght/4 + ((window_lenght/2)/n)*(j/2) +window_lenght/(4*n),-1+window_height/4 + ((window_height/2)/n)*(i/2 ),  window_lenght/4 + ((window_lenght/2)/n)*(j/2-1) + window_lenght/(4*n),-1+window_height/4 + ((window_height/2)/n)*(i/2));
  91.                 line(window_lenght/4 + ((window_lenght/2)/n)*(j/2) +window_lenght/(4*n),1+window_height/4 + ((window_height/2)/n)*(i/2 ), window_lenght/4 + ((window_lenght/2)/n)*(j/2-1) + window_lenght/(4*n),1+window_height/4 + ((window_height/2)/n)*(i/2));
  92.             }
  93.             else if(j%2==0 && i%2==1 && j!=2)
  94.             {
  95.                 teren[i][j-1]=pod_p2;
  96.                 setcolor(RED);
  97.                 line(window_lenght/4 + ((window_lenght/2)/n)*(j/2),window_height/4 + ((window_height/2)/n)*(i/2 ) +(window_height/4)/n, window_lenght/4 + ((window_lenght/2)/n)*(j/2-1),window_height/4 + ((window_height/2)/n)*(i/2) +(window_height/4)/n);
  98.                 line(window_lenght/4 + ((window_lenght/2)/n)*(j/2),-1+window_height/4 + ((window_height/2)/n)*(i/2 ) + (window_height/4)/n,  window_lenght/4 + ((window_lenght/2)/n)*(j/2-1),-1+window_height/4 + ((window_height/2)/n)*(i/2)+(window_height/4)/n);
  99.                 line(window_lenght/4 + ((window_lenght/2)/n)*(j/2),1+window_height/4 + ((window_height/2)/n)*(i/2 ) +(window_height/4)/n, window_lenght/4 + ((window_lenght/2)/n)*(j/2-1),1+window_height/4 + ((window_height/2)/n)*(i/2)+(window_height/4)/n);
  100.             }
  101.     }
  102.     if (strcmp(dir, "dr")==0)
  103.     {
  104.         if (teren[i][j+1]==0 )
  105.             if(j%2==1 && i%2==0 && j!= 2*n -1)
  106.             {
  107.                 teren[i][j+1]=pod_p1;
  108.                 setcolor(BLUE);
  109.                 line(window_lenght/4 + ((window_lenght/2)/n)*(j/2) +window_lenght/(4*n),window_height/4 + ((window_height/2)/n)*(i/2 ), window_lenght/4 + ((window_lenght/2)/n)*(j/2+1) + window_lenght/(4*n),window_height/4 + ((window_height/2)/n)*(i/2));
  110.                 line(window_lenght/4 + ((window_lenght/2)/n)*(j/2) +window_lenght/(4*n),-1+window_height/4 + ((window_height/2)/n)*(i/2 ),  window_lenght/4 + ((window_lenght/2)/n)*(j/2+1) + window_lenght/(4*n),-1+window_height/4 + ((window_height/2)/n)*(i/2));
  111.                 line(window_lenght/4 + ((window_lenght/2)/n)*(j/2) +window_lenght/(4*n),1+window_height/4 + ((window_height/2)/n)*(i/2 ), window_lenght/4 + ((window_lenght/2)/n)*(j/2+1) + window_lenght/(4*n),1+window_height/4 + ((window_height/2)/n)*(i/2));
  112.             }
  113.             else if(j%2==0 && i%2==1 && j!=2*n-2)
  114.             {
  115.                 teren[i][j+1]=pod_p2;
  116.                 setcolor(RED);
  117.                 line(window_lenght/4 + ((window_lenght/2)/n)*(j/2),window_height/4 + ((window_height/2)/n)*(i/2 ) +(window_height/4)/n, window_lenght/4 + ((window_lenght/2)/n)*(j/2+1),window_height/4 + ((window_height/2)/n)*(i/2) +(window_height/4)/n);
  118.                 line(window_lenght/4 + ((window_lenght/2)/n)*(j/2),-1+window_height/4 + ((window_height/2)/n)*(i/2 ) + (window_height/4)/n,  window_lenght/4 + ((window_lenght/2)/n)*(j/2+1),-1+window_height/4 + ((window_height/2)/n)*(i/2)+(window_height/4)/n);
  119.                 line(window_lenght/4 + ((window_lenght/2)/n)*(j/2),1+window_height/4 + ((window_height/2)/n)*(i/2 ) +(window_height/4)/n, window_lenght/4 + ((window_lenght/2)/n)*(j/2+1),1+window_height/4 + ((window_height/2)/n)*(i/2)+(window_height/4)/n);
  120.             }
  121.     }
  122. }
  123.  
  124. bool apasatInCercPl1(int &x,int &y)
  125. {
  126.     for(int i=1; i<=n; i++)
  127.         for(int j=1; j<n; j++)
  128.             if((x>(window_lenght/4- ((window_lenght/4)/n) + ((window_lenght/2)/n)*i - radius)) && (x<window_lenght/4- ((window_lenght/4)/n) + ((window_lenght/2)/n)*i + radius ))
  129.                 if((y>(window_height/4 +((window_height/4)/n) + ((window_height/2)/n)*j - 3*radius)) && (y<(window_height/4 +((window_height/4)/n) + ((window_height/2)/n)*j - radius)))
  130.                 {
  131.                     x=i;
  132.                     y=j;
  133.                     return 1;
  134.                 }
  135.     return 0;
  136. }
  137.  
  138. bool is_Above_the_First(int x1,int y1,int x2,int y2)
  139. {
  140.     if((x2>x1-radius  && x2 < x1+radius) && (y2>y1 - window_height/(2*n) - radius && y2<y1 - window_height/(2*n) + radius) )
  141.     {
  142.         outtext("done");
  143.         return 1;
  144.     }
  145.     else
  146.         return 0;
  147. }
  148.  
  149. bool is_Under_the_First(int x1, int y1, int x2, int y2)
  150. {
  151.     if((x2>x1-radius  && x2 < x1+radius) && (y2>y1 + window_height/(2*n) - radius && y2<y1 + window_height/(2*n) + radius) )
  152.     {
  153.         outtext("done");
  154.         return 1;
  155.     }
  156.     else
  157.         return 0;
  158. }
  159.  
  160. bool is_in_Right_of_First(int x1, int y1, int x2, int y2)
  161. {
  162.     if((x2>x1-radius + window_lenght/(2*n)  && x2 < x1+radius + window_lenght/(2*n)) && (y2>y1 - radius && y2<y1 + radius) )
  163.     {
  164.         outtext("done");
  165.         return 1;
  166.     }
  167.     else
  168.         return 0;
  169. }
  170.  
  171. bool is_in_Left_of_First(int x1, int y1, int x2, int y2)
  172. {
  173.     if((x2>x1-radius - window_lenght/(2*n)  && x2 < x1+radius - window_lenght/(2*n)) && (y2>y1 - radius && y2<y1 + radius) )
  174.     {
  175.         outtext("done");
  176.         return 1;
  177.     }
  178.     else
  179.         return 0;
  180. }
  181.  
  182.  
  183. void highlight_Possible_Bridges(int linie, int coloana)
  184. {
  185.     if(1);
  186. }
  187.  
  188. void player1_Move()
  189. {
  190.     int x1,x2,y1,y2,coloana,linie;
  191.     bool lineWasDrawn=FALSE, selectedAproperPosition=FALSE ;
  192.     while(!lineWasDrawn)
  193.     {
  194.         while(!selectedAproperPosition)
  195.             if(ismouseclick(WM_LBUTTONDOWN))
  196.             {
  197.                 clearmouseclick(WM_LBUTTONDOWN);
  198.                 coloana=mousex();
  199.                 linie=mousey();
  200.                 if(apasatInCercPl1(coloana,linie) )
  201.                 {
  202.                     x1=mousex();
  203.                     y1=mousey();
  204.                     selectedAproperPosition=TRUE;
  205.                 }
  206.             }
  207.         selectedAproperPosition=FALSE;
  208.         while(!selectedAproperPosition)
  209.         {
  210.             if(ismouseclick(WM_LBUTTONDOWN))
  211.             {
  212.                 clearmouseclick(WM_LBUTTONDOWN);
  213.                 int x2=mousex(),y2=mousey();
  214.                 if(is_Above_the_First(x1,y1,x2,y2)==1  && teren[coloana][linie-1] != -1)
  215.                 {
  216.                     creazaPod(2*linie,2*coloana -1,"sus");
  217.                     lineWasDrawn=TRUE;
  218.                     selectedAproperPosition=TRUE;
  219.                 }
  220.                 else if(is_Under_the_First(x1,y1,x2,y2) && teren[coloana][linie+1] != -1)
  221.                 {
  222.                     creazaPod(2*linie,2*coloana -1,"jos");
  223.                     lineWasDrawn=TRUE;
  224.                     selectedAproperPosition=TRUE;
  225.                 }
  226.                 else if(is_in_Right_of_First(x1,y1,x2,y2) && teren[coloana+1][linie]!= -1)
  227.                 {
  228.                     creazaPod(2*linie,2*coloana -1,"dr");
  229.                     lineWasDrawn=TRUE;
  230.                     selectedAproperPosition=TRUE;
  231.                 }
  232.                 else if (is_in_Left_of_First(x1,y1,x2,y2)&& teren[coloana-1][linie]!= -1)
  233.                     {
  234.                     creazaPod(2*linie,2*coloana -1,"st");
  235.                     lineWasDrawn=TRUE;
  236.                     selectedAproperPosition=TRUE;
  237.                     }
  238.             }
  239.         }
  240.     }
  241. }
  242.  
  243. bool apasatInCercPl2(int &x,int &y)
  244. {
  245.     //window_lenght/4 + ((window_lenght/2)/n)*i, window_height/4 + ((window_height/2)/n)*j - 2*radius
  246.     for(int i=1; i<n; i++)
  247.         for(int j=1; j<=n; j++)
  248.             if((x>window_lenght/4 + ((window_lenght/2)/n)*i - radius) && (x<window_lenght/4 + ((window_lenght/2)/n)*i + radius ))
  249.                 if((y>( window_height/4 + ((window_height/2)/n)*j - 3*radius)) && (y<( window_height/4 + ((window_height/2)/n)*j - 3*radius)))
  250.                 {
  251.                     x=i;
  252.                     y=j;
  253.                     outtext("True");
  254.                     return 1;
  255.  
  256.                 }
  257.     return 0;
  258. }
  259.  
  260.  
  261. void player2_Move()
  262. {
  263.     int x1,x2,y1,y2,coloana,linie;
  264.     bool lineWasDrawn=FALSE, selectedAproperPosition=FALSE ;
  265.     while(!lineWasDrawn)
  266.     {
  267.         while(!selectedAproperPosition)
  268.             if(ismouseclick(WM_LBUTTONDOWN))
  269.             {
  270.                 clearmouseclick(WM_LBUTTONDOWN);
  271.                 coloana=mousex();
  272.                 linie=mousey();
  273.                 if(apasatInCercPl2(coloana,linie) )
  274.                 {
  275.                     x1=mousex();
  276.                     y1=mousey();
  277.                     selectedAproperPosition=TRUE;
  278.                 }
  279.             }
  280.         selectedAproperPosition=FALSE;
  281.         while(!selectedAproperPosition)
  282.         {
  283.             if(ismouseclick(WM_LBUTTONDOWN))
  284.             {
  285.                 clearmouseclick(WM_LBUTTONDOWN);
  286.                 int x2=mousex(),y2=mousey();
  287.                 if(is_Above_the_First(x1,y1,x2,y2)==1  && teren[coloana][linie-1] != -1)
  288.                 {
  289.                     creazaPod(2*linie,2*coloana -1,"sus");
  290.                     lineWasDrawn=TRUE;
  291.                     selectedAproperPosition=TRUE;
  292.                 }
  293.                 else if(is_Under_the_First(x1,y1,x2,y2) && teren[coloana][linie+1] != -1)
  294.                 {
  295.                     creazaPod(2*linie,2*coloana -1,"jos");
  296.                     lineWasDrawn=TRUE;
  297.                     selectedAproperPosition=TRUE;
  298.                 }
  299.                 else if(is_in_Right_of_First(x1,y1,x2,y2) && teren[coloana+1][linie]!= -1)
  300.                 {
  301.                     creazaPod(2*linie,2*coloana -1,"dr");
  302.                     lineWasDrawn=TRUE;
  303.                     selectedAproperPosition=TRUE;
  304.                 }
  305.                 else if (is_in_Left_of_First(x1,y1,x2,y2)&& teren[coloana-1][linie]!= -1)
  306.                     {
  307.                     creazaPod(2*linie,2*coloana -1,"st");
  308.                     lineWasDrawn=TRUE;
  309.                     selectedAproperPosition=TRUE;
  310.                     }
  311.             }
  312.         }
  313.     }
  314. }
  315.  
  316.  
  317. void initTable(short int n)
  318. {
  319.     int i,j, c[]= {250,150,750,150,750,450,250,450,250,150},c2[]= {0,0,1000,0,1000,600,0,600,0,0};
  320.     setfillstyle(SOLID_FILL,WHITE);
  321.     fillpoly(5,c2);
  322.     setfillstyle(SOLID_FILL,BLACK);
  323.     fillpoly(5,c);
  324.     setcolor(BLUE);
  325.     setfillstyle(SOLID_FILL,BLUE);
  326.     for(i=1; i<=n; i++)
  327.         for(j=1; j<n; j++)
  328.             fillellipse( (window_lenght/4)- ((window_lenght/4)/n) + ((window_lenght/2)/n)*i,window_height/4 +((window_height/4)/n) + ((window_height/2)/n)*j - 2*radius, radius,radius);
  329.     setcolor(RED);
  330.     setfillstyle(SOLID_FILL,RED);
  331.     for(i=1; i<n; i++)
  332.         for(j=1; j<=n; j++)
  333.             fillellipse( window_lenght/4 + ((window_lenght/2)/n)*i, window_height/4 + ((window_height/2)/n)*j - 2*radius, radius,radius);
  334.     setcolor(BLACK);
  335.     setbkcolor(WHITE);
  336.     settextstyle(BOLD_FONT,HORIZ_DIR,7);
  337.     outtextxy(350,75,"BRIDG-IT");
  338.  
  339. }
  340.  
  341. int main()
  342. {
  343.  
  344.     cout<<"Dati lungimea marimea de joc: ";
  345.     cin>>n;
  346.     radius= (n<16 && n!=12 && n!= 13)? (25-(2*n)) : 3;
  347.     initwindow(window_lenght, window_height, "Bridg-it");
  348.     initMatrice(teren, n);
  349.     initTable(n);
  350.     for(int i=0; i<=2*n; i++)
  351.     {
  352.         for(int j=0; j<=2*n; j++)
  353.             cout<<teren[i][j]<<' ';
  354.         cout<<endl;
  355.     }
  356.     int j=0;
  357.     while(j < 10)
  358.         {player1_Move();
  359.         //player2_Move();
  360.         }
  361.     for(int i=1; i<=2*n-1; i++)
  362.     {
  363.         for(int j=1; j<=2*n-1; j++)
  364.             cout<<teren[i][j]<<' ';
  365.         cout<<endl;
  366.     }
  367.     getch();
  368.     closegraph();
  369.     return 0;
  370. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement