Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<graphics.h>
- #include<dos.h>
- void red();
- void green();
- void position1(int,int);
- void position2(int,int);
- void check();
- int turn=1,win=0,xc,yc;char game[3][3];
- union REGS in,out;
- void main()
- {
- int gd=DETECT,gm,errorcode;
- initgraph(&gd,&gm,"D:\\tcc\\BGI");
- in.x.ax=4;
- in.x.cx=0;
- in.x.dx=0;
- int86(0X33,&in,&out);
- in.x.ax=1;
- int86(0X33,&in,&out);
- outtextxy(100,20,"player 1");
- rectangle(100,30,150,80);
- outtextxy(180,20,"player 2");
- rectangle(180,30,230,80);
- red();
- green();
- line(100,100,100,200);//vertical 1
- line(130,100,130,200);//vertical 2
- line(160,100,160,200);//vertical 3
- line(190,100,190,200);//vertical 4
- line(100,130,190,130);//horizontal 1
- line(100,160,190,160);//horizontal 2
- while((turn<=9)&&(win==0))
- { int click=0;
- while(click==0)
- {
- in.x.ax=3;
- int86(51,&in,&out);
- if(out.x.bx==1)
- {
- click=1;
- xc=out.x.cx;
- yc=out.x.dx;
- if(turn%2!=0)//player 1
- {
- setcolor(GREEN);
- circle(xc,yc,3);
- position1(xc,yc);
- }
- else if(turn%2==0)//player 2
- {
- setcolor(RED);
- circle(xc,yc,3);
- position2(xc,yc);
- }
- }
- }//end of inner while
- if(turn>=5)
- check();
- turn++;
- delay(1000);
- }//end of outer while
- if(win==0)
- outtext("draw");
- // delay(3000);
- getch();
- closegraph();
- // printf("....GAME OVER....");
- //getch();
- }//end of main
- void red()
- {
- setcolor(RED);
- circle(205,55,15);
- }
- void green()
- {
- setcolor(GREEN);
- circle(125,55,15);
- setcolor(WHITE);
- }
- void position1(int xc,int yc)
- {
- if(((100<xc)&&(xc<130))&&((100<yc)&&(yc<130)))
- game[0][0]='g';
- else if(((130<xc)&&(xc<160))&&((100<yc)&&(yc<130)))
- game[0][1]='g';
- else if(((160<xc)&&(xc<190))&&((100<yc)&&(yc<130)))
- game[0][2]='g';
- else if(((100<xc)&&(xc<130))&&((130<yc)&&(yc<160)))
- game[1][0]='g';
- else if(((130<xc)&&(xc<160))&&((130<yc)&&(yc<160)))
- game[1][1]='g';
- else if(((160<xc)&&(xc<190))&&((130<yc)&&(yc<160)))
- game[1][2]='g';
- else if(((100<xc)&&(xc<130))&&((160<yc)&&(yc<190)))
- game[2][0]='g';
- else if(((130<xc)&&(xc<160))&&((160<yc)&&(yc<190)))
- game[2][1]='g';
- else if(((160<xc)&&(xc<190))&&((160<yc)&&(yc<190)))
- game[2][2]='g';
- }
- void position2(int xc,int yc)
- {
- if(((100<xc)&&(xc<130))&&((100<yc)&&(yc<130)))
- game[0][0]='r';
- else if(((130<xc)&&(xc<160))&&((100<yc)&&(yc<130)))
- game[0][1]='r';
- else if(((160<xc)&&(xc<190))&&((100<yc)&&(yc<130)))
- game[0][2]='r';
- else if(((100<xc)&&(xc<130))&&((130<yc)&&(yc<160)))
- game[1][0]='r';
- else if(((130<xc)&&(xc<160))&&((130<yc)&&(yc<160)))
- game[1][1]='r';
- else if(((160<xc)&&(xc<190))&&((130<yc)&&(yc<160)))
- game[1][2]='r';
- else if(((100<xc)&&(xc<130))&&((160<yc)&&(yc<190)))
- game[2][0]='r';
- else if(((130<xc)&&(xc<160))&&((160<yc)&&(yc<190)))
- game[2][1]='r';
- else if(((160<xc)&&(xc<190))&&((160<yc)&&(yc<190)))
- game[2][2]='r';
- }
- void check()
- {
- if(turn%2!=0)
- {
- if((game[0][0]==game[0][1])&&(game[0][0]==game[0][2]))//first row
- {
- if(game[0][0]=='g')
- {outtext("player 1 wins");
- win=1;}
- }
- else if((game[0][0]==game[1][1])&&(game[0][0]==game[2][2]))//leading diagonal
- {
- if(game[0][0]=='g')
- { outtext("player 1 wins");
- win=1; }
- }
- else if((game[0][0]==game[1][0])&&(game[0][0]==game[2][0]))//first column
- {
- if(game[0][0]=='g')
- { outtext("player 1 wins");
- win=1;}
- }
- else if((game[1][0]==game[1][1])&&(game[1][0]==game[1][2]))//2nd row
- {
- if(game[1][0]=='g')
- { outtext("player 1 wins");
- win=1;}
- }
- else if((game[2][0]==game[2][1])&&(game[2][0]==game[2][2])) //3rd row
- {
- if(game[2][0]=='g')
- { outtext("player 1 wins");
- win=1; }
- }
- else if((game[0][2]==game[1][1])&&(game[0][2]==game[2][0])) //other diagonal
- {
- if(game[0][2]=='g')
- { outtext("player 1 wins");
- win=1;}
- }
- else if((game[0][1]==game[1][1])&&(game[0][1]==game[2][1])) //2nd column
- {
- if(game[0][1]=='g')
- { outtext("player 1 wins");
- win=1; }
- }
- else if((game[0][2]==game[1][2])&&(game[0][2]==game[2][2])) //3rd column
- {
- if(game[0][2]=='g')
- { outtext("player 1 wins");
- win=1;}
- }
- }
- else if(turn%2==0)
- {
- if((game[0][0]==game[0][1])&&(game[0][0]==game[0][2]))//1st row
- {
- if(game[0][0]=='r')
- { outtext("red wins");
- win=1;}
- }
- else if((game[0][0]==game[1][1])&&(game[0][0]==game[2][2]))//leading diagonal
- {
- if(game[0][0]=='r')
- { outtext("player 2 wins");
- win=1;}
- }
- else if((game[0][0]==game[1][0])&&(game[0][0]==game[2][0])) //1st column
- {
- if(game[0][0]=='r')
- {outtext("player 2 wins");
- win=1;}
- }
- else if((game[1][0]==game[1][1])&&(game[1][0]==game[1][2])) //2nd row
- {
- if(game[1][0]=='r')
- { outtext("player 2 wins");
- win=1; }
- }
- else if((game[2][0]==game[2][1])&&(game[2][0]==game[2][2]))//3rd row
- {
- if(game[2][0]=='r')
- {outtext("player 2 wins");
- win=1;}
- }
- else if((game[0][2]==game[1][1])&&(game[0][2]==game[2][0])) //other diagonal
- {
- if(game[0][2]=='r')
- { outtext("player 2 wins");
- win=1;}
- }
- else if((game[0][1]==game[1][1])&&(game[0][1]==game[2][1])) //2nd column
- {
- if(game[0][1]=='r')
- { outtext("player 2 wins");
- win=1;}
- }
- else if((game[0][2]==game[1][2])&&(game[0][2]==game[2][2])) //3rd column
- {
- if(game[0][2]=='r')
- { outtext("player 2 wins");
- win=1;}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement