int main() { int x,y,cl,prcl,x1,y1,dx,dy; int g=DETECT,m; initgraph(&g,&m,"..\\bgi"); cleardevice(); setposi(10,10); callmouse(); prcl=0; do { mouseposi(&x,&y,&cl); if(cl==prcl && prcl==1) { x1=x; y1=y; while(cl!=0) { mouseposi(&x,&y,&cl); } dx=x-x1; dy=y-y1; gotoxy(2,2); if(dx==0 && dy==0) { gotoxy(2,2); printf("\n\t Mouse Clicked : %+04d,%+04d",x,y); } else { gotoxy(2,3); printf ("\n\tMouse dragged (DX,DY): %+04d,%+04d",dx,dy); } } gotoxy(2,5); printf("\n\tMouse Position is: %03d,%03d",x,y); prcl=cl; }while(!kbhit()); getch(); return 1; }
void menu(int mx,int my) { outline(mx,my); int x,y,cl; settextstyle(DEFAULT_FONT,0,3); setcolor(BLUE); callmouse(); outtextxy((mx/2)-80,50,"MENU"); outtextxy((mx/2)-220,150,"1.PLAY"); outtextxy((mx/2)-220,250,"2.HIGH SCORES"); outtextxy((mx/2)-220,350,"3.EXIT"); char ch; while(1) { altermouse(x,y,cl); if(cl==1) { if(x>(mx/2)-220 && x<(mx/2)-80 && y>150 && y<200) { game(mx,my); } else if(x>(mx/2)-220 && x<(mx/2)+90 && y>250 && y<300) { displayscores(mx,my); } else if(x>(mx/2)-220 && x<(mx/2)-80 && y>350 && y<400) { hidemouse(); closegraph(); exit(0); } } } }
int main() { int x,y,cl,a,b; int g=DETECT,m; initgraph(&g,&m,"..\\bgi"); cleardevice(); a=100; b=400; setposi(&a,&b); callmouse(); do { mouseposi(&x,&y,&cl); gotoxy(10,9); printf("\n\tMouse Position is: %d,%d",x,y); printf("\n\tClick: %d",cl); printf("\n\tPress any key to hide the mouse"); }while(!kbhit()); getch(); mousehide(); printf("\n\n\tPress any key to Exit"); getch(); return 1; }
void main() { int gd=DETECT,gm,x,y,res=-1,clk,chk[3][3],cnt; char *n1,*n2; clrscr(); in.x.ax=8; in.x.cx=0; in.x.dx=480; int86(51,&in,&out); start: cnt=0; for(int i=0;i<3;i++) for(int j=0;j<3;j++) chk[i][j]=0; initgraph(&gd,&gm,"c:\\tc\\bgi"); settextstyle(7,HORIZ_DIR,1); cleardevice(); draw_grid(); callmouse(); while(1) { if(cnt==9) break; back: delay(150); getmouse(x,y,clk); if(clk==1) { if(x>175 && x<240) //1st col { if(y>100 && y<166) //1st row { if(cnt%2==0) { if(chk[0][0]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[0][0]=1; draw_x(175,100); } else { if(chk[0][0]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[0][0]=2; draw_o(175,100); } } else if(y>166 && y<232) //2nd row { if(cnt%2==0) { if(chk[1][0]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[1][0]=1; draw_x(175,166); } else { if(chk[1][0]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[1][0]=2; draw_o(175,166); } } else if(y>232 && y<300) //3rd row { if(cnt%2==0) { if(chk[2][0]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[2][0]=1; draw_x(175,232); } else { if(chk[2][0]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[2][0]=2; draw_o(175,232); } } } else if(x>240 && x<306) //2nd col { if(y>100 && y<166) //1st row { if(cnt%2==0) { if(chk[0][1]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[0][1]=1; draw_x(240,100); } else { if(chk[0][1]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[0][1]=2; draw_o(240,100); } } else if(y>166 && y<232) //2nd row { if(cnt%2==0) { if(chk[1][1]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[1][1]=1; draw_x(240,166); } else { if(chk[1][1]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[1][1]=2; draw_o(240,166); } } else if(y>232 && y<300) //3rd row { if(cnt%2==0) { if(chk[2][1]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[2][1]=1; draw_x(240,232); } else { if(chk[2][1]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[2][1]=2; draw_o(240,232); } } } else if(x>306 && x<375) //3rd col { if(y>100 && y<166) //1st row { if(cnt%2==0) { if(chk[0][2]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[0][2]=1; draw_x(306,100); } else { if(chk[0][2]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[0][2]=2; draw_o(306,100); } } else if(y>166 && y<232) //2nd row { if(cnt%2==0) { if(chk[1][2]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[1][2]=1; draw_x(306,166); } else { if(chk[1][2]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[1][2]=2; draw_o(306,166); } } else if(y>232 && y<300) //3rd row { if(cnt%2==0) { if(chk[2][2]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[2][2]=1; draw_x(306,232); } else { if(chk[2][2]!=0) { outtextxy(80,50,"WRONG INPUT BUDDY !!, TRY AGAIN "); goto back; } chk[2][2]=2; draw_o(306,232); } } } cnt++; } res=win(chk); if(res==1) { settextstyle(7,HORIZ_DIR,1); outtextxy(220,330,"PLAYER_X has WON the Game !!!"); break; } if(res==2) { settextstyle(7,HORIZ_DIR,1); outtextxy(220,330,"PLAYER_O has WON the Game !!!"); break; } } if(res==-1) { settextstyle(7,HORIZ_DIR,1); outtextxy(220,330,"HEY !!! NO ONE WON...."); outtextxy(225,355,"ONE MORE GAME ??? "); if(getche()=='y') { cleardevice(); goto start; } exit(0); } getch(); }
void game(int mx,int my) { cleardevice(); int x,y,cl=0,i,j,ctr=0,points=0,lives=3,dt=100; int *ycoord,*bomby; int delaytime[20]; int randomcolor; int *xcoord,*bombx,numctr=0,playtime=0; int nob=0,bombctr=0,temp,selbomb; callmouse(); setlimits(23,mx-23,23,my-23); delay(100); // ASSIGN THE SPEED for(i=0;i<10;i++){delaytime[i]=i+10;} // ALOCATE MEMORY FOR COORDINATES if((ycoord=(int *)malloc(10))==NULL||(xcoord=(int *)malloc(10))==NULL||(bomby=(int *)malloc(10))==NULL||(bombx=(int *)malloc(10))==NULL) { cout<<"\nMEMORY ALLOCATION ERROR!"; getch(); exit(0); } randomize(); outline(mx,my); //THE GAME BEGINS int start=clock(),end; for(i=0;i<lives;i++) { setcolor(WHITE); circle((mx-200)+(i*20),my-10,6); setfillstyle(SOLID_FILL,RED); floodfill((mx-200)+(i*20),my-10,WHITE); } for(;;) { // ASSIGN COORDINATES TO BOMBS selbomb=random(10); if( (selbomb%7)==0 && nob<=3) { *(bombx+bombctr)=50; *(bomby+bombctr)=random(my-100)+50; bombctr++; nob++; } // ASSIGN COORDINATES TO BUBLES if(numctr<3) { *(xcoord+ctr)=48; *(ycoord+ctr)=random(my-100)+48; numctr++; ctr++; } // DROP THE BOMBS for(i=0;i<nob;i++) { setcolor(WHITE); circle(*(bombx+i),*(bomby+i),22); } // CREATE BUBLES for(i=0;i<numctr;i++) { randomcolor=random(5)+1; setcolor(randomcolor); circle(*(xcoord+i),*(ycoord+i),20); } // MOUSE altermouse(x,y,cl); delay(dt); // CHECK WHAT HAPPENED WITH BUBLES temp=numctr; for(i=0;i<temp;i++) { // CHECK IF BUBLES WERE HIT if(x < *(xcoord+i)+20 && x > *(xcoord+i)-20 && y< *(ycoord+i)+20 && y>*(ycoord+i)-20) { points+=10; numctr--; ctr=i; cleardevice(); outline(mx,my); for(j=0;j<lives;j++) { setcolor(WHITE); circle((mx-200)+(j*20),my-10,6); setfillstyle(SOLID_FILL,RED); floodfill((mx-200)+(j*20),my-10,WHITE); } } // DE-CREATE THE BUBLES setcolor(BLACK); circle(*(xcoord+i),*(ycoord+i),20); // LET THE BUBLES MOVE *(xcoord+i)+=delaytime[i]; // CHECK FOR PLAYER'S DEATH if(xcoord[i]>=mx-48) { numctr--; lives--; if(lives==0){goto again;} for(j=0;j<lives+1;j++) { setcolor(BLUE); circle((mx-200)+(i*20),my-10,6); setfillstyle(SOLID_FILL,BLUE); floodfill((mx-200)+(j*20),my-10,BLUE); } for(j=0;j<lives;j++) { setcolor(WHITE); circle((mx-200)+(j*20),my-10,6); setfillstyle(SOLID_FILL,RED); floodfill((mx-200)+(j*20),my-10,WHITE); } ctr=i; } } // CHECK WHAT HAPPENED WITH THE BOMB temp=nob; for(i=0;i<temp;i++) { // CHECK FOR PLAYERS DEATH AND THE END OF GAME if(x < *(bombx+i)+22 && x > *(bombx+i)-22 && y< *(bomby+i)+22 && y>*(bomby+i)-22) { goto again; } // DE-CREATE THE BOMBS setcolor(BLACK); circle(*(bombx+i),*(bomby+i),22); // LET THE BOMBS MOVE *(bombx+i)+=delaytime[i]; // CHECK FOR THE BOMBS DEATH if(*(bombx+i)>=mx-45) { bombctr=i; nob--; *(bombx+bombctr)=48; *(bomby+bombctr)=random(my-100)+50; nob++; } } end=clock(); playtime=ceill((end-start)/CLK_TCK); if(playtime>10) { dt-=10; start=clock(); } } // THIS IS THE END : again: cleardevice(); outline(mx,my); endgame(points,mx,my); readscore(points); hidemouse(); delete ycoord,xcoord; menu(mx,my); }