Thursday, November 18, 2010

Catching a fish in C

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void fish();
void fishcatch();
int fishx=0,fishy=460,fishang=0,tempx,tempy,fishx2=350,fishy2=400;
void main()
{
int gdriver = DETECT, gmode, errorcode;
int x,y,ch,yincr=0;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
x=350; y=240;

while(!kbhit())
{
rectangle(-1,240,641,481);
setfillstyle(1,BLUE);
floodfill(1,241,15);
line(x,y,x+100,y);
line(x+100,y,x+130,y-20);
line(x,y,x-30,y-20);
line(x-30,y-20,x+130,y-20);
setfillstyle(1,BROWN);
floodfill(x+1,y-1,15);
arc(x+50,y-20,0,180,15);
setfillstyle(1,RED);
floodfill(x+50,y-21,15);
circle(x+50,y-40,6);
setfillstyle(1,LIGHTGRAY);
floodfill(x+50,y-41,15);
delay(50);
cleardevice();
if(x>=300)
x=x-1;
else if(y+yincr<=400)
{
if(fishx<330)
yincr++;
}
line(x+40,y,x+50,y+yincr);

if(x<=350)
{
fishx++;
if(fishx>=330)
{
if(yincr>=0)
{
fishcatch();
fishy2--;
yincr--;
}
else
{
cleardevice();
printf("Fish curry: Rs.15/-");
getch();
exit(0);
}
}
else
{
fish();

if(y+yincr>=390)
fishy=fishy-0.5;

if(fishy<=400)
fishy=400;

if(fishx>=330)
fishx=330;
}
}

}


if(kbhit())
{
//printf("%c",getch());
}
getch();
}


void fish()
{
line(fishx,fishy,fishx+10,fishy-5);
line(fishx,fishy,fishx+10,fishy+5);
line(fishx+10,fishy-5,fishx+20,fishy);
line(fishx+20,fishy,fishx+10,fishy+5);
line(fishx,fishy,fishx-3,fishy-3);
line(fishx-3,fishy-3,fishx-3,fishy+3);
line(fishx-3,fishy+3,fishx,fishy);
setfillstyle(1,BROWN);
floodfill(fishx+2,fishy,15);
floodfill(fishx-1,fishy,15);
}

void fishcatch()
{
line(fishx2,fishy2,fishx2+5,fishy2+10);
line(fishx2,fishy2,fishx2-5,fishy2+10);
line(fishx2+5,fishy2+10,fishx2,fishy2+20);
line(fishx2-5,fishy2+10,fishx2,fishy2+20);
line(fishx2,fishy2,fishx2+3,fishy2+23);
line(fishx2,fishy2,fishx2-3,fishy2+23);
line(fishx2+3,fishy2+23,fishx2-3,fishy2+23);
setfillstyle(1,BROWN);
floodfill(fishx2,fishy2+2,15);
floodfill(fishx2,fishy2+22,15);
}

0 comments:

Post a Comment

Contact Form

Name

Email *

Message *

The Insane Techie - Android App

Launched an android app for the blog on 07th June 2016. Get it from google play store... Tips for using the app Use in landscape mo...