A simple simple ball which is bouncing....
#include dos.h
#include iostream.h
#include graphics.h
#include math.h
#include conio.h
void main()
{
int d=DETECT,m;
initgraph(&d,&m,"e:\tcc\bgi");
float x=1,y=0.00000,j=.5,count=.1;
float r=15;
setcolor(14);
line(0,215,650,215);
sleep(1);
for(int k=0;k<=7;k++)
{
for(float i=90;i<270;i+=10)
{
y=cos(((i*22/7)/180))/j;
if(y>0)
y=-y;
x+=5;
setcolor(14);
setfillstyle(1,14);
circle(x,y*100+200,r);
floodfill(x,y*100+200,14);
delay(100);
setcolor(0);
setfillstyle(1,0);
circle(x,y*100+200,r);
floodfill(x,y*100+200,0);
}
j+=count;
count+=.1;
}
getch();
}
Showing posts with label Computer Graphics. Show all posts
Showing posts with label Computer Graphics. Show all posts
Wednesday, October 15, 2008
Friday, October 10, 2008
VIRTUAL DRILLING MACHINE
This is the coding for VIRTUAL DRILLING MACHINE made in C.G and C++
/***************************************************************************/
/* VIRTUAL DRILLING MACHINE */
/* */
/* CG Project */
/* By Sampathirao Muralidhar B */
/* C.K.Pithawala College of Engg. & Tech. */
/* B.E. Computer-III, 5th Sem (6144) */
/***************************************************************************/
#include iostream.h
#include conio.h
#include stdlib.h
#include graphics.h
#include dos.h
#include math.h
#define MAXX 639
#define MAXY 479
#define interval 90
#define w() {setcolor(WHITE);}
#define lg() {setcolor(LIGHTGRAY);}
#define y() {setcolor(YELLOW);}
#define lb() {setcolor(LIGHTBLUE);}
#define lc() {setcolor(YELLOW);} /* label color */
#define normal DARKGRAY
#define shine LIGHTGRAY
/*****************/
/* Global Var */
/*****************/
int ret=0;
static int no=0;
int on_off=-1; /* indicates status of m/c ON->(1) or OFF->(-1) */
int x_limit=0;
static int degree=0;
static int x_co_ord[5],y_co_ord[5];
int reset=0;
int c=7; /* hole color */
/*****************/
void init_arr(int *);
void y_trans();
void y_trans_1();
void y_control(int);
int z_trans(int);
void z_control(void);
void x_control(void);
void x_trans(int);
int table_trans(int);
void point_trans(int,int);
void tool_trans(int);
void operation(void);
void m_on_off(void);
void hole(void);
void s_hole(void);
void label(void);
class stack
{
private:
int poly[8];
int top;
public:
int convert;
stack(int x1,int y1,int x2,int y2)
{
top=-1;
convert=1;
push(x1);
push(y1);
push(x2);
push(y2);
}
void push(int co_ord)
{
if(top==7)
return;
top++;
poly[top]=co_ord;
}
int pop()
{
if(top==-1)
return NULL;
int temp=poly[top];
top--;
return temp;
}
}y_handle(280,312,295,314),
z_handle(260,132,275,135),
table_obj(175,275,205,295),
point_obj(355+30,150+25,0,0),
tool_obj(185,200,196,205);
void calc(int *,int,int,int,int);
void hori_pix(int,int,int,int,int,int,int);
void verti_pix(int,int,int,int,int,int,int);
void line_fill(int,int,int,int,int,int,int,int);
void pixelize(int,int,int,int,int,int,int);
void border(void);
void my_menu();
void menu_access_opt1(void);
void menu_access_opt2(void);
void menu_access_opt3(void);
void draw(void);
int direction(int);
void msg(int,int);
/****************************************************************************/
void my_menu()
{
int i,j;
setcolor(RED+GREEN);
pixelize(RED+GREEN,50,200,65,215,20,1);
outtextxy(70,207,"Parts of Drilling M/C");
pixelize(RED+GREEN,50,220,65,235,20,1);
outtextxy(70,227,"Start virtual drill");
pixelize(RED+GREEN,50,240,65,255,20,1);
outtextxy(70,247,"Exit");
setcolor(LIGHTGRAY);
outtextxy(10,MAXY-30,"\n Press 'm' to access the menu or enjoy the visuals");
again:
while(!kbhit())
{
verti_pix(250,150,350,RED+GREEN,YELLOW,2,10);
}
if(getch()==(int)'m')
{
outtextxy(10,MAXY-15,"\n Use Up & Down arrow key");
menu_access_opt1();
}
else
goto again;
}
/***************************************************************************/
void pixelize(int color,int x1,int y1,int x2,int y2,int delta,int gap)
{
int i,j;
for(i=y1+1;i<=y2-1;i+=gap)
{
for(j=x1+1;j<=x2-1;j+=gap)
{
putpixel(j,i,color);
}
delay(delta);
}
}
/***************************************************************************/
void in_graph()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
}
/***************************************************************************/
my_window()
{
int i=0;
border();
pixelize(RED,3,3,MAXX-3,MAXY-3,0,2);
line_fill(RED,3,3,MAXX-3,MAXY-3,3,2,1);
while(i!=80)
{
setcolor(YELLOW);
line(i*8,4,MAXX-3,4+(i*8));
delay(20);
i=i+1;
}
i=0;
setcolor(YELLOW);
delay(interval);
outtextxy(getmaxx()/2-50,getmaxy()/2,"Welcome to Virtual Drilling");
hori_pix(getmaxx()/2-50,getmaxy()/2+10,getmaxx()/2-50+216,YELLOW,RED,2,10);
setcolor(RED+GREEN);
outtextxy(getmaxx()/2-50,getmaxy()/2+40+10,"CG Project");
delay(interval);
outtextxy(getmaxx()/2-50,getmaxy()/2+40+20,"By Sampathirao Muralidhar");
delay(interval);
outtextxy(getmaxx()/2-50,getmaxy()/2+40+30,"C.K.Pithawala College of Engg. & Tech.");
delay(interval);
outtextxy(getmaxx()/2-50,getmaxy()/2+40+40,"III-Computer (6144)");
delay(interval);
my_menu();
while(i!=80)
{
setcolor(RED);
line(i*8,4,MAXX-3,4+(i*8));
delay(20);
i=i+1;
}
border();
switch(ret)
{
case 1: line_fill(BLACK,3,3,MAXX-3,MAXY-3,3,1,1);
cleardevice();
setcolor(LIGHTBLUE);
outtextxy(240,15,"\n Parts of Drilling M/c");
draw();
label();
break;
case 2: line_fill(BLACK,3,3,MAXX-3,MAXY-3,3,1,1);
cleardevice();
setcolor(LIGHTBLUE);
outtextxy(100,15,"\n Drilling & Milling M/c ");
draw();
operation();
break;
case 3: pixelize(BLACK,3,3,MAXX-3,MAXY-3,0,2);
line_fill(BLACK,3,3,MAXX-3,MAXY-3,0,1,1);
lb();
outtextxy(140,120,"Impossible is not a fact, its an opinion!!");
outtextxy(245,140,"Thanks for visiting");
w();
outtextxy(350,240,"Pree any key to Exit");
getch();
exit(0);
break;
}
return 0;
}
/***************************************************************************/
void hori_pix(int x1,int y,int x2,int color,int dissolve_color,int gap,int wt_time)
{
int x_temp=x1;
while(x_temp<=x2)
{
putpixel(x_temp,y,color);
delay(wt_time);
x_temp+=gap;
}
x_temp=x1;
while(x_temp<=x2)
{
putpixel(x_temp,y,dissolve_color);
delay(wt_time);
x_temp+=gap;
}
}
/***************************************************************************/
void verti_pix(int x,int y1,int y2,int color,int dissolve_color,int gap,int wt_time)
{
int y_temp=y1;
while(y_temp<=y2)
{
putpixel(x,y_temp,color);
delay(wt_time);
y_temp+=gap;
}
y_temp=y1;
while(y_temp<=y2)
{
putpixel(x,y_temp,dissolve_color);
delay(wt_time);
y_temp+=gap;
}
}
/**************************************************************************/
void border()
{
setcolor(WHITE);
rectangle(0,0,MAXX,MAXY);
rectangle(2,2,MAXX-2,MAXY-2);
}
/**************************************************************************/
void menu_access_opt1()
{
int ch;
setcolor(RED+GREEN);
pixelize(RED+GREEN,50,220,65,235,0,1);
outtextxy(70,227,"Start virtual drill");
pixelize(RED+GREEN,50,240,65,255,0,1);
outtextxy(70,247,"Exit");
while(!kbhit())
{
pixelize(YELLOW,50,200,65,215,0,1);
setcolor(YELLOW);
outtextxy(70,207,"Parts of Drilling M/C");
}
ch=getch();
if(ch==13)
ret=1;
else if(ch==80)
{
menu_access_opt2();
}
else if(ch==72)
{
menu_access_opt3();
}
else
menu_access_opt1();
}
/**************************************************************************/
void menu_access_opt2()
{
int ch;
setcolor(RED+GREEN);
pixelize(RED+GREEN,50,200,65,215,0,1);
outtextxy(70,207,"Parts of Drilling M/C");
pixelize(RED+GREEN,50,240,65,255,0,1);
outtextxy(70,247,"Exit");
while(!kbhit())
{
pixelize(YELLOW,50,220,65,235,0,1);
setcolor(YELLOW);
outtextxy(70,227,"Start virtual drill");
}
ch=getch();
if(ch==13)
ret=2;
else if(ch==80)
{
menu_access_opt3();
}
else if(ch==72)
{
menu_access_opt1();
}
else
menu_access_opt2();
}
/**************************************************************************/
void menu_access_opt3()
{
int ch;
setcolor(RED+GREEN);
pixelize(RED+GREEN,50,200,65,215,0,1);
outtextxy(70,207,"Parts of Drilling M/C");
pixelize(RED+GREEN,50,220,65,235,0,1);
outtextxy(70,227,"Start virtual drill");
while(!kbhit())
{
pixelize(YELLOW,50,240,65,255,0,1);
setcolor(YELLOW);
outtextxy(70,247,"Exit");
}
ch=getch();
if(ch==13)
ret=3;
else if(ch==80)
{
menu_access_opt1();
}
else if(ch==72)
{
menu_access_opt2();
}
else
menu_access_opt3();
}
/**************************************************************************/
void line_fill(int color,int x1,int y1,int x2,int y2,int wt_time,int type,int gap)
{
int i;
switch(type)
{
case 1: for(i=x1+1;i {
setcolor(color);
line(i,y1+1,i,y2-1);
delay(wt_time);
}
break;
case 2: for(i=y2-1;i>y1;i-=gap)
{
setcolor(color);
line(x1+1,i,x2-1,i);
delay(wt_time);
}
break;
}
}
/**************************************************************************/
void draw()
{
int arr[8];
border();
hori_pix(205,275,355,GREEN,DARKGRAY,2,10); /* OBJECT VIEWS */
hori_pix(205,295,355,GREEN,DARKGRAY,2,10);
verti_pix(355,150,275,GREEN,DARKGRAY,2,10);
verti_pix(415,150,275,GREEN,DARKGRAY,2,10);
setcolor(WHITE);
rectangle(355,275,415,295); /* Side view */
rectangle(355,150,415,200); /* Top view*/
putpixel(355+30,150+25,YELLOW);
hori_pix(375,175,395,BLUE,LIGHTBLUE,4,10);
verti_pix(385,165,186,BLUE,LIGHTBLUE,4,10);
setcolor(LIGHTBLUE);
outtextxy(160,200,"O");
outtextxy(160,210,"m");
outtextxy(160,220," ");
outtextxy(160,230,"S");
outtextxy(160,240,"a");
outtextxy(160,250,"i");
setcolor(WHITE); /* BODY */
rectangle(155,170,225,290);
rectangle(153,168,227,290);
w();
rectangle(180,50,200,90); /* MOTOR */
line(180,45,180,50);
line(200,45,200,50);
arc(185,45,90,180,5);
arc(195,45,0,90,5);
line(185,40,195,40);
rectangle(175,75,180,90);
rectangle(200,65,210,90);
pixelize(normal,200,65,210,90,0,1);
line_fill(WHITE,180,50,200,90,0,1,2);
rectangle(165,90,216,175); /* Head */
line_fill(LIGHTBLUE,165,90,216,175,0,2,2);
setcolor(WHITE);
outtextxy(167,96,"Ka9L13");
rectangle(180,125,200,165);
rectangle(190,130,190,160);
rectangle(185,130,195,132);
line_fill(WHITE,185,130,195,132,0,1,1);
rectangle(130,90,165,120); /* ON/OFF Board */
pixelize(LIGHTBLUE,130,90,165,120,0,2);
w();
rectangle(135,110,140,115);
line_fill(LIGHTGRAY,135,110,140,115,0,1,1);
line_fill(LIGHTGREEN,155,110,160,115,0,1,1);
setcolor(WHITE);
rectangle(155,110,160,115);
circle(148,100,5);
line(148,100,148,95);
rectangle(216,130,235,160); /* Feed Lever */
line_fill(LIGHTBLUE,216,130,235,160,0,2,3);
line_fill(LIGHTBLUE,216,130,235,160,0,1,3);
line_fill(normal,235,140-3,245,150+3,0,1,1);
line_fill(WHITE,235,140,245,143,0,1,1);
w();
rectangle(235,140-3,245,150+3);
rectangle(245,130+4,250,160-4);
line(250,134,255,130);
line(250,156,255,160);
rectangle(255,130,260,160);
rectangle(260,132,275,135); /*handle*/
line_fill(BROWN,170,175,211,180,0,1,2);
line_fill(BROWN,167,190,213,195,0,1,2 );
setfillstyle(1,BROWN);
fillellipse(180,185,5,5);
fillellipse(201,185,5,5);
line_fill(BROWN,180,180,201,190,0,1,1);
w();
rectangle(170,175,211,180); /* chuck */
arc(180,185,90,270,5);
arc(201,185,270,90,5);
rectangle(167,190,213,195);
rectangle(180,195,201,200);
rectangle(185,200,196,205); /*small*/
line_fill(normal,185,200,192,205,0,1,1);
line_fill(shine,191,200,194,205,0,1,1);
line_fill(normal,193,200,196,205,0,1,1);
w();
rectangle(180,205,201,209);
line(184,225,197,225);
ellipse(184,205,180,270,4,20);
ellipse(197,205,270,360,4,20);
ellipse(193,211,270,360,4,13);
ellipse(192,211,270,360,4,14);
rectangle(186,227,195,234);
line_fill(normal,186,227,195,234,0,1,1);
line_fill(shine,191,227,194,234,0,1,1);
w();
rectangle(189,234,192,255); /*tool*/
calc(arr,189,234,192,255);
setfillstyle(4,WHITE);
fillpoly(4,arr);
line(189,255,190,258);
line(190,258,192,255);
rectangle(120,295,260,310); /* TABLE */
rectangle(135,290,245,295);
rectangle(175,275,205,295); /*object*/
setfillstyle(9,BROWN);
calc(arr,175,275,205,295);
fillpoly(4,arr);
rectangle(137,288,140,290); /*l-nut*/
line_fill(WHITE,137,288,140,290,0,1,1);
rectangle(240,288,243,290); /*r-nut*/
line_fill(WHITE,240,288,243,290,0,1,1);
rectangle(170,280,175,290); /*l-support*/
rectangle(168,282,170,286);
line_fill(WHITE,168,283,170,285,0,1,1);
rectangle(205,280,210,290); /*r-support*/
rectangle(210,282,212,286);
line_fill(WHITE,210,283,212,285,0,1,1);
line_fill(shine,245,313,265,325,0,2,1);
line_fill(normal,245,315,265,318,0,2,1);
line(245,320,265,320);
line_fill(WHITE,265,317,270,319,0,1,1);
w();
rectangle(245,313,265,325); /* y-Trans-r */
rectangle(265,315,270,323);
rectangle(270,313,273,325);
line(273,313,276,310);
line(273,325,276,328);
rectangle(276,310,280,328);
rectangle(280,312,295,314); /*handle*/
/****************************************/
/* x-Trans-color */
/****************************************/
line_fill(normal,135,312,245,332,0,1,1);
setfillstyle(1,normal);
arr[0]=135;
arr[1]=332;
arr[2]=155;
arr[3]=332;
arr[4]=165;
arr[5]=342;
arr[6]=155;
arr[7]=342;
fillpoly(4,arr);
arr[0]=245;
arr[2]=225;
arr[4]=215;
arr[6]=225;
fillpoly(4,arr);
w();
/****************************************/
line(135,312,245,312); //1 /* x-TRANS-r */
line(135,312,135,332); //2
line(245,312,245,332); //3
line(135,332,155,342); //4
line(155,342,165,342); //5
line(165,342,155,332); //6
line(245,332,225,342); //7
line(225,342,215,342); //8
line(215,342,225,332); //9
line(155,332,225,332); //10
line(160,334,220,334); //11
line(160,334,170,344); //12
line(220,334,210,344); //13
line(170,344,135,344); //14
line(210,344,245,344); //15
line(135,344,135,380); //16
line(245,344,245,380); //17
line(135,380,245,380); //18
/**********************/
/* x_handle back fill */
/**********************/
line_fill(BROWN,135,344,245,380,0,2,1);
setfillstyle(1,BROWN);
arr[0]=163;
arr[1]=335;
arr[2]=218;
arr[3]=335;
arr[4]=207;
arr[5]=346;
arr[6]=173;
arr[7]=346;
fillpoly(4,arr);
w();
/**********************/
circle(190,362,10);
circle(190,357,2);
setfillstyle(1,RED);
fillellipse(190,362,10,10);
setfillstyle(1,LIGHTRED); //x_handle
fillellipse(190,357,2,2);
putpixel(190,362,YELLOW);
rectangle(80,380,135,420); //1 /* BASE */
rectangle(245,380,300,420); //2
rectangle(135,380,245,400); //3
line_fill(BROWN,134,380,246,400,0,1,2); //3
line_fill(BROWN,246,380,300,420,0,1,2); //2
line_fill(BROWN,80,380,135,420,0,1,2); //1
line_fill(normal,120,295,260,310,0,2,2); //table fill
}
/**************************************************************************/
void calc(int *p,int x1,int y1,int x2,int y2)
{
*(p)=x1;
*(p+1)=y1;
*(p+2)=x2;
*(p+3)=y1;
*(p+4)=x2;
*(p+5)=y2;
*(p+6)=x1;
*(p+7)=y2;
}
/**************************************************************************/
void y_trans()
{
int x1,y1,x2,y2,k1=0,i=-1;
setcolor(BLACK);
y2=y_handle.pop();
x2=y_handle.pop();
y1=y_handle.pop();
x1=y_handle.pop();
if (y1<=312)
{
k1=direction(3);
}
else if(y1>=324)
{
k1=direction(4);
}
i=i*(y_handle.convert);
rectangle(x1,y1,x2,y2);
setcolor(WHITE);
rectangle(276,310,280,328);
rectangle(x1,y1+i,x2+k1,y2+i);
y_handle.push(x1);
y_handle.push(y1+i);
y_handle.push(x2+k1);
y_handle.push(y2+i);
if(degree==-12)
{
if(table_trans(-2))
{
msg(4,10);
y_control(1);
}
else msg(2,0);
degree=0;
}
degree--;
}
/***************************************************************************/
void y_trans_1()
{
int x1,y1,x2,y2,k1=0,i=1;
setcolor(BLACK);
y2=y_handle.pop();
x2=y_handle.pop();
y1=y_handle.pop();
x1=y_handle.pop();
if (y1<=312)
{
k1=direction(1);
}
else if(y1>=324)
{
k1=direction(2);
}
i=i*(y_handle.convert);
rectangle(x1,y1,x2,y2);
setcolor(WHITE);
rectangle(276,310,280,328);
rectangle(x1,y1+i,x2+k1,y2+i);
y_handle.push(x1);
y_handle.push(y1+i);
y_handle.push(x2+k1);
y_handle.push(y2+i);
if(degree==12)
{
if(table_trans(2))
{
msg(4,10);
y_control(2);
}
else msg(2,0);
degree=0;
}
degree++;
}
/***************************************************************************/
int direction(int x)
{
static int k=0;
if(x==1 && k==0)
return 0;
if(x==3 && k==1)
return 0;
if(x==4 && k==0)
return 0;
if(x==2 && k==1)
return 0;
if(k==1) //1 for back
{
k=0;
y_handle.convert=y_handle.convert*(-1);
return 1;
}
else
{
k=1;
y_handle.convert=y_handle.convert*(-1);
return -1;
}
}
/***************************************************************************/
void y_control(int limit)
{
int ch;
while(!kbhit()){}
ch=getch();
if(ch==72 && limit!=1)
{
y_trans();
y_control(0);
}
else if(ch==80 && limit!=2)
{
y_trans_1();
y_control(0);
}
else if(ch==27)
operation();
else
y_control(limit);
}
/***************************************************************************/
int z_trans(int z_vector)
{
int x1,y1,x2,y2;
y2=z_handle.pop();
x2=z_handle.pop();
y1=z_handle.pop();
x1=z_handle.pop();
if(y2+z_vector<=134 || y2+z_vector>=154)
{
msg(5,0);
z_handle.push(x1);
z_handle.push(y1);
z_handle.push(x2);
z_handle.push(y2);
return 1;
}
if(y1+z_vector>=141 && on_off==-1)
{
msg(6,0);
z_handle.push(x1);
z_handle.push(y1);
z_handle.push(x2);
z_handle.push(y2);
return 1;
}
else
{
msg(2,0);
setcolor(BLACK);
rectangle(x1,y1,x2,y2);
w();
rectangle(255,130,260,160);
rectangle(x1,y1+z_vector,x2,y2+z_vector);
tool_trans(z_vector*2);
if(y1>=141)
s_hole();
z_handle.push(x1);
z_handle.push(y1+z_vector);
z_handle.push(x2);
z_handle.push(y2+z_vector);
setcolor(BLACK);
rectangle(355,273,415,274);
}
return 0;
}
/***************************************************************************/
int table_trans(int x_vector)
{
int x1,y1,x2,y2,arr[8];
setcolor(BLACK);
y2=table_obj.pop();
x2=table_obj.pop();
y1=table_obj.pop();
x1=table_obj.pop();
if(x1+x_vector<=164 || x2+x_vector>=216)
{
table_obj.push(x1);
table_obj.push(y1);
table_obj.push(x2);
table_obj.push(y2);
return 1;
}
rectangle(x1-55,295,x2+55,310); /*Table*/
line_fill(BLACK,x1-55,295,x2+55,310,0,1,1);
rectangle(x1-40,290,x2+40,295);
rectangle(x1-38,288,x2-65,290); /*l-nut*/
line_fill(BLACK,x1-38,288,x2-65,290,0,1,1);
rectangle(x1+65,288,x2+38,290); /*r-nut*/
line_fill(BLACK,x1+65,288,x2+38,290,0,1,1);
rectangle(x1-5,280,x2-30,290); /*l-support*/
rectangle(x1-7,282,x2-35,286);
line_fill(BLACK,x1-7,282,x2-35,286,0,1,1);
rectangle(x1+30,280,x2+5,290); /*r-support*/
rectangle(x1+35,282,x2+7,286);
line_fill(BLACK,x1+35,282,x2+7,286,0,1,1);
setfillstyle(9,BLACK);
calc(arr,x1,y1,x2,y2);
fillpoly(4,arr);
rectangle(x1,y1,x2,y2); /*object*/
table_obj.push(x1+x_vector);
table_obj.push(y1);
table_obj.push(x2+x_vector);
table_obj.push(y2);
/********************************************/
/* REDRAW CODE */
/********************************************/
x1=x1+x_vector;
x2=x2+x_vector;
point_trans(0,-x_vector*2);
setcolor(WHITE);
rectangle(x1-55,295,x2+55,310); /*Table*/
line_fill(normal,x1-55,295,x2+55,310,0,2,2);
w();
rectangle(x1-40,290,x2+40,295);
rectangle(x1-38,288,x2-65,290); /*l-nut*/
line_fill(WHITE,x1-38,288,x2-65,290,0,1,1);
rectangle(x1+65,288,x2+38,290); /*r-nut*/
line_fill(WHITE,x1+65,288,x2+38,290,0,1,1);
rectangle(x1-5,280,x2-30,290); /*l-support*/
rectangle(x1-7,282,x2-35,286);
line_fill(WHITE,x1-7,283,x2-35,285,0,1,1);
rectangle(x1+30,280,x2+5,290); /*r-support*/
rectangle(x1+35,282,x2+7,286);
line_fill(WHITE,x1+35,283,x2+7,285,0,1,1);
setfillstyle(9,BROWN);
calc(arr,x1,y1,x2,y2);
fillpoly(4,arr);
rectangle(x1,y1,x2,y2); /*object*/
return 0;
}
/***************************************************************************/
void point_trans(int x_vector,int y_vector)
{
int x1,y1;
y1=point_obj.pop();
x1=point_obj.pop();
if (x1+x_vector<358)
{
point_obj.push(x1);
point_obj.push(y1);
x_limit=1;
}
else if(x1+x_vector>412)
{
point_obj.push(x1);
point_obj.push(y1);
x_limit=2;
}
else
{
putpixel(x1,y1,BLACK);
hori_pix(x1-10,y1,x1+10,BLACK,BLACK,4,0);
verti_pix(x1,y1-10,y1+11,BLACK,BLACK,4,0);
point_obj.push(x1+x_vector);
point_obj.push(y1+y_vector);
/*****************/
/* REDRAW */
/*****************/
w();
rectangle(355,150,415,200);
x1=x1+x_vector;
y1=y1+y_vector;
putpixel(x1,y1,YELLOW);
hori_pix(x1-10,y1,x1+10,BLUE,LIGHTBLUE,4,0);
verti_pix(x1,y1-10,y1+11,BLUE,LIGHTBLUE,4,0);
x_limit=0;
}
}
/***************************************************************************/
void operation()
{
int ch;
line_fill(BLACK,499,34,635,43,0,2,1);
reset=0;
c=7;
msg(0,20);
lb();
outtextxy(500,15,"Press:");
w();
if(on_off==-1)
outtextxy(500,35,"s:Start M/c");
else
outtextxy(500,35,"s:Stop M/c");
outtextxy(500,50,"x:x-Translation");
outtextxy(500,65,"y:y-Translation");
outtextxy(500,80,"f:Feed tool");
outtextxy(500,95,"h:Homepage");
setcolor(LIGHTRED);
outtextxy(500,110,"Esc:To abort the");
outtextxy(500,126," operation");
again:
while(!kbhit())
{
line(548,22 ,554,22);
}
ch=getch();
switch(ch)
{
case 115:lb();
if(on_off==-1)
outtextxy(500,35,"s:Start M/c");
else
outtextxy(500,35,"s:Stop M/c");
w();
outtextxy(500,15,"Press:");
m_on_off();
break;
case 120:msg(2,20);
lb();
outtextxy(500,50,"x:x-Translation");
w();
outtextxy(500,15,"Press:");
x_control();
break;
case 121:msg(2,20);
lb();
outtextxy(500,65,"y:y-Translation");
w();
outtextxy(500,15,"Press:");
y_control(0);
break;
case 102:msg(2,10);
lb();
outtextxy(500,80,"f:Feed tool");
w();
outtextxy(500,15,"Press:");
z_control();
break;
case 104:y();
my_window();
break;
default :goto again;
}
}
/***************************************************************************/
void msg(int no,int delay)
{
int ch;
y();
outtextxy(440,445,"Message:");
line_fill(BLACK,439,463,633,474,delay,2,1);
y();
switch(no)
{
case 0: outtextxy(440,465,"Select the operation");
break;
case 1: if(on_off==1)
outtextxy(440,465,"Press Enter to STOP M/c");
else
outtextxy(440,465,"Press Enter to START M/c");
break;
case 2: outtextxy(440,465,"Use up & down arrows");
break;
case 3: outtextxy(440,465,"X-Limit reached");
break;
case 4: outtextxy(440,465,"Y-Limit reached");
break;
case 5: outtextxy(440,465,"Z-Limit reached");
break;
case 6: outtextxy(440,465,"Can't drill, M/c is OFF");
break;
case 7: while(!kbhit())
outtextxy(440,465,"Max holes, Esc twice");
if(getch()==27)
break;
else msg(7,0);
}
}
/***************************************************************************/
void m_on_off()
{
int ch,arr[8];
calc(arr,189,234,192,255);
msg(1,20);
while(!kbhit()){}
ch=getch();
if(ch==13 && on_off==-1)
{
on_off=on_off*(-1);
line_fill(RED,135,110,140,115,0,1,1);
operation();
}
else if(ch==13 && on_off==1)
{
on_off=on_off*(-1);
line_fill(LIGHTGRAY,135,110,140,115,0,1,1);
operation();
}
else if(ch==27)
operation();
else m_on_off();
}
/***************************************************************************/
void z_control()
{
int ch;
while(!kbhit()){}
ch=getch();
if(ch==72)
{
z_trans(-1);
z_control();
}
else if(ch==80)
{
z_trans(1);
z_control();
}
else if(ch==27)
{
while(!z_trans(-1)){}
operation();
}
else
z_control();
}
/***************************************************************************/
void tool_trans(int z_vector)
{
int x1,y1,x2,y2,arr[8],y2_temp;
y2=tool_obj.pop();
x2=tool_obj.pop();
y1=tool_obj.pop();
x1=tool_obj.pop();
y2_temp=y2;
setcolor(BLACK);
rectangle(x1,y1,x2,y2);
line_fill(BLACK,x1,y1,x2-4,y2,0,1,1);
line_fill(BLACK,x2-5,y1,x2-2,y2,0,1,1);
line_fill(BLACK,x2-3,y1,x2,y2,0,1,1);
rectangle(180,y2,201,y2+4);
line(184,y2+20,197,y2+20);
ellipse(184,y2,180,270,4,20);
ellipse(197,y2,270,360,4,20);
ellipse(193,y2+6,270,360,4,13); /*chuck shine */
ellipse(192,y2+6,270,360,4,14);
rectangle(186,y2+22,195,y2+29); /*small*/
rectangle(189,y2+29,192,y2+50); /*tool*/
calc(arr,189,y2+29,192,y2+50);
line_fill(BLACK,186,y2+22,195,y2+29,0,1,1); /*tool holder*/
line_fill(BLACK,191,y2+22,194,y2+29,0,1,1);
setfillstyle(4,BLACK);
fillpoly(4,arr);
line(189,y2+50,190,y2+53);
line(190,y2+53,192,y2+50);
tool_obj.push(x1);
tool_obj.push(y1);
tool_obj.push(x2);
tool_obj.push(y2+z_vector);
/*********************************/
/* REDRAW */
/*********************************/
y2=y2+z_vector;
w();
rectangle(x1,y1,x2,y2);
line_fill(normal,x1,y1,x2-4,y2,0,1,1);
line_fill(shine,x2-5,y1,x2-2,y2,0,1,1);
line_fill(normal,x2-3,y1,x2,y2,0,1,1);
w();
rectangle(180,y2,201,y2+4);
line(184,y2+20,197,y2+20);
ellipse(184,y2,180,270,4,20);
ellipse(197,y2,270,360,4,20);
ellipse(193,y2+6,270,360,4,13); /*chuck shine */
ellipse(192,y2+6,270,360,4,14);
rectangle(186,y2+22,195,y2+29); /*small*/
rectangle(189,y2+29,192,y2+50); /*tool*/
line_fill(normal,186,y2+22,195,y2+29,0,1,1); /*tool holder*/
line_fill(shine,191,y2+22,194,y2+29,0,1,1);
w();
calc(arr,189,y2+29,192,y2+50);
setfillstyle(4,WHITE);
fillpoly(4,arr);
line(189,y2+50,190,y2+53);
line(190,y2+53,192,y2+50);
y2=table_obj.pop(); /*update object*/
x2=table_obj.pop();
y1=table_obj.pop();
x1=table_obj.pop();
setfillstyle(9,BROWN);
calc(arr,x1,y1,x2,y2);
fillpoly(4,arr);
rectangle(x1,y1,x2,y2);
table_obj.push(x1);
table_obj.push(y1);
table_obj.push(x2);
table_obj.push(y2);
if(no>4)
{
no=0;
msg(7,10);
init_arr(x_co_ord);
init_arr(y_co_ord);
reset=1;
c=0;
line_fill(BLACK,355,150,415,200,10,1,1);
line_fill(BLACK,355,275,415,295,10,2,1);
point_trans(0,0);
w();
}
else if(y2_temp+53==276 && !reset)
{
hole();
}
}
/***************************************************************************/
void x_control()
{
int ch;
while(!kbhit()){}
ch=getch();
if(ch==72 && x_limit!=2)
{
x_trans(1);
x_control();
}
else if(ch==80 && x_limit!=1)
{
x_trans(-1);
x_control();
}
else if(ch==27)
{
operation();
}
else
x_control();
}
/***************************************************************************/
void x_trans(int rot_vector)
{
static double x1=190,y1=357;
static int x_degree=0;
double x_temp,y_temp;
int k;
x_degree=x_degree+rot_vector;
setcolor(BLACK);
circle(190,362,10);
circle(x1,y1,2); //x_handle
/********************************/
/* REDRAW */
/********************************/
x_temp=190+(x1-190)*cos(rot_vector)-(y1-362)*sin(rot_vector);
y_temp=362+(x1-190)*sin(rot_vector)+(y1-362)*cos(rot_vector);
x1=x_temp;
y1=y_temp;
w();
circle(190,362,10);
setfillstyle(1,RED);
fillellipse(190,362,10,10);
circle(x1,y1,2); //x_handle
setfillstyle(1,LIGHTRED);
fillellipse(x1,y1,2,2);
putpixel(190,362,YELLOW);
if(x_degree<=12||x_degree>=-12)
{
x_degree=0;
point_trans(rot_vector*2,0);
if(x_limit)
msg(3,0);
else
msg(2,0);
}
}
/***************************************************************************/
void hole()
{
int x1,y1,j,pt=0;
y1=point_obj.pop();
x1=point_obj.pop();
point_obj.push(x1); /* reload point co_ord's */
point_obj.push(y1);
for(j=0;j<=no;j++)
{
if(x_co_ord[j]==x1 && y_co_ord[j]==y1)
{
pt=1;
break;
}
}
if(!pt)
{
x_co_ord[no]=x1;
y_co_ord[no]=y1;
no+=1;
for(j=0;j<=no;j++)
{
setfillstyle(1,LIGHTRED);
fillellipse(x_co_ord[j],y_co_ord[j],2,2);
}
}
}
/***************************************************************************/
void init_arr(int *p)
{
int i;
for(i=0;i<=4;i++)
{
*(p+i)=0;
}
}
/***************************************************************************/
void s_hole()
{
int pt_x1,pt_y1,tip;
pt_y1=point_obj.pop();
pt_x1=point_obj.pop();
point_obj.push(pt_x1); /* reload point co-ord's */
point_obj.push(pt_y1);
tip=tool_obj.pop()+53;
tool_obj.push(tip-53); /* reload tool tip */
line_fill(c,pt_x1-1,275,pt_x1+1,tip,0,1,1);
rectangle(pt_x1-1,275,pt_x1+1,tip);
w();
rectangle(355,275,415,295);
}
/***************************************************************************/
void label()
{
int k=20,ch;
hori_pix(204,55,250,shine,YELLOW,2,k);
lc();
outtextxy(254,50,"\n Motor");
hori_pix(220,95,270,shine,YELLOW,2,k);
lc();
outtextxy(274,90,"\n Head");
hori_pix(76,95,126,shine,YELLOW,2,k);
lc();
outtextxy(10,85,"\n On/Off");
outtextxy(10,95," Board");
hori_pix(278,135,325,shine,YELLOW,2,k);
lc();
outtextxy(329,130,"\n Feed Lever");
hori_pix(99,188,149,shine,YELLOW,2,k);
lc();
outtextxy(44,183,"\n Body");
hori_pix(199,215,249,shine,YELLOW,2,k);
lc();
outtextxy(253,210,"\n Chuck");
hori_pix(194,240,249,shine,YELLOW,2,k);
lc();
outtextxy(253,235,"\n Tool");
hori_pix(85,300,116,shine,YELLOW,2,k);
lc();
outtextxy(10,295,"\n Table");
outtextxy(10,305," & ");
outtextxy(10,315," Object");
hori_pix(204,360,254,shine,YELLOW,2,k);
lc();
outtextxy(258,355,"\n x-Translator");
hori_pix(299,310,349,shine,YELLOW,2,k);
lc();
outtextxy(352,305,"\n y-Translator");
hori_pix(300,385,368,shine,YELLOW,2,k);
lc();
outtextxy(372,380,"\n Base");
hori_pix(420,190,470,shine,YELLOW,2,k);
lc();
outtextxy(474,185,"\n Top view");
hori_pix(420,290,470,shine,YELLOW,2,k);
lc();
outtextxy(474,285,"\n Side view");
lb();
outtextxy(500,15,"Press:");
outtextxy(500,35,"h:Homepage");
while(getch()!=104){}
my_window();
}
/***************************************************************************/
void main()
{
in_graph();
setcolor(LIGHTBLUE);
settextstyle(0,0,1);
outtextxy(10,10,"Om Sai Ram");
settextstyle(0,0,1);
border();
outtextxy(350,240,"Pree any key to START");
getch();
cleardevice();
point_obj.pop(); //flush the unwanted
point_obj.pop();
my_window();
getch();
}
/***************************************************************************/
/***************************************************************************/
/* VIRTUAL DRILLING MACHINE */
/* */
/* CG Project */
/* By Sampathirao Muralidhar B */
/* C.K.Pithawala College of Engg. & Tech. */
/* B.E. Computer-III, 5th Sem (6144) */
/***************************************************************************/
#include iostream.h
#include conio.h
#include stdlib.h
#include graphics.h
#include dos.h
#include math.h
#define MAXX 639
#define MAXY 479
#define interval 90
#define w() {setcolor(WHITE);}
#define lg() {setcolor(LIGHTGRAY);}
#define y() {setcolor(YELLOW);}
#define lb() {setcolor(LIGHTBLUE);}
#define lc() {setcolor(YELLOW);} /* label color */
#define normal DARKGRAY
#define shine LIGHTGRAY
/*****************/
/* Global Var */
/*****************/
int ret=0;
static int no=0;
int on_off=-1; /* indicates status of m/c ON->(1) or OFF->(-1) */
int x_limit=0;
static int degree=0;
static int x_co_ord[5],y_co_ord[5];
int reset=0;
int c=7; /* hole color */
/*****************/
void init_arr(int *);
void y_trans();
void y_trans_1();
void y_control(int);
int z_trans(int);
void z_control(void);
void x_control(void);
void x_trans(int);
int table_trans(int);
void point_trans(int,int);
void tool_trans(int);
void operation(void);
void m_on_off(void);
void hole(void);
void s_hole(void);
void label(void);
class stack
{
private:
int poly[8];
int top;
public:
int convert;
stack(int x1,int y1,int x2,int y2)
{
top=-1;
convert=1;
push(x1);
push(y1);
push(x2);
push(y2);
}
void push(int co_ord)
{
if(top==7)
return;
top++;
poly[top]=co_ord;
}
int pop()
{
if(top==-1)
return NULL;
int temp=poly[top];
top--;
return temp;
}
}y_handle(280,312,295,314),
z_handle(260,132,275,135),
table_obj(175,275,205,295),
point_obj(355+30,150+25,0,0),
tool_obj(185,200,196,205);
void calc(int *,int,int,int,int);
void hori_pix(int,int,int,int,int,int,int);
void verti_pix(int,int,int,int,int,int,int);
void line_fill(int,int,int,int,int,int,int,int);
void pixelize(int,int,int,int,int,int,int);
void border(void);
void my_menu();
void menu_access_opt1(void);
void menu_access_opt2(void);
void menu_access_opt3(void);
void draw(void);
int direction(int);
void msg(int,int);
/****************************************************************************/
void my_menu()
{
int i,j;
setcolor(RED+GREEN);
pixelize(RED+GREEN,50,200,65,215,20,1);
outtextxy(70,207,"Parts of Drilling M/C");
pixelize(RED+GREEN,50,220,65,235,20,1);
outtextxy(70,227,"Start virtual drill");
pixelize(RED+GREEN,50,240,65,255,20,1);
outtextxy(70,247,"Exit");
setcolor(LIGHTGRAY);
outtextxy(10,MAXY-30,"\n Press 'm' to access the menu or enjoy the visuals");
again:
while(!kbhit())
{
verti_pix(250,150,350,RED+GREEN,YELLOW,2,10);
}
if(getch()==(int)'m')
{
outtextxy(10,MAXY-15,"\n Use Up & Down arrow key");
menu_access_opt1();
}
else
goto again;
}
/***************************************************************************/
void pixelize(int color,int x1,int y1,int x2,int y2,int delta,int gap)
{
int i,j;
for(i=y1+1;i<=y2-1;i+=gap)
{
for(j=x1+1;j<=x2-1;j+=gap)
{
putpixel(j,i,color);
}
delay(delta);
}
}
/***************************************************************************/
void in_graph()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
}
/***************************************************************************/
my_window()
{
int i=0;
border();
pixelize(RED,3,3,MAXX-3,MAXY-3,0,2);
line_fill(RED,3,3,MAXX-3,MAXY-3,3,2,1);
while(i!=80)
{
setcolor(YELLOW);
line(i*8,4,MAXX-3,4+(i*8));
delay(20);
i=i+1;
}
i=0;
setcolor(YELLOW);
delay(interval);
outtextxy(getmaxx()/2-50,getmaxy()/2,"Welcome to Virtual Drilling");
hori_pix(getmaxx()/2-50,getmaxy()/2+10,getmaxx()/2-50+216,YELLOW,RED,2,10);
setcolor(RED+GREEN);
outtextxy(getmaxx()/2-50,getmaxy()/2+40+10,"CG Project");
delay(interval);
outtextxy(getmaxx()/2-50,getmaxy()/2+40+20,"By Sampathirao Muralidhar");
delay(interval);
outtextxy(getmaxx()/2-50,getmaxy()/2+40+30,"C.K.Pithawala College of Engg. & Tech.");
delay(interval);
outtextxy(getmaxx()/2-50,getmaxy()/2+40+40,"III-Computer (6144)");
delay(interval);
my_menu();
while(i!=80)
{
setcolor(RED);
line(i*8,4,MAXX-3,4+(i*8));
delay(20);
i=i+1;
}
border();
switch(ret)
{
case 1: line_fill(BLACK,3,3,MAXX-3,MAXY-3,3,1,1);
cleardevice();
setcolor(LIGHTBLUE);
outtextxy(240,15,"\n Parts of Drilling M/c");
draw();
label();
break;
case 2: line_fill(BLACK,3,3,MAXX-3,MAXY-3,3,1,1);
cleardevice();
setcolor(LIGHTBLUE);
outtextxy(100,15,"\n Drilling & Milling M/c ");
draw();
operation();
break;
case 3: pixelize(BLACK,3,3,MAXX-3,MAXY-3,0,2);
line_fill(BLACK,3,3,MAXX-3,MAXY-3,0,1,1);
lb();
outtextxy(140,120,"Impossible is not a fact, its an opinion!!");
outtextxy(245,140,"Thanks for visiting");
w();
outtextxy(350,240,"Pree any key to Exit");
getch();
exit(0);
break;
}
return 0;
}
/***************************************************************************/
void hori_pix(int x1,int y,int x2,int color,int dissolve_color,int gap,int wt_time)
{
int x_temp=x1;
while(x_temp<=x2)
{
putpixel(x_temp,y,color);
delay(wt_time);
x_temp+=gap;
}
x_temp=x1;
while(x_temp<=x2)
{
putpixel(x_temp,y,dissolve_color);
delay(wt_time);
x_temp+=gap;
}
}
/***************************************************************************/
void verti_pix(int x,int y1,int y2,int color,int dissolve_color,int gap,int wt_time)
{
int y_temp=y1;
while(y_temp<=y2)
{
putpixel(x,y_temp,color);
delay(wt_time);
y_temp+=gap;
}
y_temp=y1;
while(y_temp<=y2)
{
putpixel(x,y_temp,dissolve_color);
delay(wt_time);
y_temp+=gap;
}
}
/**************************************************************************/
void border()
{
setcolor(WHITE);
rectangle(0,0,MAXX,MAXY);
rectangle(2,2,MAXX-2,MAXY-2);
}
/**************************************************************************/
void menu_access_opt1()
{
int ch;
setcolor(RED+GREEN);
pixelize(RED+GREEN,50,220,65,235,0,1);
outtextxy(70,227,"Start virtual drill");
pixelize(RED+GREEN,50,240,65,255,0,1);
outtextxy(70,247,"Exit");
while(!kbhit())
{
pixelize(YELLOW,50,200,65,215,0,1);
setcolor(YELLOW);
outtextxy(70,207,"Parts of Drilling M/C");
}
ch=getch();
if(ch==13)
ret=1;
else if(ch==80)
{
menu_access_opt2();
}
else if(ch==72)
{
menu_access_opt3();
}
else
menu_access_opt1();
}
/**************************************************************************/
void menu_access_opt2()
{
int ch;
setcolor(RED+GREEN);
pixelize(RED+GREEN,50,200,65,215,0,1);
outtextxy(70,207,"Parts of Drilling M/C");
pixelize(RED+GREEN,50,240,65,255,0,1);
outtextxy(70,247,"Exit");
while(!kbhit())
{
pixelize(YELLOW,50,220,65,235,0,1);
setcolor(YELLOW);
outtextxy(70,227,"Start virtual drill");
}
ch=getch();
if(ch==13)
ret=2;
else if(ch==80)
{
menu_access_opt3();
}
else if(ch==72)
{
menu_access_opt1();
}
else
menu_access_opt2();
}
/**************************************************************************/
void menu_access_opt3()
{
int ch;
setcolor(RED+GREEN);
pixelize(RED+GREEN,50,200,65,215,0,1);
outtextxy(70,207,"Parts of Drilling M/C");
pixelize(RED+GREEN,50,220,65,235,0,1);
outtextxy(70,227,"Start virtual drill");
while(!kbhit())
{
pixelize(YELLOW,50,240,65,255,0,1);
setcolor(YELLOW);
outtextxy(70,247,"Exit");
}
ch=getch();
if(ch==13)
ret=3;
else if(ch==80)
{
menu_access_opt1();
}
else if(ch==72)
{
menu_access_opt2();
}
else
menu_access_opt3();
}
/**************************************************************************/
void line_fill(int color,int x1,int y1,int x2,int y2,int wt_time,int type,int gap)
{
int i;
switch(type)
{
case 1: for(i=x1+1;i
setcolor(color);
line(i,y1+1,i,y2-1);
delay(wt_time);
}
break;
case 2: for(i=y2-1;i>y1;i-=gap)
{
setcolor(color);
line(x1+1,i,x2-1,i);
delay(wt_time);
}
break;
}
}
/**************************************************************************/
void draw()
{
int arr[8];
border();
hori_pix(205,275,355,GREEN,DARKGRAY,2,10); /* OBJECT VIEWS */
hori_pix(205,295,355,GREEN,DARKGRAY,2,10);
verti_pix(355,150,275,GREEN,DARKGRAY,2,10);
verti_pix(415,150,275,GREEN,DARKGRAY,2,10);
setcolor(WHITE);
rectangle(355,275,415,295); /* Side view */
rectangle(355,150,415,200); /* Top view*/
putpixel(355+30,150+25,YELLOW);
hori_pix(375,175,395,BLUE,LIGHTBLUE,4,10);
verti_pix(385,165,186,BLUE,LIGHTBLUE,4,10);
setcolor(LIGHTBLUE);
outtextxy(160,200,"O");
outtextxy(160,210,"m");
outtextxy(160,220," ");
outtextxy(160,230,"S");
outtextxy(160,240,"a");
outtextxy(160,250,"i");
setcolor(WHITE); /* BODY */
rectangle(155,170,225,290);
rectangle(153,168,227,290);
w();
rectangle(180,50,200,90); /* MOTOR */
line(180,45,180,50);
line(200,45,200,50);
arc(185,45,90,180,5);
arc(195,45,0,90,5);
line(185,40,195,40);
rectangle(175,75,180,90);
rectangle(200,65,210,90);
pixelize(normal,200,65,210,90,0,1);
line_fill(WHITE,180,50,200,90,0,1,2);
rectangle(165,90,216,175); /* Head */
line_fill(LIGHTBLUE,165,90,216,175,0,2,2);
setcolor(WHITE);
outtextxy(167,96,"Ka9L13");
rectangle(180,125,200,165);
rectangle(190,130,190,160);
rectangle(185,130,195,132);
line_fill(WHITE,185,130,195,132,0,1,1);
rectangle(130,90,165,120); /* ON/OFF Board */
pixelize(LIGHTBLUE,130,90,165,120,0,2);
w();
rectangle(135,110,140,115);
line_fill(LIGHTGRAY,135,110,140,115,0,1,1);
line_fill(LIGHTGREEN,155,110,160,115,0,1,1);
setcolor(WHITE);
rectangle(155,110,160,115);
circle(148,100,5);
line(148,100,148,95);
rectangle(216,130,235,160); /* Feed Lever */
line_fill(LIGHTBLUE,216,130,235,160,0,2,3);
line_fill(LIGHTBLUE,216,130,235,160,0,1,3);
line_fill(normal,235,140-3,245,150+3,0,1,1);
line_fill(WHITE,235,140,245,143,0,1,1);
w();
rectangle(235,140-3,245,150+3);
rectangle(245,130+4,250,160-4);
line(250,134,255,130);
line(250,156,255,160);
rectangle(255,130,260,160);
rectangle(260,132,275,135); /*handle*/
line_fill(BROWN,170,175,211,180,0,1,2);
line_fill(BROWN,167,190,213,195,0,1,2 );
setfillstyle(1,BROWN);
fillellipse(180,185,5,5);
fillellipse(201,185,5,5);
line_fill(BROWN,180,180,201,190,0,1,1);
w();
rectangle(170,175,211,180); /* chuck */
arc(180,185,90,270,5);
arc(201,185,270,90,5);
rectangle(167,190,213,195);
rectangle(180,195,201,200);
rectangle(185,200,196,205); /*small*/
line_fill(normal,185,200,192,205,0,1,1);
line_fill(shine,191,200,194,205,0,1,1);
line_fill(normal,193,200,196,205,0,1,1);
w();
rectangle(180,205,201,209);
line(184,225,197,225);
ellipse(184,205,180,270,4,20);
ellipse(197,205,270,360,4,20);
ellipse(193,211,270,360,4,13);
ellipse(192,211,270,360,4,14);
rectangle(186,227,195,234);
line_fill(normal,186,227,195,234,0,1,1);
line_fill(shine,191,227,194,234,0,1,1);
w();
rectangle(189,234,192,255); /*tool*/
calc(arr,189,234,192,255);
setfillstyle(4,WHITE);
fillpoly(4,arr);
line(189,255,190,258);
line(190,258,192,255);
rectangle(120,295,260,310); /* TABLE */
rectangle(135,290,245,295);
rectangle(175,275,205,295); /*object*/
setfillstyle(9,BROWN);
calc(arr,175,275,205,295);
fillpoly(4,arr);
rectangle(137,288,140,290); /*l-nut*/
line_fill(WHITE,137,288,140,290,0,1,1);
rectangle(240,288,243,290); /*r-nut*/
line_fill(WHITE,240,288,243,290,0,1,1);
rectangle(170,280,175,290); /*l-support*/
rectangle(168,282,170,286);
line_fill(WHITE,168,283,170,285,0,1,1);
rectangle(205,280,210,290); /*r-support*/
rectangle(210,282,212,286);
line_fill(WHITE,210,283,212,285,0,1,1);
line_fill(shine,245,313,265,325,0,2,1);
line_fill(normal,245,315,265,318,0,2,1);
line(245,320,265,320);
line_fill(WHITE,265,317,270,319,0,1,1);
w();
rectangle(245,313,265,325); /* y-Trans-r */
rectangle(265,315,270,323);
rectangle(270,313,273,325);
line(273,313,276,310);
line(273,325,276,328);
rectangle(276,310,280,328);
rectangle(280,312,295,314); /*handle*/
/****************************************/
/* x-Trans-color */
/****************************************/
line_fill(normal,135,312,245,332,0,1,1);
setfillstyle(1,normal);
arr[0]=135;
arr[1]=332;
arr[2]=155;
arr[3]=332;
arr[4]=165;
arr[5]=342;
arr[6]=155;
arr[7]=342;
fillpoly(4,arr);
arr[0]=245;
arr[2]=225;
arr[4]=215;
arr[6]=225;
fillpoly(4,arr);
w();
/****************************************/
line(135,312,245,312); //1 /* x-TRANS-r */
line(135,312,135,332); //2
line(245,312,245,332); //3
line(135,332,155,342); //4
line(155,342,165,342); //5
line(165,342,155,332); //6
line(245,332,225,342); //7
line(225,342,215,342); //8
line(215,342,225,332); //9
line(155,332,225,332); //10
line(160,334,220,334); //11
line(160,334,170,344); //12
line(220,334,210,344); //13
line(170,344,135,344); //14
line(210,344,245,344); //15
line(135,344,135,380); //16
line(245,344,245,380); //17
line(135,380,245,380); //18
/**********************/
/* x_handle back fill */
/**********************/
line_fill(BROWN,135,344,245,380,0,2,1);
setfillstyle(1,BROWN);
arr[0]=163;
arr[1]=335;
arr[2]=218;
arr[3]=335;
arr[4]=207;
arr[5]=346;
arr[6]=173;
arr[7]=346;
fillpoly(4,arr);
w();
/**********************/
circle(190,362,10);
circle(190,357,2);
setfillstyle(1,RED);
fillellipse(190,362,10,10);
setfillstyle(1,LIGHTRED); //x_handle
fillellipse(190,357,2,2);
putpixel(190,362,YELLOW);
rectangle(80,380,135,420); //1 /* BASE */
rectangle(245,380,300,420); //2
rectangle(135,380,245,400); //3
line_fill(BROWN,134,380,246,400,0,1,2); //3
line_fill(BROWN,246,380,300,420,0,1,2); //2
line_fill(BROWN,80,380,135,420,0,1,2); //1
line_fill(normal,120,295,260,310,0,2,2); //table fill
}
/**************************************************************************/
void calc(int *p,int x1,int y1,int x2,int y2)
{
*(p)=x1;
*(p+1)=y1;
*(p+2)=x2;
*(p+3)=y1;
*(p+4)=x2;
*(p+5)=y2;
*(p+6)=x1;
*(p+7)=y2;
}
/**************************************************************************/
void y_trans()
{
int x1,y1,x2,y2,k1=0,i=-1;
setcolor(BLACK);
y2=y_handle.pop();
x2=y_handle.pop();
y1=y_handle.pop();
x1=y_handle.pop();
if (y1<=312)
{
k1=direction(3);
}
else if(y1>=324)
{
k1=direction(4);
}
i=i*(y_handle.convert);
rectangle(x1,y1,x2,y2);
setcolor(WHITE);
rectangle(276,310,280,328);
rectangle(x1,y1+i,x2+k1,y2+i);
y_handle.push(x1);
y_handle.push(y1+i);
y_handle.push(x2+k1);
y_handle.push(y2+i);
if(degree==-12)
{
if(table_trans(-2))
{
msg(4,10);
y_control(1);
}
else msg(2,0);
degree=0;
}
degree--;
}
/***************************************************************************/
void y_trans_1()
{
int x1,y1,x2,y2,k1=0,i=1;
setcolor(BLACK);
y2=y_handle.pop();
x2=y_handle.pop();
y1=y_handle.pop();
x1=y_handle.pop();
if (y1<=312)
{
k1=direction(1);
}
else if(y1>=324)
{
k1=direction(2);
}
i=i*(y_handle.convert);
rectangle(x1,y1,x2,y2);
setcolor(WHITE);
rectangle(276,310,280,328);
rectangle(x1,y1+i,x2+k1,y2+i);
y_handle.push(x1);
y_handle.push(y1+i);
y_handle.push(x2+k1);
y_handle.push(y2+i);
if(degree==12)
{
if(table_trans(2))
{
msg(4,10);
y_control(2);
}
else msg(2,0);
degree=0;
}
degree++;
}
/***************************************************************************/
int direction(int x)
{
static int k=0;
if(x==1 && k==0)
return 0;
if(x==3 && k==1)
return 0;
if(x==4 && k==0)
return 0;
if(x==2 && k==1)
return 0;
if(k==1) //1 for back
{
k=0;
y_handle.convert=y_handle.convert*(-1);
return 1;
}
else
{
k=1;
y_handle.convert=y_handle.convert*(-1);
return -1;
}
}
/***************************************************************************/
void y_control(int limit)
{
int ch;
while(!kbhit()){}
ch=getch();
if(ch==72 && limit!=1)
{
y_trans();
y_control(0);
}
else if(ch==80 && limit!=2)
{
y_trans_1();
y_control(0);
}
else if(ch==27)
operation();
else
y_control(limit);
}
/***************************************************************************/
int z_trans(int z_vector)
{
int x1,y1,x2,y2;
y2=z_handle.pop();
x2=z_handle.pop();
y1=z_handle.pop();
x1=z_handle.pop();
if(y2+z_vector<=134 || y2+z_vector>=154)
{
msg(5,0);
z_handle.push(x1);
z_handle.push(y1);
z_handle.push(x2);
z_handle.push(y2);
return 1;
}
if(y1+z_vector>=141 && on_off==-1)
{
msg(6,0);
z_handle.push(x1);
z_handle.push(y1);
z_handle.push(x2);
z_handle.push(y2);
return 1;
}
else
{
msg(2,0);
setcolor(BLACK);
rectangle(x1,y1,x2,y2);
w();
rectangle(255,130,260,160);
rectangle(x1,y1+z_vector,x2,y2+z_vector);
tool_trans(z_vector*2);
if(y1>=141)
s_hole();
z_handle.push(x1);
z_handle.push(y1+z_vector);
z_handle.push(x2);
z_handle.push(y2+z_vector);
setcolor(BLACK);
rectangle(355,273,415,274);
}
return 0;
}
/***************************************************************************/
int table_trans(int x_vector)
{
int x1,y1,x2,y2,arr[8];
setcolor(BLACK);
y2=table_obj.pop();
x2=table_obj.pop();
y1=table_obj.pop();
x1=table_obj.pop();
if(x1+x_vector<=164 || x2+x_vector>=216)
{
table_obj.push(x1);
table_obj.push(y1);
table_obj.push(x2);
table_obj.push(y2);
return 1;
}
rectangle(x1-55,295,x2+55,310); /*Table*/
line_fill(BLACK,x1-55,295,x2+55,310,0,1,1);
rectangle(x1-40,290,x2+40,295);
rectangle(x1-38,288,x2-65,290); /*l-nut*/
line_fill(BLACK,x1-38,288,x2-65,290,0,1,1);
rectangle(x1+65,288,x2+38,290); /*r-nut*/
line_fill(BLACK,x1+65,288,x2+38,290,0,1,1);
rectangle(x1-5,280,x2-30,290); /*l-support*/
rectangle(x1-7,282,x2-35,286);
line_fill(BLACK,x1-7,282,x2-35,286,0,1,1);
rectangle(x1+30,280,x2+5,290); /*r-support*/
rectangle(x1+35,282,x2+7,286);
line_fill(BLACK,x1+35,282,x2+7,286,0,1,1);
setfillstyle(9,BLACK);
calc(arr,x1,y1,x2,y2);
fillpoly(4,arr);
rectangle(x1,y1,x2,y2); /*object*/
table_obj.push(x1+x_vector);
table_obj.push(y1);
table_obj.push(x2+x_vector);
table_obj.push(y2);
/********************************************/
/* REDRAW CODE */
/********************************************/
x1=x1+x_vector;
x2=x2+x_vector;
point_trans(0,-x_vector*2);
setcolor(WHITE);
rectangle(x1-55,295,x2+55,310); /*Table*/
line_fill(normal,x1-55,295,x2+55,310,0,2,2);
w();
rectangle(x1-40,290,x2+40,295);
rectangle(x1-38,288,x2-65,290); /*l-nut*/
line_fill(WHITE,x1-38,288,x2-65,290,0,1,1);
rectangle(x1+65,288,x2+38,290); /*r-nut*/
line_fill(WHITE,x1+65,288,x2+38,290,0,1,1);
rectangle(x1-5,280,x2-30,290); /*l-support*/
rectangle(x1-7,282,x2-35,286);
line_fill(WHITE,x1-7,283,x2-35,285,0,1,1);
rectangle(x1+30,280,x2+5,290); /*r-support*/
rectangle(x1+35,282,x2+7,286);
line_fill(WHITE,x1+35,283,x2+7,285,0,1,1);
setfillstyle(9,BROWN);
calc(arr,x1,y1,x2,y2);
fillpoly(4,arr);
rectangle(x1,y1,x2,y2); /*object*/
return 0;
}
/***************************************************************************/
void point_trans(int x_vector,int y_vector)
{
int x1,y1;
y1=point_obj.pop();
x1=point_obj.pop();
if (x1+x_vector<358)
{
point_obj.push(x1);
point_obj.push(y1);
x_limit=1;
}
else if(x1+x_vector>412)
{
point_obj.push(x1);
point_obj.push(y1);
x_limit=2;
}
else
{
putpixel(x1,y1,BLACK);
hori_pix(x1-10,y1,x1+10,BLACK,BLACK,4,0);
verti_pix(x1,y1-10,y1+11,BLACK,BLACK,4,0);
point_obj.push(x1+x_vector);
point_obj.push(y1+y_vector);
/*****************/
/* REDRAW */
/*****************/
w();
rectangle(355,150,415,200);
x1=x1+x_vector;
y1=y1+y_vector;
putpixel(x1,y1,YELLOW);
hori_pix(x1-10,y1,x1+10,BLUE,LIGHTBLUE,4,0);
verti_pix(x1,y1-10,y1+11,BLUE,LIGHTBLUE,4,0);
x_limit=0;
}
}
/***************************************************************************/
void operation()
{
int ch;
line_fill(BLACK,499,34,635,43,0,2,1);
reset=0;
c=7;
msg(0,20);
lb();
outtextxy(500,15,"Press:");
w();
if(on_off==-1)
outtextxy(500,35,"s:Start M/c");
else
outtextxy(500,35,"s:Stop M/c");
outtextxy(500,50,"x:x-Translation");
outtextxy(500,65,"y:y-Translation");
outtextxy(500,80,"f:Feed tool");
outtextxy(500,95,"h:Homepage");
setcolor(LIGHTRED);
outtextxy(500,110,"Esc:To abort the");
outtextxy(500,126," operation");
again:
while(!kbhit())
{
line(548,22 ,554,22);
}
ch=getch();
switch(ch)
{
case 115:lb();
if(on_off==-1)
outtextxy(500,35,"s:Start M/c");
else
outtextxy(500,35,"s:Stop M/c");
w();
outtextxy(500,15,"Press:");
m_on_off();
break;
case 120:msg(2,20);
lb();
outtextxy(500,50,"x:x-Translation");
w();
outtextxy(500,15,"Press:");
x_control();
break;
case 121:msg(2,20);
lb();
outtextxy(500,65,"y:y-Translation");
w();
outtextxy(500,15,"Press:");
y_control(0);
break;
case 102:msg(2,10);
lb();
outtextxy(500,80,"f:Feed tool");
w();
outtextxy(500,15,"Press:");
z_control();
break;
case 104:y();
my_window();
break;
default :goto again;
}
}
/***************************************************************************/
void msg(int no,int delay)
{
int ch;
y();
outtextxy(440,445,"Message:");
line_fill(BLACK,439,463,633,474,delay,2,1);
y();
switch(no)
{
case 0: outtextxy(440,465,"Select the operation");
break;
case 1: if(on_off==1)
outtextxy(440,465,"Press Enter to STOP M/c");
else
outtextxy(440,465,"Press Enter to START M/c");
break;
case 2: outtextxy(440,465,"Use up & down arrows");
break;
case 3: outtextxy(440,465,"X-Limit reached");
break;
case 4: outtextxy(440,465,"Y-Limit reached");
break;
case 5: outtextxy(440,465,"Z-Limit reached");
break;
case 6: outtextxy(440,465,"Can't drill, M/c is OFF");
break;
case 7: while(!kbhit())
outtextxy(440,465,"Max holes, Esc twice");
if(getch()==27)
break;
else msg(7,0);
}
}
/***************************************************************************/
void m_on_off()
{
int ch,arr[8];
calc(arr,189,234,192,255);
msg(1,20);
while(!kbhit()){}
ch=getch();
if(ch==13 && on_off==-1)
{
on_off=on_off*(-1);
line_fill(RED,135,110,140,115,0,1,1);
operation();
}
else if(ch==13 && on_off==1)
{
on_off=on_off*(-1);
line_fill(LIGHTGRAY,135,110,140,115,0,1,1);
operation();
}
else if(ch==27)
operation();
else m_on_off();
}
/***************************************************************************/
void z_control()
{
int ch;
while(!kbhit()){}
ch=getch();
if(ch==72)
{
z_trans(-1);
z_control();
}
else if(ch==80)
{
z_trans(1);
z_control();
}
else if(ch==27)
{
while(!z_trans(-1)){}
operation();
}
else
z_control();
}
/***************************************************************************/
void tool_trans(int z_vector)
{
int x1,y1,x2,y2,arr[8],y2_temp;
y2=tool_obj.pop();
x2=tool_obj.pop();
y1=tool_obj.pop();
x1=tool_obj.pop();
y2_temp=y2;
setcolor(BLACK);
rectangle(x1,y1,x2,y2);
line_fill(BLACK,x1,y1,x2-4,y2,0,1,1);
line_fill(BLACK,x2-5,y1,x2-2,y2,0,1,1);
line_fill(BLACK,x2-3,y1,x2,y2,0,1,1);
rectangle(180,y2,201,y2+4);
line(184,y2+20,197,y2+20);
ellipse(184,y2,180,270,4,20);
ellipse(197,y2,270,360,4,20);
ellipse(193,y2+6,270,360,4,13); /*chuck shine */
ellipse(192,y2+6,270,360,4,14);
rectangle(186,y2+22,195,y2+29); /*small*/
rectangle(189,y2+29,192,y2+50); /*tool*/
calc(arr,189,y2+29,192,y2+50);
line_fill(BLACK,186,y2+22,195,y2+29,0,1,1); /*tool holder*/
line_fill(BLACK,191,y2+22,194,y2+29,0,1,1);
setfillstyle(4,BLACK);
fillpoly(4,arr);
line(189,y2+50,190,y2+53);
line(190,y2+53,192,y2+50);
tool_obj.push(x1);
tool_obj.push(y1);
tool_obj.push(x2);
tool_obj.push(y2+z_vector);
/*********************************/
/* REDRAW */
/*********************************/
y2=y2+z_vector;
w();
rectangle(x1,y1,x2,y2);
line_fill(normal,x1,y1,x2-4,y2,0,1,1);
line_fill(shine,x2-5,y1,x2-2,y2,0,1,1);
line_fill(normal,x2-3,y1,x2,y2,0,1,1);
w();
rectangle(180,y2,201,y2+4);
line(184,y2+20,197,y2+20);
ellipse(184,y2,180,270,4,20);
ellipse(197,y2,270,360,4,20);
ellipse(193,y2+6,270,360,4,13); /*chuck shine */
ellipse(192,y2+6,270,360,4,14);
rectangle(186,y2+22,195,y2+29); /*small*/
rectangle(189,y2+29,192,y2+50); /*tool*/
line_fill(normal,186,y2+22,195,y2+29,0,1,1); /*tool holder*/
line_fill(shine,191,y2+22,194,y2+29,0,1,1);
w();
calc(arr,189,y2+29,192,y2+50);
setfillstyle(4,WHITE);
fillpoly(4,arr);
line(189,y2+50,190,y2+53);
line(190,y2+53,192,y2+50);
y2=table_obj.pop(); /*update object*/
x2=table_obj.pop();
y1=table_obj.pop();
x1=table_obj.pop();
setfillstyle(9,BROWN);
calc(arr,x1,y1,x2,y2);
fillpoly(4,arr);
rectangle(x1,y1,x2,y2);
table_obj.push(x1);
table_obj.push(y1);
table_obj.push(x2);
table_obj.push(y2);
if(no>4)
{
no=0;
msg(7,10);
init_arr(x_co_ord);
init_arr(y_co_ord);
reset=1;
c=0;
line_fill(BLACK,355,150,415,200,10,1,1);
line_fill(BLACK,355,275,415,295,10,2,1);
point_trans(0,0);
w();
}
else if(y2_temp+53==276 && !reset)
{
hole();
}
}
/***************************************************************************/
void x_control()
{
int ch;
while(!kbhit()){}
ch=getch();
if(ch==72 && x_limit!=2)
{
x_trans(1);
x_control();
}
else if(ch==80 && x_limit!=1)
{
x_trans(-1);
x_control();
}
else if(ch==27)
{
operation();
}
else
x_control();
}
/***************************************************************************/
void x_trans(int rot_vector)
{
static double x1=190,y1=357;
static int x_degree=0;
double x_temp,y_temp;
int k;
x_degree=x_degree+rot_vector;
setcolor(BLACK);
circle(190,362,10);
circle(x1,y1,2); //x_handle
/********************************/
/* REDRAW */
/********************************/
x_temp=190+(x1-190)*cos(rot_vector)-(y1-362)*sin(rot_vector);
y_temp=362+(x1-190)*sin(rot_vector)+(y1-362)*cos(rot_vector);
x1=x_temp;
y1=y_temp;
w();
circle(190,362,10);
setfillstyle(1,RED);
fillellipse(190,362,10,10);
circle(x1,y1,2); //x_handle
setfillstyle(1,LIGHTRED);
fillellipse(x1,y1,2,2);
putpixel(190,362,YELLOW);
if(x_degree<=12||x_degree>=-12)
{
x_degree=0;
point_trans(rot_vector*2,0);
if(x_limit)
msg(3,0);
else
msg(2,0);
}
}
/***************************************************************************/
void hole()
{
int x1,y1,j,pt=0;
y1=point_obj.pop();
x1=point_obj.pop();
point_obj.push(x1); /* reload point co_ord's */
point_obj.push(y1);
for(j=0;j<=no;j++)
{
if(x_co_ord[j]==x1 && y_co_ord[j]==y1)
{
pt=1;
break;
}
}
if(!pt)
{
x_co_ord[no]=x1;
y_co_ord[no]=y1;
no+=1;
for(j=0;j<=no;j++)
{
setfillstyle(1,LIGHTRED);
fillellipse(x_co_ord[j],y_co_ord[j],2,2);
}
}
}
/***************************************************************************/
void init_arr(int *p)
{
int i;
for(i=0;i<=4;i++)
{
*(p+i)=0;
}
}
/***************************************************************************/
void s_hole()
{
int pt_x1,pt_y1,tip;
pt_y1=point_obj.pop();
pt_x1=point_obj.pop();
point_obj.push(pt_x1); /* reload point co-ord's */
point_obj.push(pt_y1);
tip=tool_obj.pop()+53;
tool_obj.push(tip-53); /* reload tool tip */
line_fill(c,pt_x1-1,275,pt_x1+1,tip,0,1,1);
rectangle(pt_x1-1,275,pt_x1+1,tip);
w();
rectangle(355,275,415,295);
}
/***************************************************************************/
void label()
{
int k=20,ch;
hori_pix(204,55,250,shine,YELLOW,2,k);
lc();
outtextxy(254,50,"\n Motor");
hori_pix(220,95,270,shine,YELLOW,2,k);
lc();
outtextxy(274,90,"\n Head");
hori_pix(76,95,126,shine,YELLOW,2,k);
lc();
outtextxy(10,85,"\n On/Off");
outtextxy(10,95," Board");
hori_pix(278,135,325,shine,YELLOW,2,k);
lc();
outtextxy(329,130,"\n Feed Lever");
hori_pix(99,188,149,shine,YELLOW,2,k);
lc();
outtextxy(44,183,"\n Body");
hori_pix(199,215,249,shine,YELLOW,2,k);
lc();
outtextxy(253,210,"\n Chuck");
hori_pix(194,240,249,shine,YELLOW,2,k);
lc();
outtextxy(253,235,"\n Tool");
hori_pix(85,300,116,shine,YELLOW,2,k);
lc();
outtextxy(10,295,"\n Table");
outtextxy(10,305," & ");
outtextxy(10,315," Object");
hori_pix(204,360,254,shine,YELLOW,2,k);
lc();
outtextxy(258,355,"\n x-Translator");
hori_pix(299,310,349,shine,YELLOW,2,k);
lc();
outtextxy(352,305,"\n y-Translator");
hori_pix(300,385,368,shine,YELLOW,2,k);
lc();
outtextxy(372,380,"\n Base");
hori_pix(420,190,470,shine,YELLOW,2,k);
lc();
outtextxy(474,185,"\n Top view");
hori_pix(420,290,470,shine,YELLOW,2,k);
lc();
outtextxy(474,285,"\n Side view");
lb();
outtextxy(500,15,"Press:");
outtextxy(500,35,"h:Homepage");
while(getch()!=104){}
my_window();
}
/***************************************************************************/
void main()
{
in_graph();
setcolor(LIGHTBLUE);
settextstyle(0,0,1);
outtextxy(10,10,"Om Sai Ram");
settextstyle(0,0,1);
border();
outtextxy(350,240,"Pree any key to START");
getch();
cleardevice();
point_obj.pop(); //flush the unwanted
point_obj.pop();
my_window();
getch();
}
/***************************************************************************/
Snakeman Game
This a Snake Game in C.G and C++
//80*48
#include fstream.h
#include stdlib.h
#include process.h
#include stdio.h
#include time.h
#include dos.h
#include string.h
#include graphics.h
#include bios.h
#include conio.h
#include iomanip.h
unsigned key;
int len=0,count=0,foodtype=0,d,m,food_flag=0,j=0,i=0,display_count=10,
hscore_pos=0,x_index=0,y_index=0,mx,my,maze=1,speed=100;
long score=0,ti_elap=0,ti_rem=15,tot_ti=15,ti_init;
char *main_menu[]={{"1. Play"},{"2. Options"},{"3. Instruction"},
{"4. Hi-Score"},{"5. Exit"}};
char *game_menu[]={{"1. Mazes"},{"2. Level"},{"3. Back to Main menu"}};
char *maze_menu[]={{"1. Open"},{"2. Box"},{"3. Twisted"},
{"4. Return to Main menu"}};
char *level_menu[]={{"1. Beginner"},{"2. Intermediate"},{"3. Expert"},
{"4. Return to Main menu"}};
char *m_m[]={"P","O","I","H","E"};
char *g_m[]={"M","L","B"};
char *mm[]={"O","B","T","R"};
char *lm[]={"B","I","E","R"};
int maze3_x[][14]={{2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{25},
{30},
{37,38,39,40,41,42,43,44,45,46,47,48,49,50}};
int maze3_y[][14]={{30},
{2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{27,28,29,30,31,32,33,34,35,36,37,38,39,40},
{20}};
void showfood();
void end();
void show_game_menu();
void show_main_menu();
enum{UP=1,RIGHT=2,DOWN=3,LEFT=4}DIRECTION,Pre_Dir;
struct
{
unsigned x:7 ;
unsigned y:7 ;
}coordinate[1000],tail,head,food;
inline void initialise()
{
d=DETECT;
initgraph(&d,&m,"e:\tc\bgi");
cleardevice();
mx=getmaxx();
my=getmaxy();
}
void RESET()
{
len=count=foodtype=food_flag=i=j=hscore_pos=x_index=y_index=0;
display_count=10,
speed=100;
score=ti_elap=0;ti_rem=tot_ti=15;
head.x=head.y=tail.x=tail.y=food.x=food.y=0;
for(i=0;i<1000;i++)
coordinate[i].x=coordinate[i].y=0;
}
void showoff_food()
{
gotoxy(food.x,food.y);
cout<<" ";
food.x=food.y=0;
showfood();
}
int showfoodtimer(int fo_fl)
{
if(fo_fl==1)
{
if(ti_rem<=0)
{
showoff_food();
ti_rem=15;
food_flag=0;
}
else
{
ti_elap=((biostime(0,0L)-ti_init)/(speed/16));
ti_rem=(tot_ti-(ti_elap));
gotoxy(7,46);
if(ti_rem<10)
cout<<"0"< else
cout< }
}
else
{
gotoxy(7,46);
cout<<" ";
}
return 0;
}
void showfood()
{
int flag=0;
re:
food.x=random(49)+2;
food.y=random(39)+2;
for(i=0;i {
if(food.x==coordinate[i].x && food.y==coordinate[i].y)
goto re;
}
if(maze==3)
{
for(i=0;i<4;i++)
{
for(j=0;j<14;j++)
{
if(food.x==maze3_x[i][j])
flag=1;
}
for(j=0;j<14;j++)
{
if(food.y==maze3_y[i][j] && flag==1)
goto re;
}
}
}
gotoxy(food.x,food.y);
textcolor(RED);
cprintf("@");
}
void showbigfood()
{
re1:
food.x=random(49)+2;
food.y=random(39)+2;
for(int j=0;j {
if(food.x==coordinate[j].x && food.y==coordinate[j].y)
goto re1;
}
textcolor(YELLOW);
gotoxy(food.x,food.y);
cprintf("é");
}
void exit()
{
delay(50);
textmode(4);
gotoxy(10,8);
cout<<"Exiting the program";
delay(2000);
exit(0);
}
void border()
{
setcolor(GREEN);
rectangle(2,2,mx-2,my-2);
setcolor(RED);
rectangle(4,4,mx-4,my-4);
setcolor(GREEN);
rectangle(6,6,mx-6,my-6);
settextstyle(4,0,5);
outtextxy(180,40,"SNAKEMAN");
setcolor(YELLOW);
line(165,88,440,88);
setcolor(RED);
line(165,90,440,90);
}
void intro_graphics()
{
clrscr();
initialise();
border();
settextstyle(3,0,3);
setcolor(RED);
outtextxy(130,200,"Programmed By:");
settextstyle(1,0,3);
setcolor(WHITE);
outtextxy(330,200,"Manish Jain");
outtextxy(150,235,"mkj_manishjain@yahoo.co.in");
outtextxy(150,275," +91 9896455735");
settextstyle(1,0,4);
setcolor(RED);
outtextxy(120,360,"Press any key to play");
getch();
}
void showtime()
{
char datebuf[9];
char timebuf[9];
_strdate(datebuf);
_strtime(timebuf);
gotoxy(30,45);
cout<<" DATE TIME";
gotoxy(30,46);
cout< }
inline void showscore()
{
gotoxy(15,45);
cout<<"SCORE";
gotoxy(16,46);
cout< }
char *return_maze()
{
switch(maze)
{
case 1: return ("OPEN");
case 2: return ("BOX");
case 3: return ("TWISTED");
}
return "OPEN";
}
void init()
{
DIRECTION=Pre_Dir=RIGHT;
gotoxy(60,30);
cout<<"M A Z E";
gotoxy(60,32);
cout< gotoxy(5,45);
cout<<"Timer";
randomize();
_setcursortype(_NOCURSOR);
showtime();
showscore();
tail.x=10;
tail.y=10;
for(int i=10;i<15;i++)
{
coordinate[len].x=i;
coordinate[len].y=10;
gotoxy(coordinate[len].x,coordinate[len].y);
cout< len++;
}
head.x=14;
head.y=10;
textcolor(BLUE);
for(i=1;i<=50;i++)
{
j=1;
gotoxy(i,j);
cprintf("");
gotoxy(i,j+40);
cprintf("");
}
for(i=1;i<=41;i++)
{
j=1;
gotoxy(j,i);
cprintf("");
gotoxy(j+50,i);
cprintf("");
}
showfood();
}
void show_snake(int DIRECTION)
{
gotoxy(head.x,head.y);
textcolor(GREEN);
switch(DIRECTION)
{
case UP :
if(Pre_Dir==LEFT)
cprintf("Ý");
else
cprintf("Þ");
break;
case RIGHT:
if(Pre_Dir==DOWN)
cprintf("Ü");
else
cprintf("ß");
break;
case DOWN :
if(Pre_Dir==RIGHT)
cprintf("Þ");
else
cprintf("Ý");
break;
case LEFT :
if(Pre_Dir==UP)
cprintf("ß");
else
cprintf("Ü");
break;
}
}
inline void showoff()
{
gotoxy(tail.x,tail.y);
cout<<" ";
}
inline void SOUND()
{
sound(1500);
delay(55);
nosound();
}
void gameover()
{
sound(1220);
delay(500);
nosound();
initialise();
border();
settextstyle(1,0,5);
setcolor(RED);
outtextxy(130,180,"GAME OVER");
settextstyle(1,0,5);
setcolor(BLUE);
outtextxy(140,250,"SCORE");
gotoxy(48,16);
char *s;
ltoa(score,s,10);
outtextxy(325,250,s);
settextstyle(4,0,5);
setcolor(WHITE);
outtextxy(65,350,"Wish to continue:(Y/N):");
char ch=getche();
if(ch=='y'||ch=='Y')
{
outtextxy(510,350,"Y");
getch();
RESET();
initialise();
show_main_menu();
}
else if(ch=='n'||ch=='N')
{
outtextxy(510,350,"N");
free(maze_menu);
free(main_menu);
free(level_menu);
free(game_menu);
free(m_m);
free(mm);
free(lm);
free(g_m);
exit();
}
}
void loadmaze()
{
if(maze==3)
{
textcolor(WHITE);
for(i=1;i<15;i++)
{
gotoxy(i+1,30);
cprintf("²");
gotoxy(25,i+1);
cprintf("²");
gotoxy(36+i,20);
cprintf("²");
gotoxy(30,26+i);
cprintf("²");
}
}
}
void game()
{
init();
loadmaze();
sleep(2);
while(1)
{
if(bioskey(1))
{
key=bioskey(0);
int s=key>>8;
if(s==1)
exit();
else
if(s==72) //If UP arrow key is pressed
{
if(DIRECTION==4 || DIRECTION==2)
{
Pre_Dir=DIRECTION;
DIRECTION=UP;
}
}
else if(s==80) //If DOWN arrow key is pressed
{
if(DIRECTION==4 || DIRECTION==2)
{
Pre_Dir=DIRECTION;
DIRECTION=DOWN;
}
}
else if(s==77) ////If RIGHT arrow key is pressed
{
if(DIRECTION==1 || DIRECTION==3)
{
Pre_Dir=DIRECTION;
DIRECTION=RIGHT;
}
}
else if(s==75) ////If LEFT arrow key is pressed
{
if(DIRECTION==1 || DIRECTION==3)
{
Pre_Dir=DIRECTION;
DIRECTION=LEFT;
}
}
}
if(DIRECTION==2) //Right Key
head.x++;
else if(DIRECTION==1) //Up Key
head.y--;
else if(DIRECTION==4) //Left Key
head.x--;
else if(DIRECTION==3) //Down Key
head.y++;
if(maze==1) //OPEN maze
{
if(head.x>50)
head.x=2;
else if(head.x<=1)
head.x=50;
if(tail.x>50)
tail.x=2;
else if(tail.x<=1)
tail.x=50;
if(head.y>40)
head.y=2;
else if(head.y<=1)
head.y=40;
if(tail.y>40)
tail.y=2;
else if(tail.y<=1)
tail.y=40;
}
else if(maze==2) //BOX Maze
{
if(head.x>50 ||head.y>40 ||head.x<2 ||head.y<2)
gameover();
}
else if(maze==3) //TWISTED or SPIRAL Maze
{
for(i=2;i<16;i++)
{
if((head.x==25 && head.y==i)||(head.x==i && head.y==30)
||(head.x==35+i && head.y==20)||(head.x==30 && head.y==25+i))
{
gameover();
}
}
if(head.x>50)
head.x=2;
else if(head.x<=1)
head.x=50;
if(tail.x>50)
tail.x=2;
else if(tail.x<=1)
tail.x=50;
if(head.y>40)
head.y=2;
else if(head.y<=1)
head.y=40;
if(tail.y>40)
tail.y=2;
else if(tail.y<=1)
tail.y=40;
}
for(int i=0;i {
if(head.x==coordinate[i].x && head.y==coordinate[i].y)
{
gameover();
}
}
show_snake(DIRECTION);
if(head.x==food.x && head.y==food.y)
{
count++;
if(ti_rem>5)
score+=(foodtype*8)+2+(foodtype*((ti_rem*3)/2));
else
score+=(foodtype*8)+2;
ti_rem=15;
SOUND();
food.x=food.y=0;
if(count==5)
{
showbigfood();
food_flag=1;
ti_init=biostime(0,0);
showfoodtimer(1);
foodtype=1;
count=0;
}
else
{
showfood();
food_flag=0;
foodtype=0;
}
len++;
}
else
{
tail.x=coordinate[0].x;
tail.y=coordinate[0].y;
showoff();
for(int k=0;k {
coordinate[k].x=coordinate[k+1].x;
coordinate[k].y=coordinate[k+1].y;
}
}
coordinate[len-1].x=head.x;
coordinate[len-1].y=head.y;
delay(speed);
showtime();
showscore();
showfoodtimer(food_flag);
gotoxy(64,14);
cout<<"X-Cor Y-Cor";
gotoxy(65,15);
cout< }
}
void get_level_choice()
{
get:
int cho=bioskey(0);
cho=cho>>8;
switch(cho)
{
case 2:
case 48:
case 28:
case 79: speed=125;
show_main_menu();
break;
case 3:
case 23:
case 80: speed=90;
show_main_menu();
break;
case 4:
case 18:
case 81: speed=55;
show_main_menu();
break;
case 5:
case 19:
case 75: show_game_menu();
break;
default: goto get;
}
}
void get_maze_choice()
{
get:
int cho=bioskey(0);
cho=cho>>8;
switch(cho)
{
case 2:
case 28:
case 24:
case 79: maze=1;
show_main_menu();
break;
case 3:
case 48:
case 80: maze=2;
show_main_menu();
break;
case 4:
case 20:
case 81: maze=3;
show_main_menu();
break;
case 5:
case 19:
case 75: show_game_menu();
break;
default: goto get;
}
}
void getlevel()
{
cleardevice();
border();
settextstyle(1,0,5);
setcolor(RED);
outtextxy(50,140,"L E V E L");
settextstyle(3,0,5);
for(i=0;i<4;i++)
{
setcolor(WHITE);
outtextxy(67,190+(45*i),level_menu[i]);
setcolor(RED);
outtextxy(130,190+(45*i),lm[i]);
}
get_level_choice();
}
void getmaze()
{
cleardevice();
border();
settextstyle(1,0,5);
setcolor(RED);
outtextxy(50,140,"M A Z E S");
settextstyle(3,0,5);
for(i=0;i<4;i++)
{
setcolor(WHITE);
outtextxy(67,190+(45*i),maze_menu[i]);
setcolor(RED);
outtextxy(130,190+(45*i),mm[i]);
}
get_maze_choice();
}
void get_gm_choice()
{
get:
int cho=bioskey(0);
cho=cho>>8;
switch(cho)
{
case 2:
case 50:
case 28:
case 79: getmaze();
break;
case 3:
case 38:
case 80: getlevel();
break;
case 4:
case 48:
case 81: show_main_menu();
break;
default: goto get;
}
}
void show_game_menu()
{
cleardevice();
border();
settextstyle(1,0,5);
setcolor(RED);
outtextxy(50,140,"G A M E M E N U");
settextstyle(3,0,5);
for(i=0;i<3;i++)
{
setcolor(WHITE);
outtextxy(67,190+(45*i),game_menu[i]);
setcolor(RED);
outtextxy(130,190+(45*i),g_m[i]);
}
get_gm_choice();
}
void play()
{
cleardevice();
restorecrtmode();
textmode(64);
game();
}
void options()
{
show_game_menu();
}
void instruction()
{
cleardevice();
border();
setcolor(RED);
settextstyle(1,0,5);
outtextxy(50,140,"I N S T R U C T I O N S");
settextstyle(3,0,3);
setcolor(WHITE);
outtextxy(60,190,"1. Move the snake using Arrow Keys -> ");
outtextxy(60,230," UP, DOWN, LEFT, RIGHT");
outtextxy(60,270,"2. Eat food (@,é) and make snake grow longer.");
outtextxy(60,300,"3. You will get 2 points for (@) and");
outtextxy(60,330," more points for Bonus food(é)");
outtextxy(60,365,"4. Don't let it hit the walls or its tail");
settextstyle(4,0,4);
setcolor(RED);
outtextxy(140,425,"Press any key to Continue");
getch();
show_main_menu();
}
void hiscore()
{
cleardevice();
border();
setcolor(RED);
settextstyle(1,0,5);
outtextxy(50,140," H I S C O R E");
settextstyle(3,0,3);
setcolor(WHITE);
outtextxy(60,220,"Sorry! This feature is not available in this version
");
outtextxy(60,270,"For further details, Contact : ");
setcolor(GREEN);
outtextxy(60,310," mkj_manishjain@yahoo.co.in");
outtextxy(60,345," Mobile no.: +91 9896455735 ");
settextstyle(4,0,4);
setcolor(RED);
outtextxy(140,425,"Press any key to Continue");
getch();
show_main_menu();
}
void get_mm_choice()
{
get:
int cho=bioskey(0);
cho=cho>>8;
switch(cho)
{
case 2:
case 25:
case 28:
case 79: play();
break;
case 3:
case 24:
case 80: options();
break;
case 4:
case 23:
case 81: instruction();
break;
case 5:
case 35:
case 75: hiscore();
break;
case 6:
case 18:
case 76: exit();
break;
default: goto get;
}
}
void show_main_menu()
{
cleardevice();
border();
settextstyle(1,0,5);
setcolor(GREEN);
outtextxy(60,130,"M A I N M E N U");
settextstyle(3,0,5);
for(i=0;i<5;i++)
{
setcolor(WHITE);
outtextxy(67,180+(35*i),main_menu[i]);
setcolor(RED);
outtextxy(130,180+(35*i),m_m[i]);
}
get_mm_choice();
}
void end()
{
initialise();
for(j=0;j<=2;j++)
{
setcolor(RED+j);
circle(mx/2,my/2,150+j*2);
}
settextstyle(4,0,5);
outtextxy(mx/2-65,my/2-20,"The End");
getch();
closegraph();
restorecrtmode();
exit(0);
}
//MAIN FUNCTION
void main()
{
intro_graphics();
show_main_menu();
}
//80*48
#include fstream.h
#include stdlib.h
#include process.h
#include stdio.h
#include time.h
#include dos.h
#include string.h
#include graphics.h
#include bios.h
#include conio.h
#include iomanip.h
unsigned key;
int len=0,count=0,foodtype=0,d,m,food_flag=0,j=0,i=0,display_count=10,
hscore_pos=0,x_index=0,y_index=0,mx,my,maze=1,speed=100;
long score=0,ti_elap=0,ti_rem=15,tot_ti=15,ti_init;
char *main_menu[]={{"1. Play"},{"2. Options"},{"3. Instruction"},
{"4. Hi-Score"},{"5. Exit"}};
char *game_menu[]={{"1. Mazes"},{"2. Level"},{"3. Back to Main menu"}};
char *maze_menu[]={{"1. Open"},{"2. Box"},{"3. Twisted"},
{"4. Return to Main menu"}};
char *level_menu[]={{"1. Beginner"},{"2. Intermediate"},{"3. Expert"},
{"4. Return to Main menu"}};
char *m_m[]={"P","O","I","H","E"};
char *g_m[]={"M","L","B"};
char *mm[]={"O","B","T","R"};
char *lm[]={"B","I","E","R"};
int maze3_x[][14]={{2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{25},
{30},
{37,38,39,40,41,42,43,44,45,46,47,48,49,50}};
int maze3_y[][14]={{30},
{2,3,4,5,6,7,8,9,10,11,12,13,14,15},
{27,28,29,30,31,32,33,34,35,36,37,38,39,40},
{20}};
void showfood();
void end();
void show_game_menu();
void show_main_menu();
enum{UP=1,RIGHT=2,DOWN=3,LEFT=4}DIRECTION,Pre_Dir;
struct
{
unsigned x:7 ;
unsigned y:7 ;
}coordinate[1000],tail,head,food;
inline void initialise()
{
d=DETECT;
initgraph(&d,&m,"e:\tc\bgi");
cleardevice();
mx=getmaxx();
my=getmaxy();
}
void RESET()
{
len=count=foodtype=food_flag=i=j=hscore_pos=x_index=y_index=0;
display_count=10,
speed=100;
score=ti_elap=0;ti_rem=tot_ti=15;
head.x=head.y=tail.x=tail.y=food.x=food.y=0;
for(i=0;i<1000;i++)
coordinate[i].x=coordinate[i].y=0;
}
void showoff_food()
{
gotoxy(food.x,food.y);
cout<<" ";
food.x=food.y=0;
showfood();
}
int showfoodtimer(int fo_fl)
{
if(fo_fl==1)
{
if(ti_rem<=0)
{
showoff_food();
ti_rem=15;
food_flag=0;
}
else
{
ti_elap=((biostime(0,0L)-ti_init)/(speed/16));
ti_rem=(tot_ti-(ti_elap));
gotoxy(7,46);
if(ti_rem<10)
cout<<"0"<
cout<
}
else
{
gotoxy(7,46);
cout<<" ";
}
return 0;
}
void showfood()
{
int flag=0;
re:
food.x=random(49)+2;
food.y=random(39)+2;
for(i=0;i
if(food.x==coordinate[i].x && food.y==coordinate[i].y)
goto re;
}
if(maze==3)
{
for(i=0;i<4;i++)
{
for(j=0;j<14;j++)
{
if(food.x==maze3_x[i][j])
flag=1;
}
for(j=0;j<14;j++)
{
if(food.y==maze3_y[i][j] && flag==1)
goto re;
}
}
}
gotoxy(food.x,food.y);
textcolor(RED);
cprintf("@");
}
void showbigfood()
{
re1:
food.x=random(49)+2;
food.y=random(39)+2;
for(int j=0;j
if(food.x==coordinate[j].x && food.y==coordinate[j].y)
goto re1;
}
textcolor(YELLOW);
gotoxy(food.x,food.y);
cprintf("é");
}
void exit()
{
delay(50);
textmode(4);
gotoxy(10,8);
cout<<"Exiting the program";
delay(2000);
exit(0);
}
void border()
{
setcolor(GREEN);
rectangle(2,2,mx-2,my-2);
setcolor(RED);
rectangle(4,4,mx-4,my-4);
setcolor(GREEN);
rectangle(6,6,mx-6,my-6);
settextstyle(4,0,5);
outtextxy(180,40,"SNAKEMAN");
setcolor(YELLOW);
line(165,88,440,88);
setcolor(RED);
line(165,90,440,90);
}
void intro_graphics()
{
clrscr();
initialise();
border();
settextstyle(3,0,3);
setcolor(RED);
outtextxy(130,200,"Programmed By:");
settextstyle(1,0,3);
setcolor(WHITE);
outtextxy(330,200,"Manish Jain");
outtextxy(150,235,"mkj_manishjain@yahoo.co.in");
outtextxy(150,275," +91 9896455735");
settextstyle(1,0,4);
setcolor(RED);
outtextxy(120,360,"Press any key to play");
getch();
}
void showtime()
{
char datebuf[9];
char timebuf[9];
_strdate(datebuf);
_strtime(timebuf);
gotoxy(30,45);
cout<<" DATE TIME";
gotoxy(30,46);
cout<
inline void showscore()
{
gotoxy(15,45);
cout<<"SCORE";
gotoxy(16,46);
cout<
char *return_maze()
{
switch(maze)
{
case 1: return ("OPEN");
case 2: return ("BOX");
case 3: return ("TWISTED");
}
return "OPEN";
}
void init()
{
DIRECTION=Pre_Dir=RIGHT;
gotoxy(60,30);
cout<<"M A Z E";
gotoxy(60,32);
cout<
cout<<"Timer";
randomize();
_setcursortype(_NOCURSOR);
showtime();
showscore();
tail.x=10;
tail.y=10;
for(int i=10;i<15;i++)
{
coordinate[len].x=i;
coordinate[len].y=10;
gotoxy(coordinate[len].x,coordinate[len].y);
cout<
}
head.x=14;
head.y=10;
textcolor(BLUE);
for(i=1;i<=50;i++)
{
j=1;
gotoxy(i,j);
cprintf("");
gotoxy(i,j+40);
cprintf("");
}
for(i=1;i<=41;i++)
{
j=1;
gotoxy(j,i);
cprintf("");
gotoxy(j+50,i);
cprintf("");
}
showfood();
}
void show_snake(int DIRECTION)
{
gotoxy(head.x,head.y);
textcolor(GREEN);
switch(DIRECTION)
{
case UP :
if(Pre_Dir==LEFT)
cprintf("Ý");
else
cprintf("Þ");
break;
case RIGHT:
if(Pre_Dir==DOWN)
cprintf("Ü");
else
cprintf("ß");
break;
case DOWN :
if(Pre_Dir==RIGHT)
cprintf("Þ");
else
cprintf("Ý");
break;
case LEFT :
if(Pre_Dir==UP)
cprintf("ß");
else
cprintf("Ü");
break;
}
}
inline void showoff()
{
gotoxy(tail.x,tail.y);
cout<<" ";
}
inline void SOUND()
{
sound(1500);
delay(55);
nosound();
}
void gameover()
{
sound(1220);
delay(500);
nosound();
initialise();
border();
settextstyle(1,0,5);
setcolor(RED);
outtextxy(130,180,"GAME OVER");
settextstyle(1,0,5);
setcolor(BLUE);
outtextxy(140,250,"SCORE");
gotoxy(48,16);
char *s;
ltoa(score,s,10);
outtextxy(325,250,s);
settextstyle(4,0,5);
setcolor(WHITE);
outtextxy(65,350,"Wish to continue:(Y/N):");
char ch=getche();
if(ch=='y'||ch=='Y')
{
outtextxy(510,350,"Y");
getch();
RESET();
initialise();
show_main_menu();
}
else if(ch=='n'||ch=='N')
{
outtextxy(510,350,"N");
free(maze_menu);
free(main_menu);
free(level_menu);
free(game_menu);
free(m_m);
free(mm);
free(lm);
free(g_m);
exit();
}
}
void loadmaze()
{
if(maze==3)
{
textcolor(WHITE);
for(i=1;i<15;i++)
{
gotoxy(i+1,30);
cprintf("²");
gotoxy(25,i+1);
cprintf("²");
gotoxy(36+i,20);
cprintf("²");
gotoxy(30,26+i);
cprintf("²");
}
}
}
void game()
{
init();
loadmaze();
sleep(2);
while(1)
{
if(bioskey(1))
{
key=bioskey(0);
int s=key>>8;
if(s==1)
exit();
else
if(s==72) //If UP arrow key is pressed
{
if(DIRECTION==4 || DIRECTION==2)
{
Pre_Dir=DIRECTION;
DIRECTION=UP;
}
}
else if(s==80) //If DOWN arrow key is pressed
{
if(DIRECTION==4 || DIRECTION==2)
{
Pre_Dir=DIRECTION;
DIRECTION=DOWN;
}
}
else if(s==77) ////If RIGHT arrow key is pressed
{
if(DIRECTION==1 || DIRECTION==3)
{
Pre_Dir=DIRECTION;
DIRECTION=RIGHT;
}
}
else if(s==75) ////If LEFT arrow key is pressed
{
if(DIRECTION==1 || DIRECTION==3)
{
Pre_Dir=DIRECTION;
DIRECTION=LEFT;
}
}
}
if(DIRECTION==2) //Right Key
head.x++;
else if(DIRECTION==1) //Up Key
head.y--;
else if(DIRECTION==4) //Left Key
head.x--;
else if(DIRECTION==3) //Down Key
head.y++;
if(maze==1) //OPEN maze
{
if(head.x>50)
head.x=2;
else if(head.x<=1)
head.x=50;
if(tail.x>50)
tail.x=2;
else if(tail.x<=1)
tail.x=50;
if(head.y>40)
head.y=2;
else if(head.y<=1)
head.y=40;
if(tail.y>40)
tail.y=2;
else if(tail.y<=1)
tail.y=40;
}
else if(maze==2) //BOX Maze
{
if(head.x>50 ||head.y>40 ||head.x<2 ||head.y<2)
gameover();
}
else if(maze==3) //TWISTED or SPIRAL Maze
{
for(i=2;i<16;i++)
{
if((head.x==25 && head.y==i)||(head.x==i && head.y==30)
||(head.x==35+i && head.y==20)||(head.x==30 && head.y==25+i))
{
gameover();
}
}
if(head.x>50)
head.x=2;
else if(head.x<=1)
head.x=50;
if(tail.x>50)
tail.x=2;
else if(tail.x<=1)
tail.x=50;
if(head.y>40)
head.y=2;
else if(head.y<=1)
head.y=40;
if(tail.y>40)
tail.y=2;
else if(tail.y<=1)
tail.y=40;
}
for(int i=0;i
if(head.x==coordinate[i].x && head.y==coordinate[i].y)
{
gameover();
}
}
show_snake(DIRECTION);
if(head.x==food.x && head.y==food.y)
{
count++;
if(ti_rem>5)
score+=(foodtype*8)+2+(foodtype*((ti_rem*3)/2));
else
score+=(foodtype*8)+2;
ti_rem=15;
SOUND();
food.x=food.y=0;
if(count==5)
{
showbigfood();
food_flag=1;
ti_init=biostime(0,0);
showfoodtimer(1);
foodtype=1;
count=0;
}
else
{
showfood();
food_flag=0;
foodtype=0;
}
len++;
}
else
{
tail.x=coordinate[0].x;
tail.y=coordinate[0].y;
showoff();
for(int k=0;k
coordinate[k].x=coordinate[k+1].x;
coordinate[k].y=coordinate[k+1].y;
}
}
coordinate[len-1].x=head.x;
coordinate[len-1].y=head.y;
delay(speed);
showtime();
showscore();
showfoodtimer(food_flag);
gotoxy(64,14);
cout<<"X-Cor Y-Cor";
gotoxy(65,15);
cout<
}
void get_level_choice()
{
get:
int cho=bioskey(0);
cho=cho>>8;
switch(cho)
{
case 2:
case 48:
case 28:
case 79: speed=125;
show_main_menu();
break;
case 3:
case 23:
case 80: speed=90;
show_main_menu();
break;
case 4:
case 18:
case 81: speed=55;
show_main_menu();
break;
case 5:
case 19:
case 75: show_game_menu();
break;
default: goto get;
}
}
void get_maze_choice()
{
get:
int cho=bioskey(0);
cho=cho>>8;
switch(cho)
{
case 2:
case 28:
case 24:
case 79: maze=1;
show_main_menu();
break;
case 3:
case 48:
case 80: maze=2;
show_main_menu();
break;
case 4:
case 20:
case 81: maze=3;
show_main_menu();
break;
case 5:
case 19:
case 75: show_game_menu();
break;
default: goto get;
}
}
void getlevel()
{
cleardevice();
border();
settextstyle(1,0,5);
setcolor(RED);
outtextxy(50,140,"L E V E L");
settextstyle(3,0,5);
for(i=0;i<4;i++)
{
setcolor(WHITE);
outtextxy(67,190+(45*i),level_menu[i]);
setcolor(RED);
outtextxy(130,190+(45*i),lm[i]);
}
get_level_choice();
}
void getmaze()
{
cleardevice();
border();
settextstyle(1,0,5);
setcolor(RED);
outtextxy(50,140,"M A Z E S");
settextstyle(3,0,5);
for(i=0;i<4;i++)
{
setcolor(WHITE);
outtextxy(67,190+(45*i),maze_menu[i]);
setcolor(RED);
outtextxy(130,190+(45*i),mm[i]);
}
get_maze_choice();
}
void get_gm_choice()
{
get:
int cho=bioskey(0);
cho=cho>>8;
switch(cho)
{
case 2:
case 50:
case 28:
case 79: getmaze();
break;
case 3:
case 38:
case 80: getlevel();
break;
case 4:
case 48:
case 81: show_main_menu();
break;
default: goto get;
}
}
void show_game_menu()
{
cleardevice();
border();
settextstyle(1,0,5);
setcolor(RED);
outtextxy(50,140,"G A M E M E N U");
settextstyle(3,0,5);
for(i=0;i<3;i++)
{
setcolor(WHITE);
outtextxy(67,190+(45*i),game_menu[i]);
setcolor(RED);
outtextxy(130,190+(45*i),g_m[i]);
}
get_gm_choice();
}
void play()
{
cleardevice();
restorecrtmode();
textmode(64);
game();
}
void options()
{
show_game_menu();
}
void instruction()
{
cleardevice();
border();
setcolor(RED);
settextstyle(1,0,5);
outtextxy(50,140,"I N S T R U C T I O N S");
settextstyle(3,0,3);
setcolor(WHITE);
outtextxy(60,190,"1. Move the snake using Arrow Keys -> ");
outtextxy(60,230," UP, DOWN, LEFT, RIGHT");
outtextxy(60,270,"2. Eat food (@,é) and make snake grow longer.");
outtextxy(60,300,"3. You will get 2 points for (@) and");
outtextxy(60,330," more points for Bonus food(é)");
outtextxy(60,365,"4. Don't let it hit the walls or its tail");
settextstyle(4,0,4);
setcolor(RED);
outtextxy(140,425,"Press any key to Continue");
getch();
show_main_menu();
}
void hiscore()
{
cleardevice();
border();
setcolor(RED);
settextstyle(1,0,5);
outtextxy(50,140," H I S C O R E");
settextstyle(3,0,3);
setcolor(WHITE);
outtextxy(60,220,"Sorry! This feature is not available in this version
");
outtextxy(60,270,"For further details, Contact : ");
setcolor(GREEN);
outtextxy(60,310," mkj_manishjain@yahoo.co.in");
outtextxy(60,345," Mobile no.: +91 9896455735 ");
settextstyle(4,0,4);
setcolor(RED);
outtextxy(140,425,"Press any key to Continue");
getch();
show_main_menu();
}
void get_mm_choice()
{
get:
int cho=bioskey(0);
cho=cho>>8;
switch(cho)
{
case 2:
case 25:
case 28:
case 79: play();
break;
case 3:
case 24:
case 80: options();
break;
case 4:
case 23:
case 81: instruction();
break;
case 5:
case 35:
case 75: hiscore();
break;
case 6:
case 18:
case 76: exit();
break;
default: goto get;
}
}
void show_main_menu()
{
cleardevice();
border();
settextstyle(1,0,5);
setcolor(GREEN);
outtextxy(60,130,"M A I N M E N U");
settextstyle(3,0,5);
for(i=0;i<5;i++)
{
setcolor(WHITE);
outtextxy(67,180+(35*i),main_menu[i]);
setcolor(RED);
outtextxy(130,180+(35*i),m_m[i]);
}
get_mm_choice();
}
void end()
{
initialise();
for(j=0;j<=2;j++)
{
setcolor(RED+j);
circle(mx/2,my/2,150+j*2);
}
settextstyle(4,0,5);
outtextxy(mx/2-65,my/2-20,"The End");
getch();
closegraph();
restorecrtmode();
exit(0);
}
//MAIN FUNCTION
void main()
{
intro_graphics();
show_main_menu();
}
Koi Mil Gaya
A scene From movie KOI MIL GAYA made in c.g......
#include iostream.h
#include conio.h
#include graphics.h
#include math.h
#include dos.h
int gd=DETECT,gm;
int xc=50,yc=50,xl,yl;
void earth();
void ufo()
{
int r=10,s=2;
int erx=r*2,ery=erx/5;
static int k=1;
for(int i=0;i<3;i++,k++)
{
setcolor(1);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,15);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,1);
floodfill(xc,yc-6*k,1);
floodfill(xc,yc+6*k,1);
delay(2000);
if(i<2)
{
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
xc*=s,yc*=s,r*=s,erx*=s,ery*=s;
}
}
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
for(int j=0;j<6;j++)
{
yc+=20;
setcolor(1);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,15);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,1);
floodfill(xc,yc-6*k,1);
floodfill(xc,yc+6*k,1);
delay(1000);
if(j<5)
{
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
}
}
}
void backufo()
{
int r=40,s=2;
int erx=r*2,ery=erx/5;
int k=3;
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
// cout<<"\n"<
for(int j=0;j<6;j++)
{
yc-=20;
setcolor(1);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,15);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,1);
floodfill(xc,yc-6*k,1);
floodfill(xc,yc+6*k,1);
delay(1000);
if(j<5)
{
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
}
}
for(int i=0;i<3;i++,k--)
{
setcolor(1);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,15);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,1);
floodfill(xc,yc-6*k,1);
floodfill(xc,yc+6*k,1);
delay(1000);
if(i<2)
{
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
xc/=s,yc/=s,r/=s,erx/=s,ery/=s;
}
}
}
void legs()
{
xl=xc;
yl=yc+40;
setcolor(15);
setlinestyle(0,0,3);
for(int i=1;i<6;i++)
{
line(xl,yl,xl,yl+10*i);
line(xl-30,yl-10,(xl-30)-13*i,(yl-10)+13*i);
line(xl+30,yl-10,(xl+30)+13*i,(yl-10)+13*i);
delay(500);
}
}
void backleg()
{
setcolor(0);
setlinestyle(0,0,3);
line(xl-95,yl+55,xl-30,yl-10);
line(xl+95,yl+55,xl+30,yl-10);
line(xl,yl+60,xl,yl);
}
void earth()
{
setcolor(6);
// ellipse(getmaxx()/2,getmaxy(),0,180,430,75);
setfillstyle(1,6);
line(0,getmaxy()-71,getmaxx(),getmaxy()-71);
floodfill(getmaxx()/2,getmaxy()-10,6);
}
void flash()
{
int poly[8]={xl+30,yl-10,xl+37,yl-20,xl+300,yl+48,xl+200,yl+42};
setcolor(0);
setfillstyle(1,14);
fillpoly(4,poly);
delay(1000);
setfillstyle(1,0);
fillpoly(4,poly);
}
int xe=xl+450;
int ye=yl+405;
void elliens(int c)
{
setcolor(c);
setlinestyle(0,0,1);
ellipse(xe,ye,90,180,20,60);
ellipse(xe+20,ye-60,180,270,20,60);
ellipse(xe+10,ye-60,0,360,9,13);
line(xe-20,ye,xe+20,ye);
setfillstyle(1,c);
floodfill(xe,ye-10,c);
floodfill(xe+10,ye-60,c);
setcolor(c);
setlinestyle(0,0,1);
ellipse(xe+50,ye,90,180,20,60);
ellipse(xe+70,ye-60,180,270,20,60);
ellipse(xe+60,ye-60,0,360,9,13);
line(xe+30,ye,xe+70,ye);
setfillstyle(1,c);
floodfill(xe+50,ye-10,c);
floodfill(xe+60,ye-60,c);
}
void move()
{
for(int k=0;k<25;k++)
{
elliens(0);
xe+=10;
elliens(3);
delay(500);
}
sound(4000);
delay(4000);
nosound();
elliens(0);
}
void rtnelli(int c)
{
setcolor(c);
setlinestyle(0,0,1);
ellipse(xe,ye,0,90,20,60);
ellipse(xe-20,ye-60,270,360,20,60);
ellipse(xe-10,ye-60,0,360,9,13);
line(xe-20,ye,xe+20,ye);
setfillstyle(1,c);
floodfill(xe,ye-10,c);
floodfill(xe-10,ye-60,c);
}
void back()
{
for(int k=0;k<25;k++)
{
rtnelli(0);
xe-=10;
rtnelli(3);
delay(500);
}
}
void main()
{
initgraph(&gd,&gm,"c:/TC/bgi");
cleardevice();
earth();
ufo();
legs();
flash();
move();
back();
flash();
rtnelli(0);
backleg();
backufo();
getch();
}
#include iostream.h
#include conio.h
#include graphics.h
#include math.h
#include dos.h
int gd=DETECT,gm;
int xc=50,yc=50,xl,yl;
void earth();
void ufo()
{
int r=10,s=2;
int erx=r*2,ery=erx/5;
static int k=1;
for(int i=0;i<3;i++,k++)
{
setcolor(1);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,15);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,1);
floodfill(xc,yc-6*k,1);
floodfill(xc,yc+6*k,1);
delay(2000);
if(i<2)
{
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
xc*=s,yc*=s,r*=s,erx*=s,ery*=s;
}
}
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
for(int j=0;j<6;j++)
{
yc+=20;
setcolor(1);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,15);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,1);
floodfill(xc,yc-6*k,1);
floodfill(xc,yc+6*k,1);
delay(1000);
if(j<5)
{
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
}
}
}
void backufo()
{
int r=40,s=2;
int erx=r*2,ery=erx/5;
int k=3;
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
// cout<<"\n"<
for(int j=0;j<6;j++)
{
yc-=20;
setcolor(1);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,15);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,1);
floodfill(xc,yc-6*k,1);
floodfill(xc,yc+6*k,1);
delay(1000);
if(j<5)
{
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
}
}
for(int i=0;i<3;i++,k--)
{
setcolor(1);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,15);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,1);
floodfill(xc,yc-6*k,1);
floodfill(xc,yc+6*k,1);
delay(1000);
if(i<2)
{
setcolor(0);
arc(xc,yc,0,180,r);
arc(xc,yc,180,360,r);
setfillstyle(1,0);
fillellipse(xc,yc,erx,ery);
setfillstyle(1,0);
floodfill(xc,yc-6*k,0);
floodfill(xc,yc+6*k,0);
xc/=s,yc/=s,r/=s,erx/=s,ery/=s;
}
}
}
void legs()
{
xl=xc;
yl=yc+40;
setcolor(15);
setlinestyle(0,0,3);
for(int i=1;i<6;i++)
{
line(xl,yl,xl,yl+10*i);
line(xl-30,yl-10,(xl-30)-13*i,(yl-10)+13*i);
line(xl+30,yl-10,(xl+30)+13*i,(yl-10)+13*i);
delay(500);
}
}
void backleg()
{
setcolor(0);
setlinestyle(0,0,3);
line(xl-95,yl+55,xl-30,yl-10);
line(xl+95,yl+55,xl+30,yl-10);
line(xl,yl+60,xl,yl);
}
void earth()
{
setcolor(6);
// ellipse(getmaxx()/2,getmaxy(),0,180,430,75);
setfillstyle(1,6);
line(0,getmaxy()-71,getmaxx(),getmaxy()-71);
floodfill(getmaxx()/2,getmaxy()-10,6);
}
void flash()
{
int poly[8]={xl+30,yl-10,xl+37,yl-20,xl+300,yl+48,xl+200,yl+42};
setcolor(0);
setfillstyle(1,14);
fillpoly(4,poly);
delay(1000);
setfillstyle(1,0);
fillpoly(4,poly);
}
int xe=xl+450;
int ye=yl+405;
void elliens(int c)
{
setcolor(c);
setlinestyle(0,0,1);
ellipse(xe,ye,90,180,20,60);
ellipse(xe+20,ye-60,180,270,20,60);
ellipse(xe+10,ye-60,0,360,9,13);
line(xe-20,ye,xe+20,ye);
setfillstyle(1,c);
floodfill(xe,ye-10,c);
floodfill(xe+10,ye-60,c);
setcolor(c);
setlinestyle(0,0,1);
ellipse(xe+50,ye,90,180,20,60);
ellipse(xe+70,ye-60,180,270,20,60);
ellipse(xe+60,ye-60,0,360,9,13);
line(xe+30,ye,xe+70,ye);
setfillstyle(1,c);
floodfill(xe+50,ye-10,c);
floodfill(xe+60,ye-60,c);
}
void move()
{
for(int k=0;k<25;k++)
{
elliens(0);
xe+=10;
elliens(3);
delay(500);
}
sound(4000);
delay(4000);
nosound();
elliens(0);
}
void rtnelli(int c)
{
setcolor(c);
setlinestyle(0,0,1);
ellipse(xe,ye,0,90,20,60);
ellipse(xe-20,ye-60,270,360,20,60);
ellipse(xe-10,ye-60,0,360,9,13);
line(xe-20,ye,xe+20,ye);
setfillstyle(1,c);
floodfill(xe,ye-10,c);
floodfill(xe-10,ye-60,c);
}
void back()
{
for(int k=0;k<25;k++)
{
rtnelli(0);
xe-=10;
rtnelli(3);
delay(500);
}
}
void main()
{
initgraph(&gd,&gm,"c:/TC/bgi");
cleardevice();
earth();
ufo();
legs();
flash();
move();
back();
flash();
rtnelli(0);
backleg();
backufo();
getch();
}
4-Stroke Engine
This shows the full process ok 4-stroke engine.........
#include iostream.h
#include conio.h
#include graphics.h
#include math.h
#include dos.h
#define PI 3.141593
int gd=DETECT,gm,xc,yc;
int pst[10],inv[8],ov[8],shaft[8];
void init()
{
int epst[10]={279,109,279,159,359,159,359,109,279,109};
int einv[8]={234,19,289,69,279,79,299,59};
int eov[8]={404,19,349,69,359,79,339,59};
int eshaft[8]={309,159,319,249,329,159,309,159};
for(int i=0;i<10;i++) pst[i]=epst[i];
for(i=0;i<8;i++)
{
inv[i]=einv[i];
ov[i]=eov[i];
shaft[i]=eshaft[i];
}
}
void cyllinder()
{ // static coding
setcolor(6);
setlinestyle(0,0,1);
xc=getmaxx()/2;
yc=getmaxy()/2;
// cout<<"xc: "< circle(xc,yc+50,5);
arc(xc,yc+50,120,60,80); //inner arc
arc(xc,yc+50,120,60,90); //outer arc
circle(xc,yc+50,55);
circle(xc,yc+50,65);
circle(xc,yc+50,25);
arc(xc,yc-105,60,120,90); //upper arc
line(xc-45,yc-150,xc-45,yc-27); //left of left
line(xc-40,yc-160,xc-40,yc-20); //right of left
line(xc+45,yc-150,xc+45,yc-27); //right of right
line(xc+40,yc-160,xc+40,yc-20); //left of right
line(xc-45,yc-150,xc-85,yc-150); //lower left
line(xc-40,yc-160,xc-85,yc-160); //upper left
line(xc+45,yc-150,xc+85,yc-150); //lower right
line(xc+40,yc-160,xc+85,yc-160); //upper right
line(xc-85,yc-180,xc+85,yc-180); //upper most
line(xc-15,yc-193,xc-15,yc-180); //spark plug
line(xc+15,yc-193,xc+15,yc-180); // ''
line(xc-8,yc-195,xc-8,yc-180); // ''
line(xc+8,yc-195,xc+8,yc-180); // ''
line(xc-8,yc-195,xc,yc-215); // ''
line(xc+8,yc-195,xc,yc-215); // ''
line(xc-5,yc-180,xc-5,yc-168); // ''
line(xc+5,yc-168,xc-5,yc-168); // ''
line(xc,yc-180,xc,yc-170); // ''
line(xc+5,yc-180,xc+5,yc-170); // ''
line(xc,yc-170,xc+5,yc-170); // ''
setfillstyle(1,4);
floodfill(xc+2,yc-175,6);
line(xc-85,yc-150,xc-85,yc-180); // left stop
line(xc+85,yc-150,xc+85,yc-180); // right stop
setfillstyle(1,6);
floodfill(xc-80,yc-155,6);
}
void drawpst()
{
setlinestyle(0,0,3);
drawpoly(5,pst);
int xh=pst[0];
int yh=pst[1];
line(xh,yh+10,xh+80,yh+10);
line(xh,yh+15,xh+80,yh+15);
}
void drawin()
{
setlinestyle(0,0,3);
drawpoly(4,inv);
}
void drawout()
{
setlinestyle(0,0,3);
drawpoly(4,ov);
}
void drawshaft()
{
setlinestyle(0,0,3);
drawpoly(4,shaft);
setlinestyle(0,0,1);
int xh=shaft[2];
int yh=shaft[3];
circle(xh,yh,5);
int poly[10]={xh-8,yh-6,xh-8,yh+6,xh+8,yh+6,xh+8,yh-6,xh-8,yh-6};
line(xc-5,yc+50,xh-5,yh);
line(xc+5,yc+50,xh+5,yh);
drawpoly(5,poly);
}
void transpst(int t)
{
int k=1;
if(t<0)
{k=-k;t=-t;}
for(int j=0;j {
delay(15);
setcolor(0);
drawpst();
for(int i=1;i<10;i+=2)
pst[i]+=k;
setcolor(6);
drawpst();
cyllinder();
}
}
void transin(int t)
{
int k=1;
if(t<0)
{k=-k;t=-t;}
for(int j=0;j {
delay(15);
setcolor(0);
drawin();
for(int i=0;i<10;i++)
inv[i]+=k;
setcolor(6);
drawin();
cyllinder();
}
}
void transout(int t)
{
int k=1;
if(t<0)
{k=-k;t=-t;}
for(int j=0;j {
delay(15);
setcolor(0);
drawout();
for(int i=0;i<10;i++)
{
ov[i]-=k;
i++;
ov[i]+=k;
}
setcolor(6);
drawout();
cyllinder();
}
}
void transshaft(int t)
{int k=1;
if(t<0)
{k=-k;t=-t;}
float v=0;
for(int j=0;j {
double theta=double(v)*(PI/180.0);
delay(15);
setcolor(0);
drawshaft();
for(int i=1;i<8;i+=2)
{if(i==2 || i==3)
continue;
shaft[i]+=k;
}
int xr=xc;
int yr=yc+60;
int x=shaft[2];
int x1=x;
int y=shaft[3];
int y1=y;
x=xr+(x1-xr)*cos(theta)-(y1-yr)*sin(theta);
y=yr+(x1-xr)*sin(theta)+(y1-yr)*cos(theta);
shaft[2]=x;
shaft[3]=y;
v+=3.05;
setcolor(6);
drawshaft();
cyllinder();
}
}
void intake()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(277,390,"Exhaust");
setcolor(5);
settextstyle(1,0,3);
outtextxy(275,390," Intake");
int xf=xc;
int yf=yc-150;
for(int i=0;i<20;i++)
{
transpst(3);
transshaft(3);
transin(1);
}
transin(-20);
setfillstyle(1,15);
floodfill(xf,yf,6);
}
void comp()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(275,390," Intake");
setcolor(5);
settextstyle(1,0,3);
outtextxy(255,390,"Compression");
int xf=xc;
int yf=yc-150;
setfillstyle(1,0);
floodfill(259,69,6);
for(int i=0;i<20;i++)
{
transpst(-3);
transshaft(-3);
}
setfillstyle(1,14);
floodfill(xf,yf,6);
}
void spark()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(255,390,"Compression");
setcolor(5);
settextstyle(1,0,3);
outtextxy(277,390,"Ignition");
setcolor(4);
line(xc,yc-166,xc-2,yc-160);
line(xc-6,yc-166,xc-10,yc-160);
line(xc+3,yc-166,xc+5,yc-160);
line(xc+9,yc-166,xc+13,yc-160);
}
void expa()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(277,390,"Ignition");
setcolor(5);
settextstyle(1,0,3);
outtextxy(270,390,"Expansion");
int xf=xc;
int yf=yc-150;
setfillstyle(1,0);
floodfill(xf,yf,6);
for(int i=0;i<20;i++)
{
transpst(3);
transshaft(3);
}
setfillstyle(1,15);
floodfill(xf,yf,6);
}
void exhaust()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(270,390,"Expansion");
setcolor(5);
settextstyle(1,0,3);
outtextxy(277,390,"Exhaust");
int xf=xc;
int yf=yc-150;
setfillstyle(1,0);
floodfill(xf,yf,6);
for(int i=0;i<20;i++)
{
transpst(-3);
transshaft(-3);
// transout(1);
}
transout(20);
transout(-20);
}
void draw()
{
cyllinder();
drawpst();
drawin();
drawout();
drawshaft();
}
void contd()
{
for(int i=0;i<2;i++)
{
intake();
delay(700);
comp();
delay(700);
spark();
delay(1000);
expa();
delay(700);
exhaust();
}
}
void back()
{
cleardevice();
init();
setbkcolor(3);
draw();
setcolor(15);
setlinestyle(0,0,3);
rectangle(5,5,633,475);
setcolor(1);
settextstyle(0,0,1);
outtextxy(150,430,"* Press ENTER to see engine strokes one by one *");
outtextxy(150,450,"* Press SPACE BAR to see continues engine cycle *");
outtextxy(382,360,"* Press 'N' for Nomenclature *");
setcolor(4);
rectangle(10,10,40,30);
outtextxy(14,16,"Esc");
outtextxy(45,16,"Press Escape to QUIT");
setcolor(11);
settextstyle(0,0,9);
outtextxy(35,310,"4");
setcolor(4);
settextstyle(0,0,3);
outtextxy(65,350,"Stroke");
setcolor(14);
settextstyle(1,0,6);
outtextxy(420,140,"Internal");
settextstyle(1,0,4);
outtextxy(425,230,"Combustion");
setcolor(11);
settextstyle(1,0,7);
outtextxy(545,90,"E");
settextstyle(1,0,6);
outtextxy(417,140," n");
settextstyle(1,0,5);
outtextxy(555,182,"g");
settextstyle(1,0,4);
outtextxy(433,230," i");
settextstyle(1,0,3);
outtextxy(559,258,"n");
settextstyle(1,0,2);
outtextxy(562,280,"e");
setcolor(15);
}
void name()
{
back();
setcolor(15);
settextstyle(2,0,6);
setlinestyle(0,0,1);
outtextxy(280,5,"Spark Plug");
outtextxy(170,25,"Intake Valve");
outtextxy(370,25,"Exhaust Valve");
line(250,120,300,120);
outtextxy(140,108,"Vccum Rings");
outtextxy(295,130,"Piston");
line(230,200,320,200);
outtextxy(135,188,"Piston Rod");
outtextxy(340,170,"Cyllinder");
line(200,250,320,250);
outtextxy(90,240,"Crank Shaft");
getch();
back();
}
void main()
{
initgraph(&gd,&gm,"C:/TC/bgi");
back();
char choice;
int count=0;
while(choice!=27)
{
choice=getch();
switch(choice)
{
case 'n':
case 'N':
name();
count=0;
break;
case 13:switch(count)
{
case 0:
intake();
count++;
break;
case 1:comp();
count++;
break;
case 2:spark();
count++;
break;
case 3:expa();
count++;
break;
case 4:exhaust();
count=0;
break;
}
break;
case 32:back();
contd();
count=0;
break;
}
}
cleardevice();
setbkcolor(9);
settextstyle(4,0,8);
setcolor(15);
setlinestyle(0,0,3);
rectangle(5,5,633,475);
setcolor(4);
outtextxy(50,100,"THANK YOU !!");
settextstyle(3,0,4);
outtextxy(200,250,"CREATED BY:-");
outtextxy(200,300,"VIVEK P. MEHTA");
outtextxy(200,350,"B.E. 3RD COMPUTER");
getch();
}
#include iostream.h
#include conio.h
#include graphics.h
#include math.h
#include dos.h
#define PI 3.141593
int gd=DETECT,gm,xc,yc;
int pst[10],inv[8],ov[8],shaft[8];
void init()
{
int epst[10]={279,109,279,159,359,159,359,109,279,109};
int einv[8]={234,19,289,69,279,79,299,59};
int eov[8]={404,19,349,69,359,79,339,59};
int eshaft[8]={309,159,319,249,329,159,309,159};
for(int i=0;i<10;i++) pst[i]=epst[i];
for(i=0;i<8;i++)
{
inv[i]=einv[i];
ov[i]=eov[i];
shaft[i]=eshaft[i];
}
}
void cyllinder()
{ // static coding
setcolor(6);
setlinestyle(0,0,1);
xc=getmaxx()/2;
yc=getmaxy()/2;
// cout<<"xc: "<
arc(xc,yc+50,120,60,80); //inner arc
arc(xc,yc+50,120,60,90); //outer arc
circle(xc,yc+50,55);
circle(xc,yc+50,65);
circle(xc,yc+50,25);
arc(xc,yc-105,60,120,90); //upper arc
line(xc-45,yc-150,xc-45,yc-27); //left of left
line(xc-40,yc-160,xc-40,yc-20); //right of left
line(xc+45,yc-150,xc+45,yc-27); //right of right
line(xc+40,yc-160,xc+40,yc-20); //left of right
line(xc-45,yc-150,xc-85,yc-150); //lower left
line(xc-40,yc-160,xc-85,yc-160); //upper left
line(xc+45,yc-150,xc+85,yc-150); //lower right
line(xc+40,yc-160,xc+85,yc-160); //upper right
line(xc-85,yc-180,xc+85,yc-180); //upper most
line(xc-15,yc-193,xc-15,yc-180); //spark plug
line(xc+15,yc-193,xc+15,yc-180); // ''
line(xc-8,yc-195,xc-8,yc-180); // ''
line(xc+8,yc-195,xc+8,yc-180); // ''
line(xc-8,yc-195,xc,yc-215); // ''
line(xc+8,yc-195,xc,yc-215); // ''
line(xc-5,yc-180,xc-5,yc-168); // ''
line(xc+5,yc-168,xc-5,yc-168); // ''
line(xc,yc-180,xc,yc-170); // ''
line(xc+5,yc-180,xc+5,yc-170); // ''
line(xc,yc-170,xc+5,yc-170); // ''
setfillstyle(1,4);
floodfill(xc+2,yc-175,6);
line(xc-85,yc-150,xc-85,yc-180); // left stop
line(xc+85,yc-150,xc+85,yc-180); // right stop
setfillstyle(1,6);
floodfill(xc-80,yc-155,6);
}
void drawpst()
{
setlinestyle(0,0,3);
drawpoly(5,pst);
int xh=pst[0];
int yh=pst[1];
line(xh,yh+10,xh+80,yh+10);
line(xh,yh+15,xh+80,yh+15);
}
void drawin()
{
setlinestyle(0,0,3);
drawpoly(4,inv);
}
void drawout()
{
setlinestyle(0,0,3);
drawpoly(4,ov);
}
void drawshaft()
{
setlinestyle(0,0,3);
drawpoly(4,shaft);
setlinestyle(0,0,1);
int xh=shaft[2];
int yh=shaft[3];
circle(xh,yh,5);
int poly[10]={xh-8,yh-6,xh-8,yh+6,xh+8,yh+6,xh+8,yh-6,xh-8,yh-6};
line(xc-5,yc+50,xh-5,yh);
line(xc+5,yc+50,xh+5,yh);
drawpoly(5,poly);
}
void transpst(int t)
{
int k=1;
if(t<0)
{k=-k;t=-t;}
for(int j=0;j
delay(15);
setcolor(0);
drawpst();
for(int i=1;i<10;i+=2)
pst[i]+=k;
setcolor(6);
drawpst();
cyllinder();
}
}
void transin(int t)
{
int k=1;
if(t<0)
{k=-k;t=-t;}
for(int j=0;j
delay(15);
setcolor(0);
drawin();
for(int i=0;i<10;i++)
inv[i]+=k;
setcolor(6);
drawin();
cyllinder();
}
}
void transout(int t)
{
int k=1;
if(t<0)
{k=-k;t=-t;}
for(int j=0;j
delay(15);
setcolor(0);
drawout();
for(int i=0;i<10;i++)
{
ov[i]-=k;
i++;
ov[i]+=k;
}
setcolor(6);
drawout();
cyllinder();
}
}
void transshaft(int t)
{int k=1;
if(t<0)
{k=-k;t=-t;}
float v=0;
for(int j=0;j
double theta=double(v)*(PI/180.0);
delay(15);
setcolor(0);
drawshaft();
for(int i=1;i<8;i+=2)
{if(i==2 || i==3)
continue;
shaft[i]+=k;
}
int xr=xc;
int yr=yc+60;
int x=shaft[2];
int x1=x;
int y=shaft[3];
int y1=y;
x=xr+(x1-xr)*cos(theta)-(y1-yr)*sin(theta);
y=yr+(x1-xr)*sin(theta)+(y1-yr)*cos(theta);
shaft[2]=x;
shaft[3]=y;
v+=3.05;
setcolor(6);
drawshaft();
cyllinder();
}
}
void intake()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(277,390,"Exhaust");
setcolor(5);
settextstyle(1,0,3);
outtextxy(275,390," Intake");
int xf=xc;
int yf=yc-150;
for(int i=0;i<20;i++)
{
transpst(3);
transshaft(3);
transin(1);
}
transin(-20);
setfillstyle(1,15);
floodfill(xf,yf,6);
}
void comp()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(275,390," Intake");
setcolor(5);
settextstyle(1,0,3);
outtextxy(255,390,"Compression");
int xf=xc;
int yf=yc-150;
setfillstyle(1,0);
floodfill(259,69,6);
for(int i=0;i<20;i++)
{
transpst(-3);
transshaft(-3);
}
setfillstyle(1,14);
floodfill(xf,yf,6);
}
void spark()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(255,390,"Compression");
setcolor(5);
settextstyle(1,0,3);
outtextxy(277,390,"Ignition");
setcolor(4);
line(xc,yc-166,xc-2,yc-160);
line(xc-6,yc-166,xc-10,yc-160);
line(xc+3,yc-166,xc+5,yc-160);
line(xc+9,yc-166,xc+13,yc-160);
}
void expa()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(277,390,"Ignition");
setcolor(5);
settextstyle(1,0,3);
outtextxy(270,390,"Expansion");
int xf=xc;
int yf=yc-150;
setfillstyle(1,0);
floodfill(xf,yf,6);
for(int i=0;i<20;i++)
{
transpst(3);
transshaft(3);
}
setfillstyle(1,15);
floodfill(xf,yf,6);
}
void exhaust()
{
setcolor(0);
settextstyle(1,0,3);
outtextxy(270,390,"Expansion");
setcolor(5);
settextstyle(1,0,3);
outtextxy(277,390,"Exhaust");
int xf=xc;
int yf=yc-150;
setfillstyle(1,0);
floodfill(xf,yf,6);
for(int i=0;i<20;i++)
{
transpst(-3);
transshaft(-3);
// transout(1);
}
transout(20);
transout(-20);
}
void draw()
{
cyllinder();
drawpst();
drawin();
drawout();
drawshaft();
}
void contd()
{
for(int i=0;i<2;i++)
{
intake();
delay(700);
comp();
delay(700);
spark();
delay(1000);
expa();
delay(700);
exhaust();
}
}
void back()
{
cleardevice();
init();
setbkcolor(3);
draw();
setcolor(15);
setlinestyle(0,0,3);
rectangle(5,5,633,475);
setcolor(1);
settextstyle(0,0,1);
outtextxy(150,430,"* Press ENTER to see engine strokes one by one *");
outtextxy(150,450,"* Press SPACE BAR to see continues engine cycle *");
outtextxy(382,360,"* Press 'N' for Nomenclature *");
setcolor(4);
rectangle(10,10,40,30);
outtextxy(14,16,"Esc");
outtextxy(45,16,"Press Escape to QUIT");
setcolor(11);
settextstyle(0,0,9);
outtextxy(35,310,"4");
setcolor(4);
settextstyle(0,0,3);
outtextxy(65,350,"Stroke");
setcolor(14);
settextstyle(1,0,6);
outtextxy(420,140,"Internal");
settextstyle(1,0,4);
outtextxy(425,230,"Combustion");
setcolor(11);
settextstyle(1,0,7);
outtextxy(545,90,"E");
settextstyle(1,0,6);
outtextxy(417,140," n");
settextstyle(1,0,5);
outtextxy(555,182,"g");
settextstyle(1,0,4);
outtextxy(433,230," i");
settextstyle(1,0,3);
outtextxy(559,258,"n");
settextstyle(1,0,2);
outtextxy(562,280,"e");
setcolor(15);
}
void name()
{
back();
setcolor(15);
settextstyle(2,0,6);
setlinestyle(0,0,1);
outtextxy(280,5,"Spark Plug");
outtextxy(170,25,"Intake Valve");
outtextxy(370,25,"Exhaust Valve");
line(250,120,300,120);
outtextxy(140,108,"Vccum Rings");
outtextxy(295,130,"Piston");
line(230,200,320,200);
outtextxy(135,188,"Piston Rod");
outtextxy(340,170,"Cyllinder");
line(200,250,320,250);
outtextxy(90,240,"Crank Shaft");
getch();
back();
}
void main()
{
initgraph(&gd,&gm,"C:/TC/bgi");
back();
char choice;
int count=0;
while(choice!=27)
{
choice=getch();
switch(choice)
{
case 'n':
case 'N':
name();
count=0;
break;
case 13:switch(count)
{
case 0:
intake();
count++;
break;
case 1:comp();
count++;
break;
case 2:spark();
count++;
break;
case 3:expa();
count++;
break;
case 4:exhaust();
count=0;
break;
}
break;
case 32:back();
contd();
count=0;
break;
}
}
cleardevice();
setbkcolor(9);
settextstyle(4,0,8);
setcolor(15);
setlinestyle(0,0,3);
rectangle(5,5,633,475);
setcolor(4);
outtextxy(50,100,"THANK YOU !!");
settextstyle(3,0,4);
outtextxy(200,250,"CREATED BY:-");
outtextxy(200,300,"VIVEK P. MEHTA");
outtextxy(200,350,"B.E. 3RD COMPUTER");
getch();
}
Hangman Game
Hangman Game in c.g using C++.....
//A HANGMAN Game Program Dated: 14 NOV 2005
/*
Developed By: Manish Jain 1103143 3rd yr M.M.E.C. Mulana
mkj_manishjain@yahoo.co.in
+91 9896455735
*/
//HEADER FILES
#include fstream.h
#include bios.h
#include time.h
#include dos.h
#include stdio.h
#include string.h
#include stdlib.h
#include graphics.h
#include conio.h
#include mouse.h
#define SMILE 1
#define SAD 0
//VARIABLES AND FUNCTIONS DECLARATION
unsigned key;
char firstrow[]={'Q','W','E','R','T','Y','U','I','O','P'};
char secondrow[]={'A','S','D','F','G','H','J','K','L'};
char thirdrow[]={'Z','X','C','V','B','N','M'};
char *main_menu[]={{"1. PLAY"},{"2. INSTRUCTIONS"},{"3. HI-SCORE"},{"4.
EXIT"}};
char *categories[]={{"1. MOVIES"},{"2. SPORTS"},{"3. MOVIE STARS"},{"4.
PLACES"}};
char *m_m[]={"P","I","H","E"},*c_m[]={"M","S","A","P"};
int
blankpos_x[]={25,50,75,100,125,150,175,200,225,250,275,300,325,350,375,400
};
int blankpos_y[]={80,150,300,340},cat_pos_x[]={130,130,314,130};
char string[50],name[25],category[20],checklist[50],hitlist[50];
char wr_guesses[10],ch,datebuf[9],timebuf[9];
int
button,x,y,corx,cory,len=0,d,m,mx,my,i,j,k,count_s=0,count_f=0,hcount=0,fl
ag=0,hlflag=1,spaces=0;
int hlcount=0,prflag=0,hngmnflag=0,dispflag=0,gameflag=0;
int tcolor=GREEN,acolor=RED;
void drawsetup();
void game();
void play();
void initgraphics();
void show_main_menu();
void getoption();
//FUNCTION TO INITIALISE ALL THE VARIABLES
void init()
{
hlcount=0,prflag=0,hngmnflag=0,dispflag=0,gameflag=0;
tcolor=GREEN,acolor=RED;
len=0,count_s=0,count_f=0,hcount=0,flag=0,hlflag=1,spaces=0;
strcpy(hitlist,"");
strcpy(checklist,"");
strcpy(wr_guesses,"");
}
//CLASS RECORD TO READ RECORD FROM THE FILES
class record
{
char word[50];
public:
void input()
{
gets(word);
}
void output()
{
puts(word);
}
char *returnword()
{
return word;
}
}rec,out;
//BORDER FUNCTIONS TO BORDER EACH PAGE
void border()
{
setcolor(GREEN);
rectangle(2,2,mx-2,my-2);
setcolor(RED);
rectangle(4,4,mx-4,my-4);
setcolor(GREEN);
rectangle(6,6,mx-6,my-6);
settextstyle(4,0,5);
outtextxy(180,40,"HANGMAN");
setcolor(YELLOW);
line(175,88,420,88);
setcolor(RED);
line(175,90,420,90);
}
//FUNCTION TO DISPLAY THE VERY FIRST SCREEN OF THE PROGRAM
void FIRSTSCREEN()
{
clrscr();
initgraphics();
border();
settextstyle(3,0,3);
setcolor(RED);
outtextxy(130,200,"Programmed By:");
settextstyle(1,0,3);
setcolor(WHITE);
outtextxy(330,200,"Manish Jain");
outtextxy(150,235,"mkj_manishjain@yahoo.co.in");
outtextxy(150,275," +91 9896455735");
settextstyle(1,0,4);
setcolor(RED);
outtextxy(120,360,"Press any key to play");
getch();
}
//FUNCTION TO SHOW INSTRUCTIONS FOR THE USERS
void instruction()
{
cleardevice();
border();
setcolor(RED);
settextstyle(1,0,5);
outtextxy(50,140,"I N S T R U C T I O N S");
settextstyle(3,0,3);
setcolor(WHITE);
outtextxy(60,190,"1. Fill the Blanks with the suitable word.");
outtextxy(60,230,"2. The word should belong to the category");
outtextxy(60,270," selected by you.");
outtextxy(60,300,"3. You will be given 8 chances to fill it up.");
outtextxy(60,330,"4. Man on the Hanger describes your attempts ");
outtextxy(60,365,"5. Your wrong guesses are shown there.");
settextstyle(4,0,4);
setcolor(RED);
outtextxy(140,425,"Press any key to Continue");
getch();
show_main_menu();
}
//FUNCTION TO CHOOSE ONE FROM THE OPTIONS GIVEN USING MOUSE
void chooseoption()
{
cleardevice();
border();
settextstyle(1,0,5);
setcolor(GREEN);
outtextxy(50,140,"C A T E G O R I E S");
settextstyle(3,0,5);
for(i=0;i<4;i++)
{
setcolor(WHITE);
outtextxy(67,190+(45*i),categories[i]);
setcolor(RED);
rectangle(50,210+(45*i),60,220+(45*i));
outtextxy(cat_pos_x[i],190+(45*i),c_m[i]);
}
getoption();
}
//FUNCTION TO CHECK THE CATEGORY SELECTED BY THE USER
int getcategory(int x,int y)
{
//Check for category "Movies"
if((x>=10&&x<=80)&&(y>=200 &&y<=240))
{
strcpy(category,"Movies");
return 1;
}
//Check for Category "Sports"
if((x>=10&&x<=80)&&(y>=255 &&y<=280))
{
strcpy(category,"Sports");
return 1;
}
//Check for Category "Actors"
if((x>=10&&x<=80)&&(y>=285 &&y<=310))
{
strcpy(category,"Actors");
return 1;
}
//Check for Category "Places"
if((x>=10&&x<=80)&&(y>=315 &&y<=350))
{
strcpy(category,"Places");
return 1;
}
return 0;
}
//FUNCTION TO GET OPTION FROM THE USER USING MOUSE OR KEYBOARD
void getoption()
{
showmouseptr();
restrictmouseptr(10,200,80,400);
while(1)
{
getmousepos(&button,&x,&y);
if((button&1)==1)
{ corx=x;
cory=y;
if(getcategory(corx,cory)==1)
break;
}
int cho=bioskey(0);
cho=cho>>8;
switch(cho)
{
case 2:
case 50:
case 28:
case 79: strcpy(category,"Movies");
return;
case 3:
case 31:
case 80: strcpy(category,"Sports");
return;
case 4:
case 30:
case 81: strcpy(category,"Actors");
return;
case 5:
case 25:
case 75: strcpy(category,"Places");
return;
default: break;
}
}
}
//FUNCTION TO SHOWFACE (SMILING OR SAD)
void showface(int expr)
{
setcolor(RED);
circle(390,50,25);
setcolor(WHITE);
ellipse(378,45,0,360,3,4);
ellipse(402,45,0,360,3,4);
if(expr==SMILE)
arc(390,55,235,305,13);
else
arc(390,80,55,120,13);
}
//PRINTING HIGH SCORE WITH THE NAMES OF THE SCORERS
void hiscore()
{
cleardevice();
border();
setcolor(RED);
settextstyle(1,0,5);
outtextxy(50,140," H I S C O R E");
settextstyle(3,0,3);
setcolor(WHITE);
outtextxy(60,220,"Sorry! This feature is not available in this version
");
outtextxy(60,270,"For further details, Contact : ");
setcolor(GREEN);
outtextxy(60,310," mkj_manishjain@yahoo.co.in");
outtextxy(60,345," Mobile no.: +91 9896455735 ");
settextstyle(4,0,4);
setcolor(RED);
outtextxy(140,425,"Press any key to Continue");
getch();
show_main_menu();
}
//GETTING THE CHOICE FROM THE USER FOR THE MAIN MENU
void get_mm_choice()
{
get:
int cho=bioskey(0);
cho=cho>>8;
switch(cho)
{
case 2:
case 25:
case 28:
case 79: play();
break;
case 3:
case 23:
case 80: instruction();
break;
case 4:
case 35:
case 81: hiscore();
break;
case 5:
case 18:
case 75: exit(0);
break;
default: goto get;
}
}
//MAIN MENU OF THE PROGRAM
void show_main_menu()
{
cleardevice();
border();
settextstyle(1,0,5);
setcolor(GREEN);
outtextxy(60,130,"M A I N M E N U");
settextstyle(3,0,5);
for(i=0;i<4;i++)
{
setcolor(WHITE);
outtextxy(67,180+(35*i),main_menu[i]);
setcolor(RED);
outtextxy(130,180+(35*i),m_m[i]);
}
get_mm_choice();
}
//DISPLAY THE CHARACTER AT ITS APPROPRIATE POSITION WITH DESIRED COLOR
void display(char ch,int pos,int color)
{
char c[2];
c[0]=ch;
c[1]='\0';
setcolor(color);
outtextxy(blankpos_x[pos%16]+15,blankpos_y[pos/16],c);
}
//DRAWING THE MAN ON THE HANGER PARTS BY PARTS AS PER CORRECTNESS OF
GUESSES
void drawhangman(int count_f)
{
setcolor(RED);
if(hngmnflag==1)
{
switch(count_f)
{
case 1: circle(500,150,10);
hngmnflag=0;
break;
case 2: line(500,160,500,170);
hngmnflag=0;
break;
case 3: ellipse(500,192,0,360,15,20);
hngmnflag=0;
break;
case 4: line(500,213,490,218);
hngmnflag=0;
break;
case 5: line(500,213,510,218);
hngmnflag=0;
break;
case 6: line(500,170,480,180);
hngmnflag=0;
break;
case 7: line(500,170,520,180);
hngmnflag=0;
break;
case 8: setcolor(acolor);
outtextxy(100,340,"MERCY CHANCE");
delay(1000);
setcolor(getbkcolor());
outtextxy(100,340,"MERCY CHANCE");
hngmnflag=0;
break;
}
}
}
//ASKING USER IF HE WISHES TO PLAY AGAIN
void asktocontinue()
{
setcolor(WHITE);
outtextxy(40,340,"Wish to Play again:(Y/N):");
get:
char ch=getch();
if(ch=='y'||ch=='Y')
{
outtextxy(440,340,"Y");
getch();
play();
}
else if(ch=='n'||ch=='N')
{
outtextxy(440,340,"N");
getch();
exit(0);
}
goto get;
}
//CHECK THE KEY PRESSED AND TAKE APPROPRIATE ACTION
void check(char ch)
{
flag=0;
hlflag=1;
prflag=0;
for(i=0;string[i]!='\0';i++) //CHECKING CHARACTER IN THE STRING
{
if(ch==string[i]) //If char is present in the string
{
prflag=1;
for(j=0;j {
if(ch==hitlist[j]) //if char is present in the list of pressed
characters
{
hlflag=0;
break;
}
}
if(hlflag==1)
{ setcolor(tcolor);flag=1;display(ch,i,GREEN);count_s--; }
else break;
}
}
if(prflag==0) //If the character is not present in the string
{
for(j=0;checklist[j]!='\0';j++)
{
if(ch==checklist[j])
return;
}
checklist[count_f++]=ch;
wr_guesses[count_f-1]=ch;
display(ch,32+(count_f),RED);
hngmnflag=1;
}
else if(prflag==1 && flag==1) //If the character present is repeated
hitlist[hlcount++]=ch;
if(count_s==0) //GAME CLEARED
{
setcolor(acolor);
outtextxy(100,265,"\nGame Cleared");
gameflag=1;
//DRAWING A SMILING FACE TO SHOW GAME CLEARED
showface(SMILE);
asktocontinue();
}
else if(count_f>8) //GAME OVER
{
setcolor(acolor);
outtextxy(100,265,"\nGame Over");
gameflag=1;
setcolor(RED);
for(i=0;string[i]!='\0';i++)
{
dispflag=0;
for(j=0;j {
if(string[i]==hitlist[j])
{
dispflag=1;
break;
}
}
if(dispflag==0) //Display Remaining Characters
display(string[i],i,RED);
}
//DRAWING A SAD FACE TO SHOW GAME OVER
showface(SAD);
asktocontinue();
getch();
exit(0);
}
drawhangman(count_f);
}
void matchkey(int s) //GENERATING THE ASCII OF THE KEY PRESSED
{
if(s>=16 && s<=25)
ch=firstrow[s-16];
else if(s>=30 && s<=38)
ch=secondrow[s-30];
else if(s>=44 && s<=50)
ch=thirdrow[s-44];
else if(s>=2 && s<=10)
ch=(char)(47+s);
else if(s==11)
ch=(char)48;
check(ch);
}
//SHOW DATE AND TIME
void showtime()
{
_strtime(timebuf);
setcolor(GREEN);
settextstyle(1,0,3);
setviewport(340,18,460,60,1);
outtextxy(10,2,timebuf);
delay(50);
clearviewport();
settextstyle(1,0,4);
}
//DRAW THE HANGER FOR MAN TO BE HANGED
void drawhanger()
{
setcolor(WHITE);
line(500,125,500,140);
line(500,125,525,125);
line(525,125,525,220);
}
//DRAW THE SETUP FOR THE GAME
void drawsetup()
{
hidemouseptr();
cleardevice();
setcolor(BLUE);
rectangle(8,8,mx-8,my-8);
setcolor(RED);
rectangle(9,9,mx-9,my-9);
line(10,381,mx-10,381);
line(10,341,468,341);
line(10,301,468,301);
line(10,65,330,65);
setcolor(GREEN);
rectangle(10,10,mx-10,my-10);
line(10,380,mx-10,380);
line(10,340,468,340);
line(10,300,468,300);
line(10,66,330,66);
bar(468,10,472,380);
bar(188,10,192,66);
bar(328,10,332,66);
settextstyle(1,0,3);
_strdate(datebuf);
outtextxy(220,10,"DATE");
outtextxy(200,30,datebuf);
settextstyle(8,0,7);
outtextxy(50,360,"H A N G M A N");
setcolor(YELLOW);
outtextxy(48,360,"H A N G M A N");
setcolor(WHITE);
outtextxy(46,360,"H A N G M A N");
settextstyle(2,0,4);
outtextxy(46,446,"c"); //COPYRIGHT SYMBOL
circle(48,453,4);
settextstyle(3,0,3);
outtextxy(56,435," Fantasatic Four (P) Ltd. 2003-07");
settextstyle(3,0,4);
setcolor(BLUE);
outtextxy(500,18,"Player");
settextstyle(3,0,2);
setcolor(WHITE);
outtextxy(510-(strlen(name)*2),55,name);
setcolor(GREEN);
settextstyle(1,0,5);
outtextxy(40,13,category);
drawhanger();
}
//FUNCTION GAME-MAIN FUNCTION WHERE FUNCTIONING OF GAME STARTS
void game()
{
strcat(category,".man");
fstream f1(category,ios::in|ios::nocreate|ios::binary);
randomize();
int num=(random(150))%99+1;
f1.seekg(num*sizeof(rec));
f1.read((char*)&rec,sizeof(rec));
strcpy(string,rec.returnword());
len=strlen(string);
setcolor(GREEN);
settextstyle(1,0,4);
for(i=0;string[i]!='\0';i++)
{ //DISPLAYING THE BLANK SPACES('_') FOR EACH CHARACTER
if((string[i]>=48 &&string[i]<=57) ||(string[i]>=65 &&string[i] <=90)
||
(string[i] >=97 &&string[i] <=122))
{
outtextxy(blankpos_x[i%16],blankpos_y[i/16]," _ ");
count_s++;
}
else
{ //DISPLAYING THE COMMA(',') FOR EACH SPACE
outtextxy(blankpos_x[i%16],blankpos_y[i/16]," , ");
spaces++;
}
}
setcolor(RED);
outtextxy(50,300,"\nPRESS ANY KEY TO PLAY");
getch();
setcolor(getbkcolor());
outtextxy(50,300,"\nPRESS ANY KEY TO PLAY");
setcolor(GREEN);
//ACCEPTING KEYSTROKE UNTILL THE CONDITION IS SATISFIED
while(count_s>=0 && count_f<=8) //INITIALLY count_s=len i.e.(LENGTH
of
word)
{ //and count_f is no. of wrong
guesses
if(bioskey(1))
{
key=bioskey(0);
int s=key>>8;
if(s==1)
{
getch();
exit(0);
}
else if(s==28)
continue;
else
matchkey(s);
}
if(gameflag!=1)
showtime();
setviewport(0,0,mx,my,1);
}
}
//FUN
//FUNCTION TO INITIALISE GRAPHICS
void initgraphics()
{
d=DETECT;
initgraph(&d,&m,"..//bgi");
mx=getmaxx();
my=getmaxy();
}
void play()
{
init();
chooseoption();
drawsetup();
game();
}
//FUNCTION TO INPUT NAME OF TEH USER
void getuser()
{
cleardevice();
cout<<"\n\nEnter your Name:";
gets(name);
if(strlen(name)<1)
strcpy(name,"USER");
}
//WELCOMING THE USER
void welcomeuser()
{
cleardevice();
setcolor(GREEN);
border();
settextjustify(CENTER_TEXT,CENTER_TEXT);
settextstyle(3,0,8);
outtextxy(mx/2,150,"WELCOME");
setcolor(WHITE);
settextstyle(1,0,7);
outtextxy(mx/2,my/2,name);
setcolor(RED);
settextstyle(5,0,5);
outtextxy(mx/2,380,"\nPRESS ANY KEY TO PLAY");
settextstyle(5,0,5);
outtextxy(mx/2-1,380,"\nPRESS ANY KEY TO PLAY");
settextstyle(5,0,5);
outtextxy(mx/2+1,380,"\nPRESS ANY KEY TO PLAY");
settextjustify(LEFT_TEXT,TOP_TEXT);
getch();
show_main_menu();
cleardevice();
}
//MAIN FUNCTION- THE PROGRAM STARTS HERE
void main()
{
init();
FIRSTSCREEN();
getuser();
welcomeuser();
}
//A HANGMAN Game Program Dated: 14 NOV 2005
/*
Developed By: Manish Jain 1103143 3rd yr M.M.E.C. Mulana
mkj_manishjain@yahoo.co.in
+91 9896455735
*/
//HEADER FILES
#include fstream.h
#include bios.h
#include time.h
#include dos.h
#include stdio.h
#include string.h
#include stdlib.h
#include graphics.h
#include conio.h
#include mouse.h
#define SMILE 1
#define SAD 0
//VARIABLES AND FUNCTIONS DECLARATION
unsigned key;
char firstrow[]={'Q','W','E','R','T','Y','U','I','O','P'};
char secondrow[]={'A','S','D','F','G','H','J','K','L'};
char thirdrow[]={'Z','X','C','V','B','N','M'};
char *main_menu[]={{"1. PLAY"},{"2. INSTRUCTIONS"},{"3. HI-SCORE"},{"4.
EXIT"}};
char *categories[]={{"1. MOVIES"},{"2. SPORTS"},{"3. MOVIE STARS"},{"4.
PLACES"}};
char *m_m[]={"P","I","H","E"},*c_m[]={"M","S","A","P"};
int
blankpos_x[]={25,50,75,100,125,150,175,200,225,250,275,300,325,350,375,400
};
int blankpos_y[]={80,150,300,340},cat_pos_x[]={130,130,314,130};
char string[50],name[25],category[20],checklist[50],hitlist[50];
char wr_guesses[10],ch,datebuf[9],timebuf[9];
int
button,x,y,corx,cory,len=0,d,m,mx,my,i,j,k,count_s=0,count_f=0,hcount=0,fl
ag=0,hlflag=1,spaces=0;
int hlcount=0,prflag=0,hngmnflag=0,dispflag=0,gameflag=0;
int tcolor=GREEN,acolor=RED;
void drawsetup();
void game();
void play();
void initgraphics();
void show_main_menu();
void getoption();
//FUNCTION TO INITIALISE ALL THE VARIABLES
void init()
{
hlcount=0,prflag=0,hngmnflag=0,dispflag=0,gameflag=0;
tcolor=GREEN,acolor=RED;
len=0,count_s=0,count_f=0,hcount=0,flag=0,hlflag=1,spaces=0;
strcpy(hitlist,"");
strcpy(checklist,"");
strcpy(wr_guesses,"");
}
//CLASS RECORD TO READ RECORD FROM THE FILES
class record
{
char word[50];
public:
void input()
{
gets(word);
}
void output()
{
puts(word);
}
char *returnword()
{
return word;
}
}rec,out;
//BORDER FUNCTIONS TO BORDER EACH PAGE
void border()
{
setcolor(GREEN);
rectangle(2,2,mx-2,my-2);
setcolor(RED);
rectangle(4,4,mx-4,my-4);
setcolor(GREEN);
rectangle(6,6,mx-6,my-6);
settextstyle(4,0,5);
outtextxy(180,40,"HANGMAN");
setcolor(YELLOW);
line(175,88,420,88);
setcolor(RED);
line(175,90,420,90);
}
//FUNCTION TO DISPLAY THE VERY FIRST SCREEN OF THE PROGRAM
void FIRSTSCREEN()
{
clrscr();
initgraphics();
border();
settextstyle(3,0,3);
setcolor(RED);
outtextxy(130,200,"Programmed By:");
settextstyle(1,0,3);
setcolor(WHITE);
outtextxy(330,200,"Manish Jain");
outtextxy(150,235,"mkj_manishjain@yahoo.co.in");
outtextxy(150,275," +91 9896455735");
settextstyle(1,0,4);
setcolor(RED);
outtextxy(120,360,"Press any key to play");
getch();
}
//FUNCTION TO SHOW INSTRUCTIONS FOR THE USERS
void instruction()
{
cleardevice();
border();
setcolor(RED);
settextstyle(1,0,5);
outtextxy(50,140,"I N S T R U C T I O N S");
settextstyle(3,0,3);
setcolor(WHITE);
outtextxy(60,190,"1. Fill the Blanks with the suitable word.");
outtextxy(60,230,"2. The word should belong to the category");
outtextxy(60,270," selected by you.");
outtextxy(60,300,"3. You will be given 8 chances to fill it up.");
outtextxy(60,330,"4. Man on the Hanger describes your attempts ");
outtextxy(60,365,"5. Your wrong guesses are shown there.");
settextstyle(4,0,4);
setcolor(RED);
outtextxy(140,425,"Press any key to Continue");
getch();
show_main_menu();
}
//FUNCTION TO CHOOSE ONE FROM THE OPTIONS GIVEN USING MOUSE
void chooseoption()
{
cleardevice();
border();
settextstyle(1,0,5);
setcolor(GREEN);
outtextxy(50,140,"C A T E G O R I E S");
settextstyle(3,0,5);
for(i=0;i<4;i++)
{
setcolor(WHITE);
outtextxy(67,190+(45*i),categories[i]);
setcolor(RED);
rectangle(50,210+(45*i),60,220+(45*i));
outtextxy(cat_pos_x[i],190+(45*i),c_m[i]);
}
getoption();
}
//FUNCTION TO CHECK THE CATEGORY SELECTED BY THE USER
int getcategory(int x,int y)
{
//Check for category "Movies"
if((x>=10&&x<=80)&&(y>=200 &&y<=240))
{
strcpy(category,"Movies");
return 1;
}
//Check for Category "Sports"
if((x>=10&&x<=80)&&(y>=255 &&y<=280))
{
strcpy(category,"Sports");
return 1;
}
//Check for Category "Actors"
if((x>=10&&x<=80)&&(y>=285 &&y<=310))
{
strcpy(category,"Actors");
return 1;
}
//Check for Category "Places"
if((x>=10&&x<=80)&&(y>=315 &&y<=350))
{
strcpy(category,"Places");
return 1;
}
return 0;
}
//FUNCTION TO GET OPTION FROM THE USER USING MOUSE OR KEYBOARD
void getoption()
{
showmouseptr();
restrictmouseptr(10,200,80,400);
while(1)
{
getmousepos(&button,&x,&y);
if((button&1)==1)
{ corx=x;
cory=y;
if(getcategory(corx,cory)==1)
break;
}
int cho=bioskey(0);
cho=cho>>8;
switch(cho)
{
case 2:
case 50:
case 28:
case 79: strcpy(category,"Movies");
return;
case 3:
case 31:
case 80: strcpy(category,"Sports");
return;
case 4:
case 30:
case 81: strcpy(category,"Actors");
return;
case 5:
case 25:
case 75: strcpy(category,"Places");
return;
default: break;
}
}
}
//FUNCTION TO SHOWFACE (SMILING OR SAD)
void showface(int expr)
{
setcolor(RED);
circle(390,50,25);
setcolor(WHITE);
ellipse(378,45,0,360,3,4);
ellipse(402,45,0,360,3,4);
if(expr==SMILE)
arc(390,55,235,305,13);
else
arc(390,80,55,120,13);
}
//PRINTING HIGH SCORE WITH THE NAMES OF THE SCORERS
void hiscore()
{
cleardevice();
border();
setcolor(RED);
settextstyle(1,0,5);
outtextxy(50,140," H I S C O R E");
settextstyle(3,0,3);
setcolor(WHITE);
outtextxy(60,220,"Sorry! This feature is not available in this version
");
outtextxy(60,270,"For further details, Contact : ");
setcolor(GREEN);
outtextxy(60,310," mkj_manishjain@yahoo.co.in");
outtextxy(60,345," Mobile no.: +91 9896455735 ");
settextstyle(4,0,4);
setcolor(RED);
outtextxy(140,425,"Press any key to Continue");
getch();
show_main_menu();
}
//GETTING THE CHOICE FROM THE USER FOR THE MAIN MENU
void get_mm_choice()
{
get:
int cho=bioskey(0);
cho=cho>>8;
switch(cho)
{
case 2:
case 25:
case 28:
case 79: play();
break;
case 3:
case 23:
case 80: instruction();
break;
case 4:
case 35:
case 81: hiscore();
break;
case 5:
case 18:
case 75: exit(0);
break;
default: goto get;
}
}
//MAIN MENU OF THE PROGRAM
void show_main_menu()
{
cleardevice();
border();
settextstyle(1,0,5);
setcolor(GREEN);
outtextxy(60,130,"M A I N M E N U");
settextstyle(3,0,5);
for(i=0;i<4;i++)
{
setcolor(WHITE);
outtextxy(67,180+(35*i),main_menu[i]);
setcolor(RED);
outtextxy(130,180+(35*i),m_m[i]);
}
get_mm_choice();
}
//DISPLAY THE CHARACTER AT ITS APPROPRIATE POSITION WITH DESIRED COLOR
void display(char ch,int pos,int color)
{
char c[2];
c[0]=ch;
c[1]='\0';
setcolor(color);
outtextxy(blankpos_x[pos%16]+15,blankpos_y[pos/16],c);
}
//DRAWING THE MAN ON THE HANGER PARTS BY PARTS AS PER CORRECTNESS OF
GUESSES
void drawhangman(int count_f)
{
setcolor(RED);
if(hngmnflag==1)
{
switch(count_f)
{
case 1: circle(500,150,10);
hngmnflag=0;
break;
case 2: line(500,160,500,170);
hngmnflag=0;
break;
case 3: ellipse(500,192,0,360,15,20);
hngmnflag=0;
break;
case 4: line(500,213,490,218);
hngmnflag=0;
break;
case 5: line(500,213,510,218);
hngmnflag=0;
break;
case 6: line(500,170,480,180);
hngmnflag=0;
break;
case 7: line(500,170,520,180);
hngmnflag=0;
break;
case 8: setcolor(acolor);
outtextxy(100,340,"MERCY CHANCE");
delay(1000);
setcolor(getbkcolor());
outtextxy(100,340,"MERCY CHANCE");
hngmnflag=0;
break;
}
}
}
//ASKING USER IF HE WISHES TO PLAY AGAIN
void asktocontinue()
{
setcolor(WHITE);
outtextxy(40,340,"Wish to Play again:(Y/N):");
get:
char ch=getch();
if(ch=='y'||ch=='Y')
{
outtextxy(440,340,"Y");
getch();
play();
}
else if(ch=='n'||ch=='N')
{
outtextxy(440,340,"N");
getch();
exit(0);
}
goto get;
}
//CHECK THE KEY PRESSED AND TAKE APPROPRIATE ACTION
void check(char ch)
{
flag=0;
hlflag=1;
prflag=0;
for(i=0;string[i]!='\0';i++) //CHECKING CHARACTER IN THE STRING
{
if(ch==string[i]) //If char is present in the string
{
prflag=1;
for(j=0;j
if(ch==hitlist[j]) //if char is present in the list of pressed
characters
{
hlflag=0;
break;
}
}
if(hlflag==1)
{ setcolor(tcolor);flag=1;display(ch,i,GREEN);count_s--; }
else break;
}
}
if(prflag==0) //If the character is not present in the string
{
for(j=0;checklist[j]!='\0';j++)
{
if(ch==checklist[j])
return;
}
checklist[count_f++]=ch;
wr_guesses[count_f-1]=ch;
display(ch,32+(count_f),RED);
hngmnflag=1;
}
else if(prflag==1 && flag==1) //If the character present is repeated
hitlist[hlcount++]=ch;
if(count_s==0) //GAME CLEARED
{
setcolor(acolor);
outtextxy(100,265,"\nGame Cleared");
gameflag=1;
//DRAWING A SMILING FACE TO SHOW GAME CLEARED
showface(SMILE);
asktocontinue();
}
else if(count_f>8) //GAME OVER
{
setcolor(acolor);
outtextxy(100,265,"\nGame Over");
gameflag=1;
setcolor(RED);
for(i=0;string[i]!='\0';i++)
{
dispflag=0;
for(j=0;j
if(string[i]==hitlist[j])
{
dispflag=1;
break;
}
}
if(dispflag==0) //Display Remaining Characters
display(string[i],i,RED);
}
//DRAWING A SAD FACE TO SHOW GAME OVER
showface(SAD);
asktocontinue();
getch();
exit(0);
}
drawhangman(count_f);
}
void matchkey(int s) //GENERATING THE ASCII OF THE KEY PRESSED
{
if(s>=16 && s<=25)
ch=firstrow[s-16];
else if(s>=30 && s<=38)
ch=secondrow[s-30];
else if(s>=44 && s<=50)
ch=thirdrow[s-44];
else if(s>=2 && s<=10)
ch=(char)(47+s);
else if(s==11)
ch=(char)48;
check(ch);
}
//SHOW DATE AND TIME
void showtime()
{
_strtime(timebuf);
setcolor(GREEN);
settextstyle(1,0,3);
setviewport(340,18,460,60,1);
outtextxy(10,2,timebuf);
delay(50);
clearviewport();
settextstyle(1,0,4);
}
//DRAW THE HANGER FOR MAN TO BE HANGED
void drawhanger()
{
setcolor(WHITE);
line(500,125,500,140);
line(500,125,525,125);
line(525,125,525,220);
}
//DRAW THE SETUP FOR THE GAME
void drawsetup()
{
hidemouseptr();
cleardevice();
setcolor(BLUE);
rectangle(8,8,mx-8,my-8);
setcolor(RED);
rectangle(9,9,mx-9,my-9);
line(10,381,mx-10,381);
line(10,341,468,341);
line(10,301,468,301);
line(10,65,330,65);
setcolor(GREEN);
rectangle(10,10,mx-10,my-10);
line(10,380,mx-10,380);
line(10,340,468,340);
line(10,300,468,300);
line(10,66,330,66);
bar(468,10,472,380);
bar(188,10,192,66);
bar(328,10,332,66);
settextstyle(1,0,3);
_strdate(datebuf);
outtextxy(220,10,"DATE");
outtextxy(200,30,datebuf);
settextstyle(8,0,7);
outtextxy(50,360,"H A N G M A N");
setcolor(YELLOW);
outtextxy(48,360,"H A N G M A N");
setcolor(WHITE);
outtextxy(46,360,"H A N G M A N");
settextstyle(2,0,4);
outtextxy(46,446,"c"); //COPYRIGHT SYMBOL
circle(48,453,4);
settextstyle(3,0,3);
outtextxy(56,435," Fantasatic Four (P) Ltd. 2003-07");
settextstyle(3,0,4);
setcolor(BLUE);
outtextxy(500,18,"Player");
settextstyle(3,0,2);
setcolor(WHITE);
outtextxy(510-(strlen(name)*2),55,name);
setcolor(GREEN);
settextstyle(1,0,5);
outtextxy(40,13,category);
drawhanger();
}
//FUNCTION GAME-MAIN FUNCTION WHERE FUNCTIONING OF GAME STARTS
void game()
{
strcat(category,".man");
fstream f1(category,ios::in|ios::nocreate|ios::binary);
randomize();
int num=(random(150))%99+1;
f1.seekg(num*sizeof(rec));
f1.read((char*)&rec,sizeof(rec));
strcpy(string,rec.returnword());
len=strlen(string);
setcolor(GREEN);
settextstyle(1,0,4);
for(i=0;string[i]!='\0';i++)
{ //DISPLAYING THE BLANK SPACES('_') FOR EACH CHARACTER
if((string[i]>=48 &&string[i]<=57) ||(string[i]>=65 &&string[i] <=90)
||
(string[i] >=97 &&string[i] <=122))
{
outtextxy(blankpos_x[i%16],blankpos_y[i/16]," _ ");
count_s++;
}
else
{ //DISPLAYING THE COMMA(',') FOR EACH SPACE
outtextxy(blankpos_x[i%16],blankpos_y[i/16]," , ");
spaces++;
}
}
setcolor(RED);
outtextxy(50,300,"\nPRESS ANY KEY TO PLAY");
getch();
setcolor(getbkcolor());
outtextxy(50,300,"\nPRESS ANY KEY TO PLAY");
setcolor(GREEN);
//ACCEPTING KEYSTROKE UNTILL THE CONDITION IS SATISFIED
while(count_s>=0 && count_f<=8) //INITIALLY count_s=len i.e.(LENGTH
of
word)
{ //and count_f is no. of wrong
guesses
if(bioskey(1))
{
key=bioskey(0);
int s=key>>8;
if(s==1)
{
getch();
exit(0);
}
else if(s==28)
continue;
else
matchkey(s);
}
if(gameflag!=1)
showtime();
setviewport(0,0,mx,my,1);
}
}
//FUN
//FUNCTION TO INITIALISE GRAPHICS
void initgraphics()
{
d=DETECT;
initgraph(&d,&m,"..//bgi");
mx=getmaxx();
my=getmaxy();
}
void play()
{
init();
chooseoption();
drawsetup();
game();
}
//FUNCTION TO INPUT NAME OF TEH USER
void getuser()
{
cleardevice();
cout<<"\n\nEnter your Name:";
gets(name);
if(strlen(name)<1)
strcpy(name,"USER");
}
//WELCOMING THE USER
void welcomeuser()
{
cleardevice();
setcolor(GREEN);
border();
settextjustify(CENTER_TEXT,CENTER_TEXT);
settextstyle(3,0,8);
outtextxy(mx/2,150,"WELCOME");
setcolor(WHITE);
settextstyle(1,0,7);
outtextxy(mx/2,my/2,name);
setcolor(RED);
settextstyle(5,0,5);
outtextxy(mx/2,380,"\nPRESS ANY KEY TO PLAY");
settextstyle(5,0,5);
outtextxy(mx/2-1,380,"\nPRESS ANY KEY TO PLAY");
settextstyle(5,0,5);
outtextxy(mx/2+1,380,"\nPRESS ANY KEY TO PLAY");
settextjustify(LEFT_TEXT,TOP_TEXT);
getch();
show_main_menu();
cleardevice();
}
//MAIN FUNCTION- THE PROGRAM STARTS HERE
void main()
{
init();
FIRSTSCREEN();
getuser();
welcomeuser();
}
Rock Paper Scissor Game
Rock Paper Scissor Game.......
#include iostream.h
#include conio.h
#include graphics.h
#include dos.h
#include stdlib.h
int gd=DETECT,gm;
void scissor()
{
setcolor(15);
rectangle(75,100,250,350);
setcolor(14);
circle(125,135,20);
circle(200,135,20);
line(125,155,195,300);
line(200,155,120,300);
}
void s()
{
setcolor(15);
rectangle(375,100,550,350);
setcolor(14);
circle(425,135,20);
circle(500,135,20);
line(425,155,495,300);
line(500,155,420,300);
}
void paper()
{
setcolor(15);
rectangle(75,100,250,350);
setcolor(14);
rectangle(85,125,190,275);
}
void p()
{
setcolor(15);
rectangle(375,100,550,350);
setcolor(14);
rectangle(385,125,490,275);
}
void stone()
{
setcolor(15);
rectangle(75,100,250,350);
setcolor(14);
int poly[14]={100,150,125,140,200,175,225,275,180,285,140,270,100,150};
drawpoly(7,poly);
}
void t()
{
setcolor(15);
rectangle(375,100,550,350);
setcolor(14);
int poly[14]={400,150,425,140,500,175,525,275,480,285,440,270,400,150};
drawpoly(7,poly);
}
int generate(int a)
{
int x=a%10;
int y=a/10;
if(x%2==0 && y%2==0)
return 1;
else if(x%2==0 && y%2!=0)
return 2;
else
return 3;
}
int check(int x,int y)
{
int ans;
switch(x)
{
case 49:switch(y)
{
case 1: ans = 0;
break;
case 2: ans = 1;
break;
case 3: ans = 2;
break;
}
break;
case 50:switch(y)
{
case 1: ans = 2;
break;
case 2: ans = 0;
break;
case 3: ans = 1;
break;
}
break;
case 51:switch(y)
{
case 1: ans = 1;
break;
case 2: ans = 2;
break;
case 3: ans = 0;
break;
}
break;
}
return ans;
}
void main()
{
initgraph(&gd,&gm,"C:/TC/bgi");
lable: cleardevice();
int ch,code,round=1,status,p_score=0,c_score=0;
setlinestyle(0,0,3);
while(round<=10)
{
clrscr();
cleardevice();
setfillstyle(1,0);
floodfill(80,110,15);
cout<<"Round no. :"<< round <<"\nYour socre :"<< p_score <<"\nCom.'s score:"< setcolor(14);
settextstyle(1,0,2);
outtextxy(275,80,"Play");
outtextxy(80,90,"YOU");
outtextxy(400,90,"COM");
outtextxy(20,450,"Press 1 for scissor, 2 for Paper, 3 for Stone, Esc to quit..");
ch=getch();
if(ch==49)
scissor();
else if(ch==50)
paper();
else if(ch==51)
stone();
else if(ch==27)
break;
else
continue;
delay(200);
randomize();
int a=random(99);
code=generate(a);
if(code==1)
s();
else if(code==2)
p();
else
t();
status=check(ch,code);
delay(300);
setcolor(5);
if(status==0)
outtextxy(275,400,"Tie");
else if(status==1)
{p_score+=10;
outtextxy(275,400,"You win");
}
else
{c_score+=10;
outtextxy(275,400,"You lose");
}
getch();
round++;
}
cleardevice();
setcolor(2);
settextstyle(4,0,5);
if(p_score>c_score)
outtextxy(250,250,"You Won!!");
else if(p_score outtextxy(250,250,"You Lose!!");
else
outtextxy(250,250,"TIE !!");
cout<<"\nPress P to play again..";
char p;
p=getch();
if(p=='p' || p=='P')
goto lable;
cout<<"\nBye Bye..";
getch();
}
#include iostream.h
#include conio.h
#include graphics.h
#include dos.h
#include stdlib.h
int gd=DETECT,gm;
void scissor()
{
setcolor(15);
rectangle(75,100,250,350);
setcolor(14);
circle(125,135,20);
circle(200,135,20);
line(125,155,195,300);
line(200,155,120,300);
}
void s()
{
setcolor(15);
rectangle(375,100,550,350);
setcolor(14);
circle(425,135,20);
circle(500,135,20);
line(425,155,495,300);
line(500,155,420,300);
}
void paper()
{
setcolor(15);
rectangle(75,100,250,350);
setcolor(14);
rectangle(85,125,190,275);
}
void p()
{
setcolor(15);
rectangle(375,100,550,350);
setcolor(14);
rectangle(385,125,490,275);
}
void stone()
{
setcolor(15);
rectangle(75,100,250,350);
setcolor(14);
int poly[14]={100,150,125,140,200,175,225,275,180,285,140,270,100,150};
drawpoly(7,poly);
}
void t()
{
setcolor(15);
rectangle(375,100,550,350);
setcolor(14);
int poly[14]={400,150,425,140,500,175,525,275,480,285,440,270,400,150};
drawpoly(7,poly);
}
int generate(int a)
{
int x=a%10;
int y=a/10;
if(x%2==0 && y%2==0)
return 1;
else if(x%2==0 && y%2!=0)
return 2;
else
return 3;
}
int check(int x,int y)
{
int ans;
switch(x)
{
case 49:switch(y)
{
case 1: ans = 0;
break;
case 2: ans = 1;
break;
case 3: ans = 2;
break;
}
break;
case 50:switch(y)
{
case 1: ans = 2;
break;
case 2: ans = 0;
break;
case 3: ans = 1;
break;
}
break;
case 51:switch(y)
{
case 1: ans = 1;
break;
case 2: ans = 2;
break;
case 3: ans = 0;
break;
}
break;
}
return ans;
}
void main()
{
initgraph(&gd,&gm,"C:/TC/bgi");
lable: cleardevice();
int ch,code,round=1,status,p_score=0,c_score=0;
setlinestyle(0,0,3);
while(round<=10)
{
clrscr();
cleardevice();
setfillstyle(1,0);
floodfill(80,110,15);
cout<<"Round no. :"<< round <<"\nYour socre :"<< p_score <<"\nCom.'s score:"<
settextstyle(1,0,2);
outtextxy(275,80,"Play");
outtextxy(80,90,"YOU");
outtextxy(400,90,"COM");
outtextxy(20,450,"Press 1 for scissor, 2 for Paper, 3 for Stone, Esc to quit..");
ch=getch();
if(ch==49)
scissor();
else if(ch==50)
paper();
else if(ch==51)
stone();
else if(ch==27)
break;
else
continue;
delay(200);
randomize();
int a=random(99);
code=generate(a);
if(code==1)
s();
else if(code==2)
p();
else
t();
status=check(ch,code);
delay(300);
setcolor(5);
if(status==0)
outtextxy(275,400,"Tie");
else if(status==1)
{p_score+=10;
outtextxy(275,400,"You win");
}
else
{c_score+=10;
outtextxy(275,400,"You lose");
}
getch();
round++;
}
cleardevice();
setcolor(2);
settextstyle(4,0,5);
if(p_score>c_score)
outtextxy(250,250,"You Won!!");
else if(p_score
else
outtextxy(250,250,"TIE !!");
cout<<"\nPress P to play again..";
char p;
p=getch();
if(p=='p' || p=='P')
goto lable;
cout<<"\nBye Bye..";
getch();
}
Maze
A Maze solving game in Computer Graphics....
#include stdio.h
#include graphics.h
#include conio.h
#include dos.h
int c=360,a,b;
int set=5;
void maze();
void display();
void win();
void clos();
void main()
{
int a[2]={0};
int y=410,x=605;
int ch,i;
// int x=290,y=210;
initgraph(a,a+1,"c:\\tc\\bgi");
// display();
maze();
while(ch!=27)
{
while(!kbhit())
{
setcolor(4);
switch(ch)
{
case 75:
x=x-1;
circle(x,y,5);
setcolor(set);
for(i=0;i<5;i++)
circle(x,y,i);
break;
case 77:
x=x+1;
circle(x,y,5);
setcolor(set);
for(i=0;i<5;i++)
circle(x,y,i);
break;
case 72:
y=y-1;
circle(x,y,5);
setcolor(set);
for(i=0;i<5;i++)
circle(x,y,i);
break;
case 80:
y=y+1;
circle(x,y,5);
setcolor(set);
for(i=0;i<5;i++)
circle(x,y,i);
break;
}
setcolor(4);
circle(290,240,10);
setcolor(set);
for(i=0;i<10;i++)
circle(290,240,i);
set++;
if(set==15)
set=5;
if(getpixel(x+6,y)==3||getpixel(x-6,y)==3||getpixel(x,y+6)==3||getpixel(x,y-6)==3)
{
clos();
exit(1);
}
if(getpixel(x+6,y)==2||getpixel(x-6,y)==2||getpixel(x,y+6)==2||getpixel(x,y-6)==2)
{
clos();
exit(1);
}
if(x<295 && x>285 && y<245 && y>235)
win();
delay(25);
setcolor(0);
circle(x,y,5);
}
ch=getch();
}
getch();
}
//---------------------------------------------------------------------------//
void maze()
{
setcolor(GREEN);
line(20,20,20,420);
line(20,20,620,20);
line(620,20,620,400);
line(20,420,620,420);
setcolor(CYAN);
//--------------------------vertical----------------------------//
line(50,20,50,60);line(50,80,50,140);line(50,160,50,240);line(50,280,50,340);
line(80,40,80,80);line(80,100,80,120);line(80,180,80,200);line(80,220,80,240);line(80,260,80,380);
line(110,60,110,80);line(110,200,110,220);line(110,240,110,260);line(110,280,110,340);
line(140,80,140,100);line(140,180,140,240);line(140,300,140,320);
line(170,60,170,100);line(170,160,170,240);line(170,340,170,360);line(170,380,170,400);
line(200,40,200,80);line(200,200,200,240);
line(230,20,230,40);line(230,80,230,100);line(230,140,230,180);line(230,220,230,260);line(230,320,230,340);
line(260,40,260,60);line(260,100,260,120);line(260,220,260,280);line(260,340,260,360);line(260,380,260,400);
line(290,360,290,380);line(290,400,290,420);
line(320,60,320,80); line(320,160,320,180);line(320,220,320,240);line(320,340,320,400);
line(350,80,350,140);line(350,200,350,260);line(350,320,350,340);line(350,360,350,420);
line(380,40,380,80); line(380,100,380,140);line(380,180,380,280);line(380,340,380,400);
line(410,20,410,40);line(410,100,410,300);
line(440,100,440,120); line(440,140,440,180);line(440,240,440,320);line(440,380,440,400);
line(470,160,470,200);line(470,240,470,280);line(470,300,470,320);line(470,360,470,380);
line(500,140,500,180);line(500,200,500,220);line(500,300,500,360);
line(530,40,530,80);line(530,100,530,260);line(530,300,530,320);line(530,340,530,380);
line(560,20,560,40);line(560,80,560,240);line(560,280,560,320);line(560,340,560,400);
line(590,40,590,220); line(590,240,590,340);line(590,360,590,400);
//--------------------------------horizontal----------------------//
line(80,40,200,40);line(260,40,380,40);line(410,40,530,40);
line(110,60,170,60);line(200,60,290,60);line(320,60,350,60);line(380,60,500,60);line(560,60,590,60);
line(50,80,110,80);line(230,80,320,80);line(380,80,560,80);
line(80,100,140,100);line(170,100,230,100);line(260,100,350,100);line(470,100,530,100);
line(80,120,260,120);line(290,120,350,120);line(440,120,530,120);
line(50,140,320,140);line(350,140,380,140);line(440,140,500,140);
line(50,160,200,160);line(260,160,320,160);line(350,160,410,160);
line(80,180,140,180);line(170,180,380,180);line(410,180,440,180);line(500,180,530,180);
line(80,200,110,200);line(200,200,350,200);line(440,200,500,200);
line(230,220,320,220);line(410,220,500,220);line(590,220,620,220);
line(50,240,80,240);line(110,240,140,240);line(440,240,530,240);line(560,240,590,240);
line(50,260,110,260);line(140,260,230,260);line(260,260,350,260);line(500,260,560,260);
line(110,280,380,280);line(470,280,560,280);
line(140,300,410,300);line(470,300,500,300);
line(140,320,320,320);line(350,320,440,320);line(530,320,560,320);
line(50,340,80,340);line(170,340,230,340);line(260,340,320,340);line(380,340,410,340);line(440,340,500,340);line(530,340,590,340);
line(20,360,50,360);line(110,360,260,360);line(380,360,500,360);
line(50,380,170,380);line(200,380,290,380);line(410,380,440,380);line(470,380,530,380);
line(20,400,140,400);line(170,400,260,400);line(290,400,320,400);line(380,400,410,400);line(440,400,560,400);line(590,400,620,400);
setcolor(4);
circle(290,240,10);
settextstyle(4,HORIZ_DIR,5);
outtextxy(280,420,"Maze...");
}
void display()
{
b=410;
while(b>-20)
{
settextstyle(1,0,6);
setcolor(8);
outtextxy(0,b," ");
delay(5);
setcolor(2);
outtextxy(0,b,"_ .");
b--;
}
b=-30;
while(b<620)
{
settextstyle(1,0,6);
setcolor(8);
outtextxy(b,0," ");
delay(5);
setcolor(2);
outtextxy(b,0,"!");
b++;
}
b=-20;
while(b<400)
{
settextstyle(1,0,6);
setcolor(8);
outtextxy(600,b," ");
delay(5);
setcolor(2);
outtextxy(600,b,"._");
b++;
}
b=620;
while(b>0)
{
settextstyle(1,0,6);
setcolor(8);
outtextxy(b,400,"");
setcolor(2);
delay(5);
outtextxy(b,400,"i");
b--;
}
settextstyle(7,1,4);
setcolor(4);
outtextxy(15,50,"Project By AAKASH");
while(c>290)
{ delay(50);
arc(250,240,30,320,c-200);
settextstyle(1,0,6);
c--;
}
delay(300);
settextstyle(1,0,4);
setcolor(4);
outtextxy(390,140,"Red Chilies");
delay(300);
outtextxy(370,330,"Entertainment ");
delay(300);
settextstyle(3,0,6);
setcolor(6);
outtextxy(170,200,"atch Me If U Can");
delay(100);
settextstyle(3,0,5);
setcolor(5);
delay(300);
outtextxy(25,443,"******************************");
settextstyle(2,0,18);
setcolor(5);
outtextxy(625,3,"*");
// while(c>0)
//{
//delay(50);
//arc(250,240,30,320,c-200);
//settextstyle(1,0,6);
//c--;
//}
}
void win()
{
cleardevice();
settextstyle(4,0,8);
outtextxy(getmaxx()/2-230,getmaxy()/2-100,"YOU WIN.....");
getch();
exit(1);
}
void clos()
{
cleardevice();
setcolor(4);
settextstyle(4,0,8);
outtextxy(getmaxx()/2-230,getmaxy()/2-230,"GAME OVER");
getch();
}
#include stdio.h
#include graphics.h
#include conio.h
#include dos.h
int c=360,a,b;
int set=5;
void maze();
void display();
void win();
void clos();
void main()
{
int a[2]={0};
int y=410,x=605;
int ch,i;
// int x=290,y=210;
initgraph(a,a+1,"c:\\tc\\bgi");
// display();
maze();
while(ch!=27)
{
while(!kbhit())
{
setcolor(4);
switch(ch)
{
case 75:
x=x-1;
circle(x,y,5);
setcolor(set);
for(i=0;i<5;i++)
circle(x,y,i);
break;
case 77:
x=x+1;
circle(x,y,5);
setcolor(set);
for(i=0;i<5;i++)
circle(x,y,i);
break;
case 72:
y=y-1;
circle(x,y,5);
setcolor(set);
for(i=0;i<5;i++)
circle(x,y,i);
break;
case 80:
y=y+1;
circle(x,y,5);
setcolor(set);
for(i=0;i<5;i++)
circle(x,y,i);
break;
}
setcolor(4);
circle(290,240,10);
setcolor(set);
for(i=0;i<10;i++)
circle(290,240,i);
set++;
if(set==15)
set=5;
if(getpixel(x+6,y)==3||getpixel(x-6,y)==3||getpixel(x,y+6)==3||getpixel(x,y-6)==3)
{
clos();
exit(1);
}
if(getpixel(x+6,y)==2||getpixel(x-6,y)==2||getpixel(x,y+6)==2||getpixel(x,y-6)==2)
{
clos();
exit(1);
}
if(x<295 && x>285 && y<245 && y>235)
win();
delay(25);
setcolor(0);
circle(x,y,5);
}
ch=getch();
}
getch();
}
//---------------------------------------------------------------------------//
void maze()
{
setcolor(GREEN);
line(20,20,20,420);
line(20,20,620,20);
line(620,20,620,400);
line(20,420,620,420);
setcolor(CYAN);
//--------------------------vertical----------------------------//
line(50,20,50,60);line(50,80,50,140);line(50,160,50,240);line(50,280,50,340);
line(80,40,80,80);line(80,100,80,120);line(80,180,80,200);line(80,220,80,240);line(80,260,80,380);
line(110,60,110,80);line(110,200,110,220);line(110,240,110,260);line(110,280,110,340);
line(140,80,140,100);line(140,180,140,240);line(140,300,140,320);
line(170,60,170,100);line(170,160,170,240);line(170,340,170,360);line(170,380,170,400);
line(200,40,200,80);line(200,200,200,240);
line(230,20,230,40);line(230,80,230,100);line(230,140,230,180);line(230,220,230,260);line(230,320,230,340);
line(260,40,260,60);line(260,100,260,120);line(260,220,260,280);line(260,340,260,360);line(260,380,260,400);
line(290,360,290,380);line(290,400,290,420);
line(320,60,320,80); line(320,160,320,180);line(320,220,320,240);line(320,340,320,400);
line(350,80,350,140);line(350,200,350,260);line(350,320,350,340);line(350,360,350,420);
line(380,40,380,80); line(380,100,380,140);line(380,180,380,280);line(380,340,380,400);
line(410,20,410,40);line(410,100,410,300);
line(440,100,440,120); line(440,140,440,180);line(440,240,440,320);line(440,380,440,400);
line(470,160,470,200);line(470,240,470,280);line(470,300,470,320);line(470,360,470,380);
line(500,140,500,180);line(500,200,500,220);line(500,300,500,360);
line(530,40,530,80);line(530,100,530,260);line(530,300,530,320);line(530,340,530,380);
line(560,20,560,40);line(560,80,560,240);line(560,280,560,320);line(560,340,560,400);
line(590,40,590,220); line(590,240,590,340);line(590,360,590,400);
//--------------------------------horizontal----------------------//
line(80,40,200,40);line(260,40,380,40);line(410,40,530,40);
line(110,60,170,60);line(200,60,290,60);line(320,60,350,60);line(380,60,500,60);line(560,60,590,60);
line(50,80,110,80);line(230,80,320,80);line(380,80,560,80);
line(80,100,140,100);line(170,100,230,100);line(260,100,350,100);line(470,100,530,100);
line(80,120,260,120);line(290,120,350,120);line(440,120,530,120);
line(50,140,320,140);line(350,140,380,140);line(440,140,500,140);
line(50,160,200,160);line(260,160,320,160);line(350,160,410,160);
line(80,180,140,180);line(170,180,380,180);line(410,180,440,180);line(500,180,530,180);
line(80,200,110,200);line(200,200,350,200);line(440,200,500,200);
line(230,220,320,220);line(410,220,500,220);line(590,220,620,220);
line(50,240,80,240);line(110,240,140,240);line(440,240,530,240);line(560,240,590,240);
line(50,260,110,260);line(140,260,230,260);line(260,260,350,260);line(500,260,560,260);
line(110,280,380,280);line(470,280,560,280);
line(140,300,410,300);line(470,300,500,300);
line(140,320,320,320);line(350,320,440,320);line(530,320,560,320);
line(50,340,80,340);line(170,340,230,340);line(260,340,320,340);line(380,340,410,340);line(440,340,500,340);line(530,340,590,340);
line(20,360,50,360);line(110,360,260,360);line(380,360,500,360);
line(50,380,170,380);line(200,380,290,380);line(410,380,440,380);line(470,380,530,380);
line(20,400,140,400);line(170,400,260,400);line(290,400,320,400);line(380,400,410,400);line(440,400,560,400);line(590,400,620,400);
setcolor(4);
circle(290,240,10);
settextstyle(4,HORIZ_DIR,5);
outtextxy(280,420,"Maze...");
}
void display()
{
b=410;
while(b>-20)
{
settextstyle(1,0,6);
setcolor(8);
outtextxy(0,b," ");
delay(5);
setcolor(2);
outtextxy(0,b,"_ .");
b--;
}
b=-30;
while(b<620)
{
settextstyle(1,0,6);
setcolor(8);
outtextxy(b,0," ");
delay(5);
setcolor(2);
outtextxy(b,0,"!");
b++;
}
b=-20;
while(b<400)
{
settextstyle(1,0,6);
setcolor(8);
outtextxy(600,b," ");
delay(5);
setcolor(2);
outtextxy(600,b,"._");
b++;
}
b=620;
while(b>0)
{
settextstyle(1,0,6);
setcolor(8);
outtextxy(b,400,"");
setcolor(2);
delay(5);
outtextxy(b,400,"i");
b--;
}
settextstyle(7,1,4);
setcolor(4);
outtextxy(15,50,"Project By AAKASH");
while(c>290)
{ delay(50);
arc(250,240,30,320,c-200);
settextstyle(1,0,6);
c--;
}
delay(300);
settextstyle(1,0,4);
setcolor(4);
outtextxy(390,140,"Red Chilies");
delay(300);
outtextxy(370,330,"Entertainment ");
delay(300);
settextstyle(3,0,6);
setcolor(6);
outtextxy(170,200,"atch Me If U Can");
delay(100);
settextstyle(3,0,5);
setcolor(5);
delay(300);
outtextxy(25,443,"******************************");
settextstyle(2,0,18);
setcolor(5);
outtextxy(625,3,"*");
// while(c>0)
//{
//delay(50);
//arc(250,240,30,320,c-200);
//settextstyle(1,0,6);
//c--;
//}
}
void win()
{
cleardevice();
settextstyle(4,0,8);
outtextxy(getmaxx()/2-230,getmaxy()/2-100,"YOU WIN.....");
getch();
exit(1);
}
void clos()
{
cleardevice();
setcolor(4);
settextstyle(4,0,8);
outtextxy(getmaxx()/2-230,getmaxy()/2-230,"GAME OVER");
getch();
}
Subscribe to:
Posts (Atom)