Mega Code Archive

 
Categories / C / Games Graphic
 

Egg Game

#include"dos.h" #include"graphics.h" #include<stdio.h> #include<conio.h> #include<process.h> #include<dos.h> #include<stdlib.h> #include<iostream.h> union REGS i,o; main() { FILE *fp; fp=fopen("record.txt","r"); if(fp=NULL) cout<<"THE GAME HAS SOME PROBLEMS FOR MORE DETAILS CONTECT varun..."; void help(); int initmouse(); int restrictmouseptr(int,int,int,int); int getmousepos(int *,int *,int *); int showmouseptr(); int gd=DETECT,gm,maxx,maxy,x,y,button; initgraph(&gd,&gm,"c:\turboc3\bin"); //circle(100,100,40); int count=0; maxx=getmaxx(); maxy=getmaxy(); // rectangle(0,0,maxx,maxy); setbkcolor(1); setviewport(0,0,maxx,maxy,1); gotoxy(26,1); //printf("mouse demonstration program"); if(initmouse()==0) { closegraph(); restorecrtmode(); //to go back to normal graphics mode or deleting viewport. printf(" mouse driver not loaded"); exit(1); } restrictmouseptr(0,getmaxy()-20,maxx,getmaxy()-15); //showmouseptr(); //gotoxy(1,2); //printf("left button"); //gotoxy(15,2); //printf("right button"); //printf("press any key to exit...."); int a=30;int b=0; setcolor(0); setfillstyle(1,15); int score=0; count=20; int s=5; int level=0; char name[40]; gotoxy(5,2); cout<<"PLEASE ENTER YOUR SWEET NAME::-"; gets(name); gotoxy(5,2); cout<<" "; while(!kbhit()) { getmousepos(&button,&x,&y); // gotoxy(5,3); // (button&1)==1 ? printf("down") : printf("up"); //gotoxy(20,3); // (button&1)==2 ? printf("down") : printf("up"); setcolor(15); setfillstyle(1,15); fillellipse(a,b,10,15); if((b>getmaxy()-20)&&(b<=getmaxy()-15)) { if(a>=(x-20)&&(a<=(x+60))) { score+=10; gotoxy(320,2); textcolor(13); cout<<"your score: "<<score; } } if(b>getmaxy()+40) { b=0; a=random(getmaxx()); gotoxy(10,2); cout<<"eggs left: "<<count; count--; if(count==-1) { gotoxy(32,10); cout<<"LEVEL COMPLETED."; level++; if(level==4) { goto varun; } count=10; s++; getch(); gotoxy(32,10); cout<<" "; } } setcolor(10); line(x,getmaxy(),x+40,getmaxy()); line(x,getmaxy(),x-20,getmaxy()-20); line(x+40,getmaxy(),x+60,getmaxy()-20); line(x-20,getmaxy()-20,x+60,getmaxy()-20); delay(10); setcolor(0); line(x,getmaxy(),x+40,getmaxy()); line(x,getmaxy(),x-20,getmaxy()-20); line(x+40,getmaxy(),x+60,getmaxy()-20); line(x-20,getmaxy()-20,x+60,getmaxy()-20); setfillstyle(1,0); fillellipse(a,b,10,15); b+=s; } varun: FILE *p; p=fopen("RECORD.TXT","w+"); if(p==NULL) cout<<"DATABASE NOT ACCESSABLE"; fputc('b',p); gotoxy(30,12); cout<<"EXCELLENT WORK "<<name; gotoxy(33,15); cout<<"GAME OVER. "; gotoxy(32,18); cout<<"YOUR SCORE:"<<score; gotoxy(30,10); char h_score=0; h_score=fgetc(fp); cout<<"GREATEST SCORE::"<< "560...."; char varun=fgetc(fp); getch(); getch(); } initmouse() { i.x.ax=0;//for initialising mouse. int86(0x33,&i,&o); return(o.x.ax); } showmouseptr() { i.x.ax=1; // for displaying mouse pointer. int86(0x33,&i,&o); } restrictmouseptr(int x1,int y1,int x2,int y2) { i.x.ax=7; //to define the upper left boundry of mouse. i.x.cx=x1; i.x.dx=x2; int86(0x33,&i,&o); i.x.ax=8; //to define the bottom right boundry of mouse. i.x.cx=y1; i.x.dx=y2; int86(0x33,&i,&o); } getmousepos(int *button,int *x, int *y) { i.x.ax=3; //to move mouse. int86(0x33,&i,&o); *button=o.x.bx; *x=o.x.cx; *y=o.x.dx; }