123 Eng

Engineering the engineers™


Latest Jobs   Forum Map

 


Home
Source Codes
Engineering Colleges

Training  Reports
Seminar Reports
Placement Papers

Forums

   Computer Science / IT
   Electronics
   Electrical
   Mechanical
   Chemical
   Civil

   CAT / MBA

   GMAT / Foreign MBA
Latest Jobs

Engineering Jobs / Technical Jobs
Management Jobs

Sitemap
Terms of use

Displaying  Source Code(s)  
 

 
Ships Moving & one Ship come first (Mini Project)

--------------------------------------------------------------------------------

Description : Not Specified

Code :
/* Ship design */ // ship.h
ships()
{
rectangle(200,100,450,350);
line(200,225,450,225);
line(325,100,325,350);

arc(260,150,180,0,50);
line(210,150,310,150);
line(210,155,310,155);

line(220,150,220,155);
line(223,150,223,155);
line(297,150,297,155);
line(300,150,300,155);
line(212,150,212,155);
line(308,150,308,155);

line(230,130,230,155);
line(238,130,238,155);
ellipse(234,130,2,1,4,2);

setlinestyle(1,0,0);
line(255,122,240,110);
line(256,122,242,110);
line(258,122,245,110);
line(259,122,247,110);
setlinestyle(0,0,1);
line(250,122,250,155);
line(262,122,262,155);
ellipse(256,122,2,1,6,3);

line(274,130,274,155);
line(282,130,282,155);
ellipse(278,130,2,1,4,2);

rectangle(230,165,238,181);
rectangle(247,165,255,181);
rectangle(264,165,272,181);
rectangle(281,165,289,181);

setlinestyle(1,0,0);
line(230,172,238,172);
line(230,174,238,174);
line(247,172,255,172);
line(247,174,255,174);
line(264,172,272,172);
line(264,174,272,174);
line(281,172,289,172);
line(281,174,289,174);

/* Text line */
setlinestyle(0,0,1);
line(200,202,450,202);
line(200,327,450,327);
/*getch();*/
}





/* Main program */
#include<graphics.h>
#include<alloc.h>
#include<stdio.h>
#include<stdlib.h>
#include<dos.h>
#include "ship.h"
main()
{
int gd=DETECT,gm;
int i,ch,j,k,c;
char choice,char1[1];
int p,q,r,area,*ship1;
initgraph(&gd,&gm,"z:\lngs\tc\bgi");
cleardevice();
settextstyle(GOTHIC_FONT,HORIZ_DIR,2);
setcolor(GREEN);
outtextxy(300,250,"Welcome !");
outtextxy(310,270,"TO");
setcolor(243);
outtextxy(290,290,"Ship Move Game");
sleep(2);
start:
cleardevice();
i=1;
j=1;
p=20;
q=20;
r=20;
setcolor(243);
ships();
select1();
nselect2();
nselect3();
nselect4();
while(j==1)
{
ch=getch();
if(ch==77 && i==1)
{
i=2;
select2();
nselect1();
}
else if(ch==80 && i==1)
{
i=3;
select3();
nselect1();
}
else if(ch==75 && i==2)
{
i=1;
select1();
nselect2();
}
else if(ch==80 && i==2)
{
i=4;
select4();
nselect2();
}
else if(ch==72 && i==3)
{
i=1;
select1();
nselect3();
}
else if(ch==77 && i==3)
{
i=4;
select4();
nselect3();
}
else if(ch==72 && i==4)
{
i=2;
select2();
nselect4();
}
else if(ch==75 && i==4)
{
i=3;
select3();
nselect4();
}
else if(ch==27)
{
setcolor(243);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,1);
outtextxy(250,360,"Exit");
setcolor(GREEN);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(252,385,"Yes");
outtextxy(252,395,"No");
fflush(stdin);
choice=getch();
if(choice=='Y' || choice=='y')
{closegraph();
restorecrtmode();
exit(0);
}
else
{
setcolor(BLACK);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,1);
outtextxy(250,360,"Exit");
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(252,385,"Yes");
outtextxy(252,395,"No");
continue;
}
}
if(ch==13 && i==1)
{
area=imagesize(205,105,320,200);
ship1=malloc(area);
getimage(205,105,320,200,ship1);
j=2;
}

}/*End of while loop */

cleardevice();
settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
for(i=5;i>=0;i--)
{
cleardevice();
setcolor(RED);
outtextxy(300,200,"START");
sprintf(char1,"%d",i);
setcolor(CYAN);
outtextxy(320,220,char1);
sleep(1);
}

cleardevice();
while(p<450 && q<450 && r<450)
{
cleardevice();
p=p+random(10);
putimage(p,20,ship1,XOR_PUT);
q=q+random(10);
putimage(q,170,ship1,XOR_PUT);
r=r+random(10);
putimage(r,320,ship1,XOR_PUT);

if(kbhit())
{
ch=getch();
if(ch==27)
{
outtextxy(250,250,"Exit");
sleep(1);
goto start;
}
}
delay(10000000);
delay(10000000);
delay(10000000);
delay(10000000);
putimage(p,20,ship1,XOR_PUT);
putimage(q,170,ship1,XOR_PUT);
putimage(r,320,ship1,XOR_PUT);
}/* End of while loop */

putimage(p,20,ship1,XOR_PUT);
putimage(q,170,ship1,XOR_PUT);
putimage(r,320,ship1,XOR_PUT);

if(p>q && p>r)
c=1;
else if(q>r && q>p)
c=2;
else c=3;

switch(c)
{
case 1:
for(i=0;i<=20;i++)
{
setcolor(GREEN);
outtextxy(p+120,70,"Win");
delay(1000000000);
delay(1000000000);

setcolor(BLACK);
outtextxy(p+120,70,"Win");
delay(1000000000);
delay(1000000000);
delay(1000000000);
}
break;
case 2:
for(i=0;i<=20;i++)
{
setcolor(GREEN);
outtextxy(q+120,220,"Win");
delay(100000000);

delay(100000000);
setcolor(BLACK);
outtextxy(q+120,220,"Win");
delay(100000000);
delay(100000000);
delay(100000000);
}
break;
case 3:
for(i=0;i<=20;i++)
{
setcolor(GREEN);
outtextxy(r+120,370,"Win");

delay(100000000);
delay(100000000);
setcolor(BLACK);
outtextxy(r+120,370,"Win");
delay(100000000);
delay(100000000);
delay(100000000);
}

}
cleardevice();
outtextxy(300,200,"Game Over");
sleep(1);
goto start;

closegraph();
restorecrtmode();

}



select1()
{
settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);
setcolor(RED);
outtextxy(220,203,"TITANIC1");
}
select2()
{
settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);
setcolor(RED);
outtextxy(345,203,"TITANIC2");
}
select3()
{
settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);
setcolor(RED);
outtextxy(220,328,"TITANIC3");
}
select4()
{
settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);
setcolor(RED);
outtextxy(345,328,"TITANIC4");
}

nselect1()
{
settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);
setcolor(WHITE);
outtextxy(220,203,"TITANIC1");
}
nselect2()
{
settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);
setcolor(WHITE);
outtextxy(345,203,"TITANIC2");
}
nselect3()
{
settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);
setcolor(WHITE);
outtextxy(220,328,"TITANIC3");
}
nselect4()
{
settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);
setcolor(WHITE);
outtextxy(345,328,"TITANIC4");
}


 

 

 

Contribute content or training reports / feedback / Comments
job placement papers
All rights reserved © copyright 123ENG