Thursday, November 18, 2010

Sinking of Titanic

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void titanic(int,int);
void titanics(int,int);
void iceberg();
int poly[]={0,300,640,300,640,480,0,480,0,300};
int ix=1,iy=1;
void main()
{
int gdriver = DETECT, gmode, errorcode;
int maxx, maxy;
int xincr=1,yincr=1,i;
int tempx=400,tempy=300;
int sink=0;
initgraph(&gdriver, &gmode, "c:/tc/bgi");

errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}

while(1)
{
delay(30);
cleardevice();
iceberg();

if(sink==1)
{
tempy+=yincr;
}
else
{
tempx-=xincr;
}

if(tempx<=120)
{
sink=1;
titanics(tempx,tempy);
}
else
{
titanic(tempx,tempy);
}

if(tempy>=600)
break;
}
getch();
}

void titanic(int x,int y)
{
setcolor(15);
line(x,y,x+100,y);
line(x,y,x-20,y-20);
line(x-20,y-20,x+120,y-20);
line(x+120,y-20,x+100,y);
rectangle(x+10,y-30,x+90,y-20);
rectangle(x+20,y-40,x+80,y-30);
rectangle(x+60,y-70,x+70,y-40);
}

void titanics(int x,int y)
{
setcolor(15);
line(x,y,x+100,y-10);
line(x,y,x-20,y-30);
line(x-20,y-20,x+120,y-30);
line(x+120,y-20,x+100,y-10);
rectangle(x+10,y-30,x+90,y-10);
rectangle(x+20,y-40,x+80,y-10);
rectangle(x+60,y-70,x+70,y-10);
}

void iceberg()
{
setcolor(BLUE);
setfillstyle(1,BLUE);
fillpoly(4,poly);
setfillstyle(1,WHITE);
fillellipse(0,300,100,100);
}

0 comments:

Post a Comment

Contact Form

Name

Email *

Message *