TIC TAC TOE with mouse

1,115 views
1,019 views

Published on

play game and enjoy..

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,115
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

TIC TAC TOE with mouse

  1. 1. TIC TAC TOE COMPUTER-PROGRAMMING
  2. 2. Main program:#include<stdio.h>#include<dos.h>#include<conio.h>//-----------------------------------------------------------//-------here is the section which has functions for mouse//-----------------------------------------------------------union REGS in,out; //the unions int callmouse(void) { in.x.ax=1; int86(51,&in,&out); return (1); //shows successful call of the mouse call func } void mouseposi(int* xpos,int* ypos,int* click) { in.x.ax=3; // telling state int86(51,&in,&out); (*click)=out.x.bx; //used for knowing the state of click . . (*xpos)=out.x.cx; //simply tells x position . . (*ypos)=out.x.dx; //simply tells y position . . } int mousehide() { in.x.ax=2; //hiding state int86(51,&in,&out); return 1; } void setposi(int* xpos,int* ypos) { in.x.ax=4; // inputting state that mouse will take input and //will aquire that position , , .. in.x.cx=*xpos; in.x.dx=*ypos; int86(51,&in,&out); }int jitao=0;char i; //basic logic of the game . . . . //the array containing all the game . . .
  3. 3. char dabby[6][6]={ {" | | "}, {"-----"}, {" | | "}, {"-----"}, {" | | "},};// This function is used to print boxes for Tic Tac Toevoid printkd(void){ printf("n"); for(int i=0;i<5;i++) { for(int j=0;j<5;j++) { printf("%c",dabby[i][j]); } printf("n"); }printf("nn");}// This function is used for player 1 turn....void player1(void){ clrscr(); int x; int y; int mx = 0,my =0,click = 0; int sx=25,sy=25; callmouse(); setposi(&sx,&sy); printkd(); while(1) { mouseposi(&mx,&my,&click); //ifs for fist row . . .. . . . . if( (mx>=0 && mx <16) && (my>=0 && my<17) && click ==1) { dabby[0][0] = X; return; } else if((mx>=16 && mx <33) && (my>=0 && my<=17) && click ==1)
  4. 4. { dabby[0][2] = X;return;}else if((mx>=33 && mx <50) && (my>=0 && my<=17) && click ==1){ dabby[0][4] = X; return;}//ifs for second row . . .. . . . .if((mx>=0 && mx <16) && (my>=17 && my<32) && click ==1){ dabby[2][0] = X;return;}else if((mx>=16 && mx <33) && (my>=17 && my<=32) && click ==1){ dabby[2][2] = X;return;}else if((mx>=33 && mx <50) && (my>=17 && my<=32) && click ==1){ dabby[2][4] = X; return;} //ifs for 3rd row . . .. . . . .if((mx>=0 && mx <16) && (my>=33 && my<50) && click ==1){ dabby[4][0] = X;return;}else if((mx>=16 && mx <33) && (my>=33 && my<=50) && click ==1){ dabby[4][2] = X;return;}else if((mx>=33 && mx <50) && (my>=33 && my<=50) && click ==1){ dabby[4][4] = X; return;}
  5. 5. }//end of the while loop . . .. . . . clrscr(); printkd();}// This function is used for Player 2 turn....void player2(void){ clrscr(); int x; int y; int mx = 0,my = 0,click =0; int sx=200,sy=200; callmouse(); setposi(&sx,&sy); printkd(); while(1) { mouseposi(&mx,&my,&click); //ifs for fist row . . .. . . . . if( (mx>=0 && mx <16) && (my>=0 && my<17) && click ==1) { dabby[0][0] = O; return; } else if((mx>=16 && mx <33) && (my>=0 && my<=17) && click ==1) { dabby[0][2] = O; return; } else if((mx>=33 && mx <50) && (my>=0 && my<=17) && click ==1) { dabby[0][4] = O; return; } //ifs for second row . . .. . . . . if((mx>=0 && mx <16) && (my>=17 && my<32) && click ==1) { dabby[2][0] = O;
  6. 6. return; } else if((mx>=16 && mx <33) && (my>=17 && my<=32) && click ==1) { dabby[2][2] = O; return; } else if((mx>=33 && mx <50) && (my>=17 && my<=32) && click ==1) { dabby[2][4] = O; return; } //ifs for 3rd row . . .. . . . . if((mx>=0 && mx <16) && (my>=33 && my<50) && click ==1) { dabby[4][0] = O; return; } else if((mx>=16 && mx <33) && (my>=33 && my<=50) && click ==1) { dabby[4][2] = O; return; } else if((mx>=33 && mx <50) && (my>=33 && my<=50) && click ==1) { dabby[4][4] = O; return; } }//end of the while loop . . .. . . . clrscr(); printkd();}// This funtions is used for Check the turn of player 1 whether he is win or not....void chkp1(void){ gotoxy(5,10); //Raws wise........ if(dabby[0][0] == X && dabby[0][2] == X && dabby[0][4] == X) {jitao=1;printf("nnnPlayer 1 WON ");} else if(dabby[2][0] == X && dabby[2][2] == X && dabby[2][4] == X) {jitao=1;printf("nnnPlayer 1 WON ");} else if(dabby[4][0] == X && dabby[4][2] == X && dabby[4][4] == X)
  7. 7. {jitao=1;printf("nnnPlayer 1 WON ");} //Colomns Wise...... else if(dabby[0][0] == X && dabby[2][0] == X && dabby[4][0] == X) {jitao=1;printf("nnnPlayer 1 WON ");} else if(dabby[0][2] == X && dabby[2][2] == X && dabby[4][2] == X) {jitao=1;printf("nnnPlayer 1 WON ");} else if(dabby[0][4] == X && dabby[2][4] == X && dabby[4][4] == X) {jitao=1;printf("nnnPlayer 1 WON ");} //digonaly else if(dabby[0][0] == X && dabby[2][2] == X && dabby[4][4] == X) {jitao=1;printf("nnnPlayer 1 WON ");} else if(dabby[0][4] == X && dabby[2][2] == X && dabby[4][0] == X) {jitao=1;printf("nnnPlayer 1 WON ");}}// This funtions is used for Check the turn of player 2 whether he is win or not....void chkp2(void){ gotoxy(10,10); //Raws wise........ if(dabby[0][0] == O && dabby[0][2] == O && dabby[0][4] == O) {jitao=1;printf("nnnPlayer 2 WON ");} else if(dabby[2][0] == O && dabby[2][2] == O && dabby[2][4] == O) {jitao=1;printf("nnnPlayer 2 WON ");} else if(dabby[4][0] == O && dabby[4][2] == O && dabby[4][4] == O) {jitao=1;printf("nnnPlayer 2 WON ");} //Colomns Wise...... else if(dabby[0][0] == O && dabby[2][0] == O && dabby[4][0] == O) {jitao=1;printf("nnnPlayer 2 WON ");} else if(dabby[0][2] == O && dabby[2][2] == O && dabby[4][2] == O) {jitao=1;printf("nnnPlayer 2 WON ");} else if(dabby[0][4] == O && dabby[2][4] == O && dabby[4][4] == O) {jitao=1;printf("nnnPlayer 2 WON ");} //digonaly else if(dabby[0][0] == O && dabby[2][2] == O && dabby[4][4] == O) {jitao=1;printf("nnnPlayer 2 WON ");} else if(dabby[0][4] == O && dabby[2][2] == O && dabby[4][0] == O) {jitao=1;printf("nnnPlayer 2 WON ");}}int main(){ callmouse(); int x; char y; gotoxy(10,10); do {
  8. 8. clrscr(); int start=0,end=0; jitao=0; printkd(); printf("Whos Gona Play First???? "); printf("nPlayer 1 or Player 2n"); scanf("%d",&x); clrscr(); printkd(); if(x==1) {start=0;end=9;} else if (x==2) {start=1;end=10;} for(int i=start;i<end;i+=1) { if(i % 2 == 0) { player1(); printf("player 2 turn now %d",i); printkd(); getch(); } else if(i%2!=0) { player2(); printf("player 1 turn now"); printkd(); getch(); getch(); } chkp1(); chkp2(); if(jitao==1) break; } gotoxy(10,20); printf("Hay Man!!! Wana Play Again????n"); y = getch(); } while(y==y); clrscr(); return 0;}

×