Advertisement
TroubleMaker84

Bridg-it, almost there

Jan 10th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 31.52 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. #define BLUE_COLOR_Player1 1
  11. #define GREEN_COLOR_Player1 10
  12. #define PINK_COLOR_Player1 13
  13. #define RED_COLOR_Player2 4
  14. #define YELLOR_COLOR_Player2 14
  15. #define GRAY_COLOR_Player2 7
  16. int radius,Player1_Color_Choice=BLUE_COLOR_Player1, Player2_Color_Choice=RED_COLOR_Player2;
  17. int window_lenght =1000;
  18. int window_height=600;
  19. int teren[120][120];
  20. int board_Size=6;
  21. bool Player1_WON=FALSE, Player2_WON=FALSE;
  22.  
  23.  
  24.  
  25. void initMatrice(int teren[120][120],int n)
  26. {
  27.     int i,j;
  28.     for(i=1; i<=2*board_Size-1; i++)
  29.         for (j=1; j<=2*board_Size-1; j++)
  30.         {
  31.             if(j%2==1 && i%2==0)
  32.             {
  33.                 teren[i][j]=1;
  34.                 teren[j][i]=2;
  35.             }
  36.         }
  37.     for(i=0; i<2*board_Size+1; i++)
  38.         teren[i][0]=teren[0][i]=teren[2*n][i]=teren[i][2*n]=-1;
  39. }
  40.  
  41. void init_Matrice_Vizitare(int v[120][120])
  42. {
  43.     int i;
  44.     for (i=1; i<=2*board_Size; i++)
  45.         for(int j=1;i<=2*board_Size;j++)
  46.             v[i][j]=0;
  47. }
  48. /*void parcurgere_adancime_p1 (int linie, int coloana)
  49.  
  50. {
  51.     if (coloana==2*n-1)
  52.         Player1_WON= TRUE;
  53.     if(teren[linie][coloana+1]==10)
  54.         parcurgere_adancime_p1(linie, coloana+2);
  55.     else
  56.         if(teren[linie-1][coloana]==10)
  57.             parcurgere_adancime_p1(linie-2, coloana);
  58.         else
  59.             if(teren[linie+1][coloana]==10)
  60.                 parcurgere_adancime_p1(linie+2,coloana);
  61.             else
  62.                 if(teren[linie][coloana-1]==10)
  63.                     parcurgere_adancime_p1(linie, coloana-2);
  64. }
  65.  
  66.  
  67.   int parcurgere_adancime_p2 (int k)
  68.  
  69.     {
  70.         v_p2[k]=1;
  71.     if (k==2*n) return k;
  72.  
  73.         for(int x=0;x<2*n;x=x+2)
  74.  
  75.             if(teren [k][x]==1)
  76.  
  77.                if(v_p2[x]==0)
  78.  
  79.                   parcurgere_adancime_p2 (x); else return x;
  80.  
  81.     }
  82.  
  83. int verifica_castigator ()
  84. {
  85.     int i;
  86.     for (i=2; i<=2*n-2; i=i+2)
  87.     {
  88.         //init_Matrice_Vizitare(vizitat_p1);
  89.         parcurgere_adancime_p1(i,1);
  90.         if(Player1_WON)
  91.             return 1;
  92.     }
  93.     /*for (i=0;i<=2*n;i=i+2)
  94.     {
  95.         init(v_p2); if (parcurgere_adancime_p2(i)==2*n) return 2;
  96.     }
  97.     return 0;
  98. }
  99. */
  100.  
  101.  
  102. void creazaPod(int i, int j, char *dir)
  103. {
  104.  
  105.  
  106.     if (strcmp(dir, "sus")==0)
  107.     {
  108.         if (teren[i-1][j]==0 )
  109.         {
  110.             if(j%2==1 && i%2==0 && i!=1)
  111.             {
  112.                 teren[i-1][j]=pod_p1;
  113.                 setcolor(Player1_Color_Choice);
  114.                 line(window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2) +window_lenght/(4*board_Size),window_height/4 + ((window_height/2)/board_Size)*(i/2), window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2) + window_lenght/(4*board_Size),window_height/4 + ((window_height/2)/board_Size)*(i/2-1));
  115.                 line(1+window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2) +window_lenght/(4*board_Size),window_height/4 + ((window_height/2)/board_Size)*(i/2),1+ window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2) + window_lenght/(4*board_Size),window_height/4 + ((window_height/2)/board_Size)*(i/2-1));
  116.                 line(-1 + window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2) +window_lenght/(4*board_Size),window_height/4 + ((window_height/2)/board_Size)*(i/2),-1 + window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2) + window_lenght/(4*board_Size),window_height/4 + ((window_height/2)/board_Size)*(i/2-1));
  117.  
  118.             }
  119.             else if(j%2==0 && i%2==1 && i!=2)
  120.             {
  121.                 teren[i-1][j]=pod_p2;
  122.                 setcolor(Player2_Color_Choice);
  123.                 line(window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2),window_height/4 + ((window_height/2)/board_Size)*(i/2) + (window_height/4)/board_Size, window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2),window_height/4 + ((window_height/2)/board_Size)*(i/2-1) +(window_height/4)/board_Size);
  124.                 line(1+window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2),window_height/4 + ((window_height/2)/board_Size)*(i/2) + (window_height/4)/board_Size,1+ window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2),window_height/4 + ((window_height/2)/board_Size)*(i/2-1) +(window_height/4)/board_Size);
  125.                 line(-1 +window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2),window_height/4 + ((window_height/2)/board_Size)*(i/2) + (window_height/4)/board_Size,-1 + window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2),window_height/4 + ((window_height/2)/board_Size)*(i/2-1) +(window_height/4)/board_Size);
  126.             }
  127.         }
  128.  
  129.     }
  130.     if (strcmp(dir, "jos")==0)
  131.     {
  132.         if (teren[i+1][j]==0)
  133.         {
  134.             if(j%2==1 && i%2==0 && i!=2*board_Size-2)
  135.             {
  136.                 teren[i+1][j]=pod_p1;
  137.                 setcolor(Player1_Color_Choice);
  138.                 line(window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2) +window_lenght/(4*board_Size),window_height/4 + ((window_height/2)/board_Size)*(i/2), window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2) + window_lenght/(4*board_Size),window_height/4 + ((window_height/2)/board_Size)*(i/2+1));
  139.                 line(1+window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2) +window_lenght/(4*board_Size),window_height/4 + ((window_height/2)/board_Size)*(i/2),1+ window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2) + window_lenght/(4*board_Size),window_height/4 + ((window_height/2)/board_Size)*(i/2+1));
  140.                 line(-1+window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2) +window_lenght/(4*board_Size),window_height/4 + ((window_height/2)/board_Size)*(i/2),-1+ window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2) + window_lenght/(4*board_Size),window_height/4 + ((window_height/2)/board_Size)*(i/2+1));
  141.             }
  142.             else if(j%2==0 && i%2==1 && i!=2*board_Size-1)
  143.             {
  144.                 teren[i+1][j]=pod_p2;
  145.                 setcolor(Player2_Color_Choice);
  146.                 line(window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2),window_height/4 + ((window_height/2)/board_Size)*(i/2) + (window_height/4)/board_Size, window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2),window_height/4 + ((window_height/2)/board_Size)*(i/2+1) +(window_height/4)/board_Size);
  147.                 line(1+window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2),window_height/4 + ((window_height/2)/board_Size)*(i/2) + (window_height/4)/board_Size,1 + window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2),window_height/4 + ((window_height/2)/board_Size)*(i/2+1) +(window_height/4)/board_Size);
  148.                 line(-1+window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2),window_height/4 + ((window_height/2)/board_Size)*(i/2) + (window_height/4)/board_Size,-1 + window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2),window_height/4 + ((window_height/2)/board_Size)*(i/2+1) +(window_height/4)/board_Size);
  149.  
  150.             }
  151.         }
  152.     }
  153.     if (strcmp(dir, "st")==0)
  154.     {
  155.         if (teren[i][j-1]==0 )
  156.             if(j%2==1 && i%2==0 && j!=1)
  157.             {
  158.                 teren[i][j-1]=pod_p1;
  159.                 setcolor(Player1_Color_Choice);
  160.                 line(window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2) +window_lenght/(4*board_Size),window_height/4 + ((window_height/2)/board_Size)*(i/2 ), window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2-1) + window_lenght/(4*board_Size),window_height/4 + ((window_height/2)/board_Size)*(i/2));
  161.                 line(window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2) +window_lenght/(4*board_Size),1+window_height/4 + ((window_height/2)/board_Size)*(i/2 ), window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2-1) + window_lenght/(4*board_Size),1+window_height/4 + ((window_height/2)/board_Size)*(i/2));
  162.                 line(window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2) +window_lenght/(4*board_Size),-1 +window_height/4 + ((window_height/2)/board_Size)*(i/2 ), window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2-1) + window_lenght/(4*board_Size),-1+window_height/4 + ((window_height/2)/board_Size)*(i/2));
  163.             }
  164.             else if(j%2==0 && i%2==1 && j!=2)
  165.             {
  166.                 teren[i][j-1]=pod_p2;
  167.                 setcolor(Player2_Color_Choice);
  168.                 line(window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2),window_height/4 + ((window_height/2)/board_Size)*(i/2 ) +(window_height/4)/board_Size, window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2-1),window_height/4 + ((window_height/2)/board_Size)*(i/2) +(window_height/4)/board_Size);
  169.                 line(window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2),1+window_height/4 + ((window_height/2)/board_Size)*(i/2 ) +(window_height/4)/board_Size, window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2-1),1+ window_height/4 + ((window_height/2)/board_Size)*(i/2) +(window_height/4)/board_Size);
  170.                 line(window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2),-1 +window_height/4 + ((window_height/2)/board_Size)*(i/2 ) +(window_height/4)/board_Size, window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2-1),-1 + window_height/4 + ((window_height/2)/board_Size)*(i/2) +(window_height/4)/board_Size);
  171.             }
  172.     }
  173.     if (strcmp(dir, "dr")==0)
  174.     {
  175.         if (teren[i][j+1]==0 )
  176.             if(j%2==1 && i%2==0 && j!= 2*board_Size -1)
  177.             {
  178.                 teren[i][j+1]=pod_p1;
  179.                 setcolor(Player1_Color_Choice);
  180.                 line(window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2) +window_lenght/(4*board_Size),window_height/4 + ((window_height/2)/board_Size)*(i/2 ), window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2+1) + window_lenght/(4*board_Size),window_height/4 + ((window_height/2)/board_Size)*(i/2));
  181.                 line(window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2) +window_lenght/(4*board_Size),1+window_height/4 + ((window_height/2)/board_Size)*(i/2 ), window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2+1) + window_lenght/(4*board_Size),1 +window_height/4 + ((window_height/2)/board_Size)*(i/2));
  182.                 line(window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2) +window_lenght/(4*board_Size),-1 + window_height/4 + ((window_height/2)/board_Size)*(i/2 ), window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2+1) + window_lenght/(4*board_Size),-1 + window_height/4 + ((window_height/2)/board_Size)*(i/2));
  183.             }
  184.             else if(j%2==0 && i%2==1 && j!=2*board_Size-2)
  185.             {
  186.                 teren[i][j+1]=pod_p2;
  187.                 setcolor(Player2_Color_Choice);
  188.                 line(window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2),window_height/4 + ((window_height/2)/board_Size)*(i/2 ) +(window_height/4)/board_Size, window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2+1),window_height/4 + ((window_height/2)/board_Size)*(i/2) +(window_height/4)/board_Size);
  189.                 line(window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2),1+window_height/4 + ((window_height/2)/board_Size)*(i/2 ) +(window_height/4)/board_Size, window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2+1),1+window_height/4 + ((window_height/2)/board_Size)*(i/2) +(window_height/4)/board_Size);
  190.                 line(window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2),-1 + window_height/4 + ((window_height/2)/board_Size)*(i/2 ) +(window_height/4)/board_Size, window_lenght/4 + ((window_lenght/2)/board_Size)*(j/2+1),-1 +window_height/4 + ((window_height/2)/board_Size)*(i/2) +(window_height/4)/board_Size);
  191.             }
  192.     }
  193. }
  194.  
  195. bool apasatInCercPl1(int &x,int &y)
  196. {
  197.     for(int i=1; i<=board_Size; i++)
  198.         for(int j=1; j<board_Size; j++)
  199.             if((x>(window_lenght/4- ((window_lenght/4)/board_Size) + ((window_lenght/2)/board_Size)*i - radius)) && (x<window_lenght/4- ((window_lenght/4)/board_Size) + ((window_lenght/2)/board_Size)*i + radius ))
  200.                 if((y>(window_height/4 +((window_height/4)/board_Size) + ((window_height/2)/board_Size)*j - 3*radius)) && (y<(window_height/4 +((window_height/4)/board_Size) + ((window_height/2)/board_Size)*j - radius)))
  201.                 {
  202.                     x=i;
  203.                     y=j;
  204.                     return 1;
  205.                 }
  206.     return 0;
  207. }
  208.  
  209. bool is_Above_the_First(int x1,int y1,int x2,int y2)
  210. {
  211.     if((x2>x1-radius  && x2 < x1+radius) && (y2>y1 - window_height/(2*board_Size) - radius && y2<y1 - window_height/(2*board_Size) + radius) )
  212.     {
  213.         return 1;
  214.     }
  215.     else
  216.         return 0;
  217. }
  218.  
  219. bool is_Under_the_First(int x1, int y1, int x2, int y2)
  220. {
  221.     if((x2>x1-radius  && x2 < x1+radius) && (y2>y1 + window_height/(2*board_Size) - radius && y2<y1 + window_height/(2*board_Size) + radius) )
  222.     {
  223.         return 1;
  224.     }
  225.     else
  226.         return 0;
  227. }
  228.  
  229. bool is_in_Right_of_First(int x1, int y1, int x2, int y2)
  230. {
  231.     if((x2>x1-radius + window_lenght/(2*board_Size)  && x2 < x1+radius + window_lenght/(2*board_Size)) && (y2>y1 - radius && y2<y1 + radius) )
  232.     {
  233.         return 1;
  234.     }
  235.     else
  236.         return 0;
  237. }
  238.  
  239. bool is_in_Left_of_First(int x1, int y1, int x2, int y2)
  240. {
  241.     if((x2>x1-radius - window_lenght/(2*board_Size)  && x2 < x1+radius - window_lenght/(2*board_Size)) && (y2>y1 - radius && y2<y1 + radius) )
  242.     {
  243.         return 1;
  244.     }
  245.     else
  246.         return 0;
  247. }
  248.  
  249.  
  250. void highlight_Possible_Bridges(int linie, int coloana)
  251. {
  252.     if(1);
  253. }
  254.  
  255. void player1_Move()
  256. {
  257.     int x1,x2,y1,y2,coloana,linie;
  258.     bool lineWasDrawn=FALSE, selectedAproperPosition=FALSE ;
  259.     while(!lineWasDrawn)
  260.     {
  261.         while(!selectedAproperPosition)
  262.             if(ismouseclick(WM_LBUTTONDOWN))
  263.             {
  264.                 clearmouseclick(WM_LBUTTONDOWN);
  265.                 coloana=mousex();
  266.                 linie=mousey();
  267.                 if(apasatInCercPl1(coloana,linie) )
  268.                 {
  269.                     x1=mousex();
  270.                     y1=mousey();
  271.                     selectedAproperPosition=TRUE;
  272.                 }
  273.             }
  274.         selectedAproperPosition=FALSE;
  275.         while(!selectedAproperPosition)
  276.         {
  277.             if(ismouseclick(WM_LBUTTONDOWN))
  278.             {
  279.                 clearmouseclick(WM_LBUTTONDOWN);
  280.                 int x2=mousex(),y2=mousey();
  281.                 if(is_Above_the_First(x1,y1,x2,y2)==1  && teren[2*linie-1][2*coloana-1] ==0)
  282.                 {
  283.                     creazaPod(2*linie,2*coloana -1,"sus");
  284.                     lineWasDrawn=TRUE;
  285.                     selectedAproperPosition=TRUE;
  286.                 }
  287.                 else if(is_Under_the_First(x1,y1,x2,y2) && teren[2*linie+1][2*coloana-1] ==0)
  288.                 {
  289.                     creazaPod(2*linie,2*coloana -1,"jos");
  290.                     lineWasDrawn=TRUE;
  291.                     selectedAproperPosition=TRUE;
  292.                 }
  293.                 else if(is_in_Right_of_First(x1,y1,x2,y2) && teren[2*linie][2*coloana] ==0)
  294.                 {
  295.                     creazaPod(2*linie,2*coloana -1,"dr");
  296.                     lineWasDrawn=TRUE;
  297.                     selectedAproperPosition=TRUE;
  298.                 }
  299.                 else if (is_in_Left_of_First(x1,y1,x2,y2)&& teren[2*linie][2*coloana-2] ==0)
  300.                 {
  301.                     creazaPod(2*linie,2*coloana -1,"st");
  302.                     lineWasDrawn=TRUE;
  303.                     selectedAproperPosition=TRUE;
  304.                 }
  305.                 else {coloana=mousex();
  306.                     linie=mousey();
  307.                     if(apasatInCercPl1(coloana,linie) )
  308.                     {
  309.                         x1=mousex();
  310.                         y1=mousey();
  311.                         selectedAproperPosition=TRUE;
  312.                     }
  313.                     }
  314.             }
  315.         }
  316.     }
  317. }
  318.  
  319. bool apasatInCercPl2(int &x,int &y)
  320. {
  321.     for(int i=1; i<board_Size; i++)
  322.         for(int j=1; j<=board_Size; j++)
  323.             if((x>window_lenght/4 + ((window_lenght/2)/board_Size)*i - radius) && (x<window_lenght/4 + ((window_lenght/2)/board_Size)*i + radius ))
  324.             {
  325.                 if((y>( window_height/4 + ((window_height/2)/board_Size)*j - 3*radius)) && (y<( window_height/4 + ((window_height/2)/board_Size)*j - radius)))
  326.                 {
  327.                     x=i;
  328.                     y=j;
  329.                     return 1;
  330.                 }
  331.             }
  332.     return 0;
  333. }
  334.  
  335.  
  336. void player2_Move()
  337. {
  338.     int x1,x2,y1,y2,coloana,linie;
  339.     bool lineWasDrawn=FALSE, selectedAproperPosition=FALSE ;
  340.     while(!lineWasDrawn)
  341.     {
  342.         while(!selectedAproperPosition)
  343.             if(ismouseclick(WM_LBUTTONDOWN))
  344.             {
  345.                 clearmouseclick(WM_LBUTTONDOWN);
  346.                 coloana=mousex();
  347.                 linie=mousey();
  348.                 if(apasatInCercPl2(coloana,linie) )
  349.                 {
  350.                     x1=mousex();
  351.                     y1=mousey();
  352.                     selectedAproperPosition=TRUE;
  353.                 }
  354.             }
  355.         selectedAproperPosition=FALSE;
  356.         while(!selectedAproperPosition)
  357.         {
  358.             if(ismouseclick(WM_LBUTTONDOWN))
  359.             {
  360.                 clearmouseclick(WM_LBUTTONDOWN);
  361.                 int x2=mousex(),y2=mousey();
  362.                 if(is_Above_the_First(x1,y1,x2,y2)==1 && teren[2*linie-2][2*coloana] ==0 )
  363.                 {
  364.                     creazaPod(2*linie-1,2*coloana ,"sus");
  365.                     lineWasDrawn=TRUE;
  366.                     selectedAproperPosition=TRUE;
  367.                 }
  368.                 else if(is_Under_the_First(x1,y1,x2,y2) && teren[2*linie][2*coloana] ==0)
  369.                 {
  370.                     creazaPod(2*linie-1,2*coloana ,"jos");
  371.                     lineWasDrawn=TRUE;
  372.                     selectedAproperPosition=TRUE;
  373.                 }
  374.                 else if(is_in_Right_of_First(x1,y1,x2,y2) && teren[2*linie-1][2*coloana+1] ==0)
  375.                 {
  376.                     creazaPod(2*linie-1,2*coloana,"dr");
  377.                     lineWasDrawn=TRUE;
  378.                     selectedAproperPosition=TRUE;
  379.                 }
  380.                 else if (is_in_Left_of_First(x1,y1,x2,y2)&& teren[2*linie-1][2*coloana-1] ==0)
  381.                 {
  382.                     creazaPod(2*linie-1,2*coloana ,"st");
  383.                     lineWasDrawn=TRUE;
  384.                     selectedAproperPosition=TRUE;
  385.                 }
  386.                 else {
  387.                     coloana=mousex();
  388.                     linie=mousey();
  389.                     if(apasatInCercPl2(coloana,linie) )
  390.                     {
  391.                         x1=mousex();
  392.                         y1=mousey();
  393.                         selectedAproperPosition=TRUE;
  394.                     }
  395.                     }
  396.             }
  397.         }
  398.     }
  399. }
  400.  
  401.  
  402. void initTable(short int board_Size, int Player1_Color_Choice, int Player2_Color_Choice)
  403. {
  404.     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};
  405.     setfillstyle(SOLID_FILL,WHITE);
  406.     fillpoly(5,c2);
  407.     setfillstyle(SOLID_FILL,BLACK);
  408.     fillpoly(5,c);
  409.     setcolor(Player1_Color_Choice);
  410.     setfillstyle(SOLID_FILL,Player1_Color_Choice);
  411.     for(i=1; i<=board_Size; i++)
  412.         for(j=1; j<board_Size; j++)
  413.             fillellipse( (window_lenght/4)- ((window_lenght/4)/board_Size) + ((window_lenght/2)/board_Size)*i,window_height/4 +((window_height/4)/board_Size) + ((window_height/2)/board_Size)*j - 2*radius, radius,radius);
  414.     setcolor(Player2_Color_Choice);
  415.     setfillstyle(SOLID_FILL,Player2_Color_Choice);
  416.     for(i=1; i<board_Size; i++)
  417.         for(j=1; j<=board_Size; j++)
  418.             fillellipse( window_lenght/4 + ((window_lenght/2)/board_Size)*i, window_height/4 + ((window_height/2)/board_Size)*j - 2*radius, radius,radius);
  419.     setcolor(BLACK);
  420.     setbkcolor(WHITE);
  421.     settextstyle(BOLD_FONT,HORIZ_DIR,7);
  422.     outtextxy(350,75,"BRIDG-IT");
  423.  
  424. }
  425.  
  426. void draw_Instructions_Page()
  427. {
  428.     int c2[]= {0,0,1000,0,1000,600,0,600,0,0};
  429.     setfillstyle(SOLID_FILL,BLACK);
  430.     fillpoly(5,c2);
  431.     settextstyle(BOLD_FONT,HORIZ_DIR, 3);
  432.     setcolor(LIGHTGREEN);
  433.     setbkcolor(BLACK);
  434.     outtextxy(window_lenght/3 - 70, window_height/5 -30, "What is Bridg-It?");
  435.     outtextxy(window_lenght/3-70, window_height/5 + 100, "Rules:" );
  436.     outtextxy(window_lenght/4+10,window_height/5+190, "Controls: ");
  437.     settextstyle(BOLD_FONT,HORIZ_DIR, 1);
  438.     setcolor(YELLOW);
  439.     outtextxy(window_lenght/4, window_height/5 , "Bridg-It is a simple *connect the dots* board game");
  440.     outtextxy(window_lenght/4, window_height/5 + 15, "where players take turns");
  441.     outtextxy(window_lenght/4,window_height/5+30, "trying to connect as many of their dots");
  442.     outtextxy(window_lenght/4,window_height/5+45, "with the ultimate goal of connecting");
  443.     outtextxy(window_lenght/4,window_height/5+60, "the left side to the right side for Player 1");
  444.     outtextxy(window_lenght/4,window_height/5+75, "respectively top to bottom for Player 2.");
  445.     outtextxy(window_lenght/4,window_height/5+120, "-You draw 1 bridge at a time BETWEEN YOUR DOTS");
  446.     outtextxy(window_lenght/4,window_height/5+135, "-You cannot draw a bridge in a place where there already is one");
  447.     outtextxy(window_lenght/4,window_height/5+150, "-Player 1 wins if he manages to get from left to right");
  448.     outtextxy(window_lenght/4,window_height/5+165, "-Player2 wins if he manages to get from top to bottom ");
  449.     outtextxy(window_lenght/4,window_height/5+210, "You mouse-click on the dot that you want to connect with another");
  450.     outtextxy(window_lenght/4,window_height/5+225, "then on the one you want it connected with");
  451.     int c[]={window_lenght/2-100,window_height/5 +260, window_lenght/2+100, window_height/5+260, window_lenght/2 +100, window_height/5+300,window_lenght/2-100,window_height/5+300, window_lenght/2-100,window_height/5 +260};
  452.     setfillstyle(SOLID_FILL,LIGHTGRAY);
  453.     fillpoly(5,c);
  454.     setbkcolor(LIGHTGRAY);
  455.     setcolor(BLUE);
  456.     outtextxy(window_lenght/2-95, window_height/5+270, "BACK TO MAIN MENU");
  457. }
  458. void main_Menu();
  459.  
  460. void instructions_Page()
  461. {
  462.     cleardevice();
  463.     draw_Instructions_Page();
  464.     bool selectedBackToMM = FALSE;
  465.     while(!selectedBackToMM)
  466.             if(ismouseclick(WM_LBUTTONDOWN))
  467.             {
  468.                 clearmouseclick(WM_LBUTTONDOWN);
  469.                 if(mousex()> window_lenght/2-100 && mousex()<window_lenght/2+100)
  470.                     if(mousey()>window_height/5+260 && mousey()< window_height/5 +300)
  471.                     {
  472.                         cleardevice();
  473.                         selectedBackToMM=TRUE;
  474.                     }
  475.             }
  476. }
  477.  
  478. void draw_Play_Menu()
  479. {
  480.     int c[]= {window_lenght/2-130,window_height/3,window_lenght/2+130,window_height/3,window_lenght/2+130,window_height/3+30,window_lenght/2-130,window_height/3+30,window_lenght/2-130,window_height/3};
  481.     int c2[]= {0,0,1000,0,1000,600,0,600,0,0};
  482.     setfillstyle(SOLID_FILL,BLACK);
  483.     fillpoly(5,c2);
  484.     setfillstyle(SOLID_FILL,LIGHTGRAY);
  485.     setbkcolor(LIGHTGRAY);
  486.     fillpoly(5,c);
  487.     c[1]+=50; c[3]+=50;c[5]+=50;c[7]+=50; c[9]+=50;
  488.     fillpoly(5,c);
  489.     c[1]+=100; c[3]+=100;c[5]+=120;c[7]+=120; c[9]+=100;
  490.     fillpoly(5,c);
  491.     c[1]+=70; c[3]+=70;c[5]+=50;c[7]+=50; c[9]+=70;
  492.     fillpoly(5,c);
  493.     setcolor(BLACK);
  494.     line(window_lenght/2-80,window_height/3+150,window_lenght/2-80,window_height/3+200);
  495.     line(window_lenght/2+80,window_height/3+150,window_lenght/2+80,window_height/3+200);
  496.     line(window_lenght/2-79,window_height/3+150,window_lenght/2-79,window_height/3+200);
  497.     line(window_lenght/2+81,window_height/3+150,window_lenght/2+81,window_height/3+200);
  498.     line(window_lenght/2-81,window_height/3+150,window_lenght/2-81,window_height/3+200);
  499.     line(window_lenght/2+79,window_height/3+150,window_lenght/2+79,window_height/3+200);
  500.     settextstyle(BOLD_FONT,HORIZ_DIR,5);
  501.     outtextxy(window_lenght/2-117, window_height/3+155, "-");
  502.     outtextxy(window_lenght/2+95, window_height/3+155, "+");
  503.     setcolor(BLUE);
  504.     settextstyle(BOLD_FONT,HORIZ_DIR,1);
  505.     outtextxy(window_lenght/2-110,window_height/3+7,"PLAYER VERSUS PLAYER");
  506.     outtextxy(window_lenght/2-122,window_height/3+57,"PLAYER VERSUS COMPUTER");
  507.     outtextxy(window_lenght/2-95, window_height/3+227, "BACK TO MAIN MENU");
  508.     settextstyle(BOLD_FONT,HORIZ_DIR,4);
  509.     setcolor(BLUE);
  510.     bgiout<<board_Size;
  511.     outstreamxy(window_lenght/2-3, window_height/3+162);
  512.     settextstyle(BOLD_FONT,HORIZ_DIR, 7);
  513.     setcolor(YELLOW);
  514.     setbkcolor(BLACK);
  515.     outtextxy(window_lenght/3-110,window_height/4-70, "PLAYING OPTIONS");
  516.     settextstyle(BOLD_FONT,HORIZ_DIR,3);
  517.     setcolor(RED);
  518.     outtextxy(window_lenght/2-120,window_height/3+120,"CHOOSE BOARD SIZE");
  519.     settextstyle(BOLD_FONT,HORIZ_DIR,1);
  520.     outtextxy(window_lenght/4-110, window_height/3+20, "CHOOSE PLAYER1 COLOR");
  521.     outtextxy(window_lenght-360, window_height/3+20, "CHOOSE PLAYER2 COLOR");
  522.     setcolor(BLUE_COLOR_Player1);
  523.     setfillstyle(SOLID_FILL,BLUE_COLOR_Player1);
  524.     setcolor(BLUE_COLOR_Player1);
  525.     fillellipse(window_lenght/4-50, window_height/3+65, 15, 15);
  526.     setcolor(GREEN_COLOR_Player1);
  527.     setfillstyle(SOLID_FILL,GREEN_COLOR_Player1);
  528.     setcolor(GREEN_COLOR_Player1);
  529.     fillellipse(window_lenght/4, window_height/3+65, 15, 15);
  530.     setcolor(PINK_COLOR_Player1);
  531.     setfillstyle(SOLID_FILL,PINK_COLOR_Player1);
  532.     setcolor(PINK_COLOR_Player1);
  533.     fillellipse(window_lenght/4+50, window_height/3+65, 15, 15);
  534.     setcolor(RED_COLOR_Player2);
  535.     setfillstyle(SOLID_FILL,RED_COLOR_Player2);
  536.     setcolor(RED_COLOR_Player2);
  537.     fillellipse(window_lenght-300, window_height/3+65, 15, 15);
  538.     setcolor(YELLOR_COLOR_Player2);
  539.     setfillstyle(SOLID_FILL,YELLOR_COLOR_Player2);
  540.     setcolor(YELLOR_COLOR_Player2);
  541.     fillellipse(window_lenght-250, window_height/3+65, 15, 15);
  542.     setcolor(GRAY_COLOR_Player2);
  543.     setfillstyle(SOLID_FILL,GRAY_COLOR_Player2);
  544.     setcolor(GRAY_COLOR_Player2);
  545.     fillellipse(window_lenght-200, window_height/3+65, 15, 15);
  546.  
  547. }
  548.  
  549. void start_PVP_Game()
  550. {
  551.     cleardevice();
  552.     initMatrice(teren, board_Size);
  553.     radius= (board_Size<16 && board_Size!=12 && board_Size!= 13)? (25-(2*board_Size)) : 3;
  554.     initTable(board_Size,Player1_Color_Choice, Player2_Color_Choice);
  555.     while(1)
  556.     {
  557.         player1_Move();
  558.         player2_Move();
  559.         for(int i=0; i<=2*board_Size; i++)
  560.     {
  561.         for(int j=0; j<=2*board_Size; j++)
  562.             cout<<teren[i][j]<<' ';
  563.         cout<<endl;
  564.     }
  565.     }
  566. }
  567.  
  568. void play_Menu()
  569. {
  570.     draw_Play_Menu();
  571.     bool selectedOption = FALSE;
  572.     while(!selectedOption)
  573.             if(ismouseclick(WM_LBUTTONDOWN))
  574.             {
  575.                 clearmouseclick(WM_LBUTTONDOWN);
  576.                 if (mousex()>window_lenght/2-130 && mousex()<window_lenght/2+130)
  577.                     if(mousey()>window_height/3 && mousey()<window_height/3 +30)
  578.                     {
  579.                         start_PVP_Game();
  580.                         cleardevice();
  581.                         selectedOption=TRUE;
  582.                     }
  583.                 if (mousex()>window_lenght/2-130 && mousex()<window_lenght/2-80)
  584.                     if(mousey()>window_height/3+150 && mousey()<window_height/3 +180)
  585.                         if(board_Size>=4)
  586.                             {
  587.                             board_Size--;
  588.                             setbkcolor(LIGHTGRAY);
  589.                             settextstyle(BOLD_FONT,HORIZ_DIR,4);
  590.                             setcolor(BLUE);
  591.                             bgiout<<board_Size;
  592.                             outstreamxy(window_lenght/2-3, window_height/3+162);
  593.                             setcolor(WHITE);
  594.                             }
  595.                 if (mousex()>window_lenght/2+80 && mousex()<window_lenght/2+130)
  596.                     if(mousey()>window_height/3+150 && mousey()<window_height/3 +180)
  597.                         if(board_Size<20)
  598.                             {
  599.                             board_Size++;
  600.                             setbkcolor(LIGHTGRAY);
  601.                             settextstyle(BOLD_FONT,HORIZ_DIR,4);
  602.                             setcolor(BLUE);
  603.                             bgiout<<board_Size;
  604.                             outstreamxy(window_lenght/2-3, window_height/3+162);
  605.                             setcolor(BLUE);
  606.                             }
  607.                 if(mousey()>window_height/3+50 && mousey()<window_height/3+80)
  608.                     {if(mousex()>window_lenght/4-65 && mousex()<window_lenght/4-35)
  609.                         {   Player1_Color_Choice=BLUE;}
  610.                     else if(mousex()>window_lenght/4-15 && mousex()<window_lenght/4+15)
  611.                             { Player1_Color_Choice=LIGHTGREEN;  }
  612.                     else if(mousex()>window_lenght/4+35 && mousex()<window_lenght/4+65)
  613.                             {   Player1_Color_Choice=LIGHTMAGENTA;}
  614.                     else if(mousex()>window_lenght-315 && mousex()<window_lenght-285)
  615.                             {   Player2_Color_Choice=RED;}
  616.                     else if (mousex()>window_lenght-265 && mousex()<window_lenght-235)
  617.                             {   Player2_Color_Choice=YELLOW;   }
  618.                     else if(mousex()>window_lenght-215 &&mousex()<window_lenght-185)
  619.                             {   Player2_Color_Choice=LIGHTGRAY; }
  620.                     }
  621.                 if (mousex()>window_lenght/2-130 && mousex()<window_lenght/2+130)
  622.                     if(mousey()>window_height/3+220 && mousey()<window_height/3 +250)
  623.                     {
  624.                         cleardevice();
  625.                         selectedOption=TRUE;
  626.                     }
  627.  
  628.             }
  629.  
  630. }
  631.  
  632. void draw_Main_Menu()
  633. {
  634.     int c[]= {window_lenght/2 - 55,window_height/3 - 15,window_lenght/2 + 55,window_height/3 - 15,window_lenght/2 + 55,window_height/3 + 15,window_lenght/2 - 55,window_height/3 + 15 , window_lenght/2 - 55,window_height/3 - 15};
  635.     int c2[]= {0,0,1000,0,1000,600,0,600,0,0};
  636.     setfillstyle(SOLID_FILL,BLACK);
  637.     fillpoly(5,c2);
  638.     setfillstyle(SOLID_FILL,LIGHTGRAY);
  639.     fillpoly(5,c);
  640.     c[0]-=60; c[1]+= 60; c[2]+=60; c[3]+=60; c[4]+=60; c[5]+=60; c[6]-=60; c[7]+=60; c[8]-= 60; c[9]+=60;
  641.     fillpoly(5,c);
  642.     c[0]+=70; c[1]+= 60; c[2]-=70; c[3]+=60; c[4]-=70; c[5]+=60; c[6]+=70; c[7]+=60; c[8]+= 70; c[9]+=60;
  643.     fillpoly(5,c);
  644.     setcolor(BLUE);
  645.     settextstyle(EUROPEAN_FONT,HORIZ_DIR,2);
  646.     setbkcolor(LIGHTGRAY);
  647.     outtextxy(window_lenght/2 - 37,window_height/3 - 10 ,"PLAY");
  648.     outtextxy(window_lenght/2 -105 , window_height/3+50, "INSTRUCTIONS");
  649.     settextstyle(BOLD_FONT,HORIZ_DIR, 5);
  650.     setcolor(YELLOW);
  651.     setbkcolor(BLACK);
  652.     outtextxy(40, 100, "WELCOME TO THE BOARD GAME OF BRIDG-IT");
  653.     setcolor(RED);
  654.     setbkcolor(LIGHTGRAY);
  655.     settextstyle(EUROPEAN_FONT,HORIZ_DIR,2);
  656.     outtextxy(window_lenght/2 - 35, window_height/3 + 110, "QUIT");
  657.  
  658.  
  659. }
  660.  
  661.  
  662.  
  663. void main_Menu()
  664. {
  665.     draw_Main_Menu();
  666.     bool selectedOption = FALSE;
  667.     while(!selectedOption)
  668.             if(ismouseclick(WM_LBUTTONDOWN))
  669.             {
  670.                 clearmouseclick(WM_LBUTTONDOWN);
  671.                 if(mousex()> window_lenght/2-55 && mousex()<window_lenght/2+55)
  672.                     if(mousey()> window_height/3-15 && mousey()< window_height/3 + 15)
  673.                     {
  674.                         play_Menu();
  675.                         draw_Main_Menu();
  676.                     }
  677.                 if(mousex()> window_lenght/2-115 && mousex()<window_lenght/2+115)
  678.                     if(mousey()> window_height/3+45 && mousey()< window_height/3 + 75)
  679.                         {instructions_Page();
  680.                         draw_Main_Menu();}
  681.                 if(mousex()> window_lenght/2 - 45 && mousex()<window_lenght/2 +45)
  682.                     if(mousey()>window_height/3 + 105 && mousey()<window_height/3+135)
  683.                         {   selectedOption=TRUE; }
  684.  
  685.             }
  686.  
  687. }
  688. int main()
  689. {
  690.     initwindow(window_lenght, window_height, "Bridg-it");
  691.     main_Menu();
  692.     closegraph();
  693.     return 0;
  694. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement