Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <graphics.h>
- #include <winbgim.h>
- #include <conio.h>
- #include <windows.h>
- #include <math.h>
- using namespace std;
- #define pod_p1 10
- #define pod_p2 20
- int radius;
- int window_lenght =1000;
- int window_height=600;
- int teren[120][120];
- int n;
- void initMatrice(int teren[120][120],int n)
- {
- int i,j;
- for(i=1; i<=2*n-1; i++)
- for (j=1; j<=2*n-1; j++)
- {
- if(j%2==1 && i%2==0)
- {
- teren[i][j]=1;
- teren[j][i]=2;
- }
- }
- for(i=0; i<2*n+1; i++)
- teren[i][0]=teren[0][i]=teren[2*n][i]=teren[i][2*n]=-1;
- }
- void creazaPod(int i, int j, char *dir)
- {
- if (strcmp(dir, "sus")==0)
- {
- if (teren[i-1][j]==0 )
- {
- if(j%2==1 && i%2==0 && i!=1)
- {
- teren[i-1][j]=pod_p1;
- setcolor(BLUE);
- 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));
- 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));
- 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));
- }
- else if(j%2==0 && i%2==1 && i!=2)
- {
- teren[i-1][j]=pod_p2;
- setcolor(RED);
- 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);
- 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);
- 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 );
- }
- }
- }
- if (strcmp(dir, "jos")==0)
- {
- if (teren[i+1][j]==0)
- {
- if(j%2==1 && i%2==0 && i!=2*n-2)
- {
- teren[i+1][j]=pod_p1;
- setcolor(BLUE);
- 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));
- 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));
- 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));
- }
- else if(j%2==0 && i%2==1 && i!=2*n-1)
- {
- teren[i+1][j]=pod_p2;
- setcolor(RED);
- 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);
- 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);
- 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 );
- }
- }
- }
- if (strcmp(dir, "st")==0)
- {
- if (teren[i][j-1]==0 )
- if(j%2==1 && i%2==0 && j!=1)
- {
- teren[i][j-1]=pod_p1;
- setcolor(BLUE);
- 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));
- 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));
- 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));
- }
- else if(j%2==0 && i%2==1 && j!=2)
- {
- teren[i][j-1]=pod_p2;
- setcolor(RED);
- 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);
- 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);
- 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);
- }
- }
- if (strcmp(dir, "dr")==0)
- {
- if (teren[i][j+1]==0 )
- if(j%2==1 && i%2==0 && j!= 2*n -1)
- {
- teren[i][j+1]=pod_p1;
- setcolor(BLUE);
- 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));
- 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));
- 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));
- }
- else if(j%2==0 && i%2==1 && j!=2*n-2)
- {
- teren[i][j+1]=pod_p2;
- setcolor(RED);
- 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);
- 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);
- 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);
- }
- }
- }
- bool apasatInCercPl1(int &x,int &y)
- {
- for(int i=1; i<=n; i++)
- for(int j=1; j<n; j++)
- 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 ))
- 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)))
- {
- x=i;
- y=j;
- return 1;
- }
- return 0;
- }
- bool is_Above_the_First(int x1,int y1,int x2,int y2)
- {
- if((x2>x1-radius && x2 < x1+radius) && (y2>y1 - window_height/(2*n) - radius && y2<y1 - window_height/(2*n) + radius) )
- {
- outtext("done");
- return 1;
- }
- else
- return 0;
- }
- bool is_Under_the_First(int x1, int y1, int x2, int y2)
- {
- if((x2>x1-radius && x2 < x1+radius) && (y2>y1 + window_height/(2*n) - radius && y2<y1 + window_height/(2*n) + radius) )
- {
- outtext("done");
- return 1;
- }
- else
- return 0;
- }
- bool is_in_Right_of_First(int x1, int y1, int x2, int y2)
- {
- if((x2>x1-radius + window_lenght/(2*n) && x2 < x1+radius + window_lenght/(2*n)) && (y2>y1 - radius && y2<y1 + radius) )
- {
- outtext("done");
- return 1;
- }
- else
- return 0;
- }
- bool is_in_Left_of_First(int x1, int y1, int x2, int y2)
- {
- if((x2>x1-radius - window_lenght/(2*n) && x2 < x1+radius - window_lenght/(2*n)) && (y2>y1 - radius && y2<y1 + radius) )
- {
- outtext("done");
- return 1;
- }
- else
- return 0;
- }
- void highlight_Possible_Bridges(int linie, int coloana)
- {
- if(1);
- }
- void player1_Move()
- {
- int x1,x2,y1,y2,coloana,linie;
- bool lineWasDrawn=FALSE, selectedAproperPosition=FALSE ;
- while(!lineWasDrawn)
- {
- while(!selectedAproperPosition)
- if(ismouseclick(WM_LBUTTONDOWN))
- {
- clearmouseclick(WM_LBUTTONDOWN);
- coloana=mousex();
- linie=mousey();
- if(apasatInCercPl1(coloana,linie) )
- {
- x1=mousex();
- y1=mousey();
- selectedAproperPosition=TRUE;
- }
- }
- selectedAproperPosition=FALSE;
- while(!selectedAproperPosition)
- {
- if(ismouseclick(WM_LBUTTONDOWN))
- {
- clearmouseclick(WM_LBUTTONDOWN);
- int x2=mousex(),y2=mousey();
- if(is_Above_the_First(x1,y1,x2,y2)==1 && teren[coloana][linie-1] != -1)
- {
- creazaPod(2*linie,2*coloana -1,"sus");
- lineWasDrawn=TRUE;
- selectedAproperPosition=TRUE;
- }
- else if(is_Under_the_First(x1,y1,x2,y2) && teren[coloana][linie+1] != -1)
- {
- creazaPod(2*linie,2*coloana -1,"jos");
- lineWasDrawn=TRUE;
- selectedAproperPosition=TRUE;
- }
- else if(is_in_Right_of_First(x1,y1,x2,y2) && teren[coloana+1][linie]!= -1)
- {
- creazaPod(2*linie,2*coloana -1,"dr");
- lineWasDrawn=TRUE;
- selectedAproperPosition=TRUE;
- }
- else if (is_in_Left_of_First(x1,y1,x2,y2)&& teren[coloana-1][linie]!= -1)
- {
- creazaPod(2*linie,2*coloana -1,"st");
- lineWasDrawn=TRUE;
- selectedAproperPosition=TRUE;
- }
- }
- }
- }
- }
- bool apasatInCercPl2(int &x,int &y)
- {
- //window_lenght/4 + ((window_lenght/2)/n)*i, window_height/4 + ((window_height/2)/n)*j - 2*radius
- for(int i=1; i<n; i++)
- for(int j=1; j<=n; j++)
- if((x>window_lenght/4 + ((window_lenght/2)/n)*i - radius) && (x<window_lenght/4 + ((window_lenght/2)/n)*i + radius ))
- if((y>( window_height/4 + ((window_height/2)/n)*j - 3*radius)) && (y<( window_height/4 + ((window_height/2)/n)*j - 3*radius)))
- {
- x=i;
- y=j;
- outtext("True");
- return 1;
- }
- return 0;
- }
- void player2_Move()
- {
- int x1,x2,y1,y2,coloana,linie;
- bool lineWasDrawn=FALSE, selectedAproperPosition=FALSE ;
- while(!lineWasDrawn)
- {
- while(!selectedAproperPosition)
- if(ismouseclick(WM_LBUTTONDOWN))
- {
- clearmouseclick(WM_LBUTTONDOWN);
- coloana=mousex();
- linie=mousey();
- if(apasatInCercPl2(coloana,linie) )
- {
- x1=mousex();
- y1=mousey();
- selectedAproperPosition=TRUE;
- }
- }
- selectedAproperPosition=FALSE;
- while(!selectedAproperPosition)
- {
- if(ismouseclick(WM_LBUTTONDOWN))
- {
- clearmouseclick(WM_LBUTTONDOWN);
- int x2=mousex(),y2=mousey();
- if(is_Above_the_First(x1,y1,x2,y2)==1 && teren[coloana][linie-1] != -1)
- {
- creazaPod(2*linie,2*coloana -1,"sus");
- lineWasDrawn=TRUE;
- selectedAproperPosition=TRUE;
- }
- else if(is_Under_the_First(x1,y1,x2,y2) && teren[coloana][linie+1] != -1)
- {
- creazaPod(2*linie,2*coloana -1,"jos");
- lineWasDrawn=TRUE;
- selectedAproperPosition=TRUE;
- }
- else if(is_in_Right_of_First(x1,y1,x2,y2) && teren[coloana+1][linie]!= -1)
- {
- creazaPod(2*linie,2*coloana -1,"dr");
- lineWasDrawn=TRUE;
- selectedAproperPosition=TRUE;
- }
- else if (is_in_Left_of_First(x1,y1,x2,y2)&& teren[coloana-1][linie]!= -1)
- {
- creazaPod(2*linie,2*coloana -1,"st");
- lineWasDrawn=TRUE;
- selectedAproperPosition=TRUE;
- }
- }
- }
- }
- }
- void initTable(short int n)
- {
- 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};
- setfillstyle(SOLID_FILL,WHITE);
- fillpoly(5,c2);
- setfillstyle(SOLID_FILL,BLACK);
- fillpoly(5,c);
- setcolor(BLUE);
- setfillstyle(SOLID_FILL,BLUE);
- for(i=1; i<=n; i++)
- for(j=1; j<n; j++)
- 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);
- setcolor(RED);
- setfillstyle(SOLID_FILL,RED);
- for(i=1; i<n; i++)
- for(j=1; j<=n; j++)
- fillellipse( window_lenght/4 + ((window_lenght/2)/n)*i, window_height/4 + ((window_height/2)/n)*j - 2*radius, radius,radius);
- setcolor(BLACK);
- setbkcolor(WHITE);
- settextstyle(BOLD_FONT,HORIZ_DIR,7);
- outtextxy(350,75,"BRIDG-IT");
- }
- int main()
- {
- cout<<"Dati lungimea marimea de joc: ";
- cin>>n;
- radius= (n<16 && n!=12 && n!= 13)? (25-(2*n)) : 3;
- initwindow(window_lenght, window_height, "Bridg-it");
- initMatrice(teren, n);
- initTable(n);
- for(int i=0; i<=2*n; i++)
- {
- for(int j=0; j<=2*n; j++)
- cout<<teren[i][j]<<' ';
- cout<<endl;
- }
- int j=0;
- while(j < 10)
- {player1_Move();
- //player2_Move();
- }
- for(int i=1; i<=2*n-1; i++)
- {
- for(int j=1; j<=2*n-1; j++)
- cout<<teren[i][j]<<' ';
- cout<<endl;
- }
- getch();
- closegraph();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement