Professional Documents
Culture Documents
C++ Programs
C++ Programs
TOWER OF HANOI-2
DESIGN OF TAJMAHAL
-5
TELEPHONE DIRECTORY
15
ROTATION OF TRIANGLE
20
THREE BALL
CLAENDER
26
27
BOUNCING BALL 30
3D TRANSFORMATIOM
PARI MAN
30
35
MOVING 3D BOX 39
MICKEY MOUSE
GAME PACK
DX BALL
40
42
51
BLINKING LIGHTS 54
Brick Game 57
Brainvita - Game in C++ (Project) 68
Tower of Hanoi - A
Graphical Representation
initgraph(&gdriver, &gmode,
"d:\TC\BGI");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s
", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
width=50/x;
<graphics.h>
<stdlib.h>
<stdio.h>
<conio.h>
MAX12
BegPos 105
AuxPos 305
EndPos 505
beg.top=end.top=aux.top=0;
beg.pos=1;end.pos=3;aux.pos=2;
for(i=0;i<x;i++)
push(&beg,(x-i)+1);
int width;
typedef struct disc
{
char val1[MAX];
char top,pos;
};
draw_stack(&beg,&end,&aux);
tower(x,&beg,&end,&aux);
closegraph();
return 0;
}
void
tower(int
n,disc
*beg,disc
*aux,disc *end)
{
if(n>0)
/*
{
push(end,pop(beg));
draw_stack(beg,end,aux);
}
else*/
{
tower(n-1,beg,end,aux);
push(end,pop(beg));
draw_stack(beg,end,aux);
tower(n-1,aux,beg,end);
}
//
}
void push(disc *tt,int x)
{
tt->val1[tt->top]=x;
tt->top++;
rectangle(xpos-(end>val1[i]*width),ypos,xpos+(end>val1[i]*width),ypos-height);
ypos-=(height+2);
}
ver=end->pos;
}
pop(disc *tt)
{
int a;
tt->top--;
a=tt->val1[tt->top];
tt->val1[tt->top]=0;
return a;
}
/* BEG TOWER*/
if(beg->pos==1)
xpos=BegPos;
else if(beg->pos==2)
xpos=AuxPos;
else if(beg->pos==3)
xpos=EndPos;
void
draw_stack(disc
*beg,disc
*end,disc *aux)
{
int ypos=295,i,height=10,xpos;
int ver=0;
cleardevice();
ypos=295;
for(i=0;i<beg->top;i++)
{
setfillstyle(beg>val1[i],beg->val1[i]);
setfillstyle(1,2);
bar(20,300,580,310);
bar(xpos-(beg>val1[i]*width),ypos,xpos+(beg>val1[i]*width),ypos-height);
bar(100,100,110,300);
bar(300,100,310,300);
bar(500,100,510,300);
rectangle(xpos-(beg>val1[i]*width),ypos,xpos+(beg>val1[i]*width),ypos-height);
ypos-=(height+2);
}
rectangle(20,300,580,310);
rectangle(100,100,110,300);
rectangle(300,100,310,300);
rectangle(500,100,510,300);
/* AUX TOWER*/
ver=ver*10+beg->pos;
/* END TOWER*/
ypos=295;
if(end->pos==1)
xpos=BegPos;
else if(end->pos==2)
xpos=AuxPos;
else if(end->pos==3)
xpos=EndPos;
if(ver<20)
{
if(ver%10==2)
xpos=EndPos;
else
xpos=AuxPos;
}
else if(ver<30)
{
if(ver%10==1)
xpos=EndPos;
else
xpos=BegPos;
}
else if(ver<40)
{
for(i=0;i<end->top;i++)
{
setfillstyle(end>val1[i],end->val1[i]);
bar(xpos-(end>val1[i]*width),ypos,xpos+(end>val1[i]*width),ypos-height);
if(ver%10==1)
xpos=AuxPos;
else
xpos=BegPos;
tower====================
====//
//======================
===========IIst
tower====================
========//
//#################TOWER%
%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%//
int l=-20;
line(28+l,400+h,33+l,333+h);
line(86+l,400+h,80+l,333+h);
//||||||||||||||||||||||||||||||Ist
stage||||||||||||||||||||||||||||||||||||||||||||//
line(23+l,328+h,32+l,334+h);
// slant
line(88+l,328+h,80+l,334+h);
// slant
line(83+l,323+h,75+l,334+h);
// slant
line(75+l,323+h,70+l,332+h);
line(66+l,323+h,65+l,332+h);
// slant
line(57+l,323+h,57+l,332+h);
// slant
line(30+l,323+h,39+l,334+h);
// slant
line(38+l,323+h,45+l,332+h);
line(48+l,323+h,51+l,332+h);
//
slant
}
ypos=295;
for(i=0;i<aux->top;i++)
{
setfillstyle(aux>val1[i],aux->val1[i]);
bar(xpos-(aux>val1[i]*width),ypos,xpos+(aux>val1[i]*width),ypos-height);
rectangle(xpos-(aux>val1[i]*width),ypos,xpos+(aux>val1[i]*width),ypos-height);
ypos-=(height+2);
}
getch();
}
Design of Tajmahal In
Turbo C++ 3.0 graphics
#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<process.h>
ellipse(57+l,320+h,350,190,34,5);
ellipse(57+l,327+h,350,190,34,5);
ellipse(57+l,337+h,0,180,25,5);
line(22+l,320+h,22+l,328+h);
line(91+l,320+h,91+l,327+h);
setfillstyle(6,15);
floodfill(60+l,320+h,15);
main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\tc\bgi");
int h=40;
line(0,440,639,440);
setfillstyle(10,15);
floodfill(60+l,320+h+15,15);
//line(20,30+h,619,30+h);
//line(25,400,38,120);
//line(85,400,78,120);
//line(85,400,78,120);
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||
||||||||||||||||
||//
//++++++++++++++++++++++
+++++++++++++2nd++++++++
+++++++++++++++++++
//======================
===========Ist
5
line(35+l,315+h,38+l,242+h);
line(80+l,315+h,75+l,242+h);
t=-182;
line(32+l,328+t+4+h,32+7+l,334+t+
h);
// slant
line(80+l,328+t+4+h,73+l,334+t+h);
// slant
//line(+l83,323+t+4,75,334+t);
// slant
line(76+l,323+t+5+h,71+l,332+t+h);
line(66+l,323+t+4+h,65+l,332+t+h);
// slant
line(57+l,323+t+4+h,57+l,332+t2+h);
// slant
//line(30,323+t+2,39,334+t);
// slant
line(39+l,323+t+6+h,45+l,332+t+1+
h);
line(48+l,323+t+4+h,51+l,332+t+h);
// slant
//||||||||||||||||||||||||||||||2st
stage||||||||||||||||||||||||||||||||||||||||||||//
int t=-93;
line(23+4+l,328+t+3+h,32+5+l,334
+t+h);
// slant
line(88+l,328+t+2+h,76+l,334+t+h);
// slant
//line(+l83,323+t+4,75,334+t);
// slant
line(78+l,323+t+3+h,71+l,332+t+h);
line(66+l,323+t+2+h,65+l,332+t+h);
// slant
line(57+l,323+t+2+h,57+l,332+t2+h);
// slant
//line(30,323+t+2,39,334+t);
// slant
line(35+l,323+t+3+h,453+l,332+t+h);
line(48+l,323+t+2+h,51+l,332+t2+h);
// slant
ellipse(57+l,320+t+6+h,360,190,24,5
);
ellipse(57+l,327+t+4+h,360,190,24,5
);
ellipse(57+l,337+t-1+h,0,170,16,5);
ellipse(57+l,320+t+3+h,360,190,30,5
);
ellipse(57+l,327+t+3+h,360,190,30,5
);
ellipse(57+l,337+t-1+h,0,180,18,5);
line(32+l,320+t+6+h,32+l,328+t+3+
h);
line(81+l,320+t+6+h,81+l,327+t+3+
h);
line(26+l,320+t+3+h,26+l,328+t+2+
h);
line(88+l,320+t+3+h,88+l,327+t+3+
h);
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||
||||||||||||||||
|//
setfillstyle(6,15);
floodfill(60+l,320+h+t,15);
////////////////
setfillstyle(10,15);
floodfill(60+l,320+h-35,15);
setfillstyle(6,15);
floodfill(60+l,322+h+t,15);
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||
||||||||||||||||
||//
setfillstyle(10,15);
floodfill(60+l,322+h+t+30,15);
//GGF################TOWE
R%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%//
ellipse(51+l,132+h,340,216,4,15);
ellipse(62+l,131+h,327,216,4,15);
ellipse(72+l,132+h,327,216,2,15);
ellipse(42+l,132+h,327,216,2,15);
ellipse(57+l,107+h,0,170,16,5);
line(40+l,107+h,40+l,140+h);
line(75+l,107+h,75+l,140+h);
//||||||||||||||||||||||||||||||3rd
stage||||||||||||||||||||||||||||||||||||||||||||//
line(38+l,225+h,41+l,152+h);
line(75+l,225+h,72+l,152+h);
line(88+l,328+h,80+l,334+h);
// slant
line(83+l,323+h,75+l,334+h);
// slant
line(75+l,323+h,70+l,332+h);
line(66+l,323+h,65+l,332+h);
// slant
line(57+l,323+h,57+l,332+h);
// slant
line(30+l,323+h,39+l,334+h);
// slant
line(38+l,323+h,45+l,332+h);
line(48+l,323+h,51+l,332+h);
slant
line(34+l,107+h,40+l,107+h);
line(75+l,107+h,81+l,107+h);
line(34+l,107+h,28+l,102+h);
//slant
line(81+l,107+h,87+l,102+h);
line(28+l,102+h,34+l,98+h);
line(87+l,102+h,81+l,98+h);
line(34+l,98+h,58+l,95+h);
line(58+l,95+h,81+l,98+h);
ellipse(65+l,92+h,104,190,30,30);
//
ellipse(57+l,320+h,350,190,34,5);
ellipse(57+l,327+h,350,190,34,5);
ellipse(57+l,337+h,0,180,25,5);
line(22+l,320+h,22+l,328+h);
line(91+l,320+h,91+l,327+h);
setfillstyle(6,15);
floodfill(60+l,320+h,15);
ellipse(50+l,92+h,350,76,30,30);
line(58+l,61+h,58+l,63+h);
circle(58+l,58+h,3);
line(58+l,55+h,58+l,53+h);
circle(58+l,50+h,2);
line(58+l,48+h,58+l,47+h);
circle(58+l,45+h,1);
line(58+l,44+h,58+l,41+h);
setfillstyle(6,15);
floodfill(60+l-2,322+h+t-60,15);
setfillstyle(10,15);
floodfill(60+l,320+h+15,15);
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||
||||||||||||||||
||//
//++++++++++++++++++++++
+++++++++++++2nd++++++++
+++++++++++++++++++
setfillstyle(10,15);
floodfill(60+l-2,322+h+t-30,15);
//======================
===========IIst
tower====================
========//
//#################TOWER%
%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%//
l=547;
line(35+l,315+h,38+l,242+h);
line(80+l,315+h,75+l,242+h);
//||||||||||||||||||||||||||||||2st
stage||||||||||||||||||||||||||||||||||||||||||||//
t=-93;
line(23+4+l,328+t+3+h,32+5+l,334
+t+h);
// slant
line(88+l,328+t+2+h,76+l,334+t+h);
// slant
//line(+l83,323+t+4,75,334+t);
// slant
line(78+l,323+t+3+h,71+l,332+t+h);
line(66+l,323+t+2+h,65+l,332+t+h);
// slant
line(28+l,400+h,33+l,333+h);
line(86+l,400+h,80+l,333+h);
//||||||||||||||||||||||||||||||Ist
stage||||||||||||||||||||||||||||||||||||||||||||//
line(23+l,328+h,32+l,334+h);
// slant
line(57+l,323+t+2+h,57+l,332+t2+h);
// slant
//line(30,323+t+2,39,334+t);
// slant
line(35+l,323+t+3+h,453+l,332+t+h);
line(48+l,323+t+2+h,51+l,332+t2+h);
// slant
line(39+l,323+t+6+h,45+l,332+t+1+
h);
line(48+l,323+t+4+h,51+l,332+t+h);
// slant
ellipse(57+l,320+t+6+h,360,190,24,5
);
ellipse(57+l,327+t+4+h,360,190,24,5
);
ellipse(57+l,337+t-1+h,0,170,16,5);
ellipse(57+l,320+t+3+h,360,190,30,5
);
ellipse(57+l,327+t+3+h,360,190,30,5
);
ellipse(57+l,337+t-1+h,0,180,18,5);
line(32+l,320+t+6+h,32+l,328+t+3+
h);
line(81+l,320+t+6+h,81+l,327+t+3+
h);
line(26+l,320+t+3+h,26+l,328+t+2+
h);
line(88+l,320+t+3+h,88+l,327+t+3+
h);
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||
||||||||||||||||
||//
setfillstyle(6,15);
floodfill(60+l,320+h+t,15);
////////////////
setfillstyle(10,15);
floodfill(60+l,320+h-35,15);
setfillstyle(6,15);
floodfill(60+l,322+h+t,15);
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||
||||||||||||||||
||//
setfillstyle(10,15);
floodfill(60+l,322+h+t+30,15);
//GGF################TOWE
R%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%//
ellipse(51+l,132+h,340,216,4,15);
ellipse(62+l,131+h,327,216,4,15);
ellipse(72+l,132+h,327,216,2,15);
ellipse(42+l,132+h,327,216,2,15);
ellipse(57+l,107+h,0,170,16,5);
line(40+l,107+h,40+l,140+h);
line(75+l,107+h,75+l,140+h);
//||||||||||||||||||||||||||||||3rd
stage||||||||||||||||||||||||||||||||||||||||||||//
line(38+l,225+h,41+l,152+h);
line(75+l,225+h,72+l,152+h);
line(34+l,107+h,40+l,107+h);
line(75+l,107+h,81+l,107+h);
t=-182;
line(32+l,328+t+4+h,32+7+l,334+t+
h);
// slant
line(80+l,328+t+4+h,73+l,334+t+h);
// slant
//line(+l83,323+t+4,75,334+t);
// slant
line(76+l,323+t+5+h,71+l,332+t+h);
line(66+l,323+t+4+h,65+l,332+t+h);
// slant
line(57+l,323+t+4+h,57+l,332+t2+h);
// slant
//line(30,323+t+2,39,334+t);
// slant
line(34+l,107+h,28+l,102+h);
//slant
line(81+l,107+h,87+l,102+h);
line(28+l,102+h,34+l,98+h);
line(87+l,102+h,81+l,98+h);
line(34+l,98+h,58+l,95+h);
line(58+l,95+h,81+l,98+h);
ellipse(65+l,92+h,104,190,30,30);
8
circle(58+l,58+h,3);
line(58+l,55+h,58+l,53+h);
circle(58+l,50+h,2);
line(58+l,48+h,58+l,47+h);
circle(58+l,45+h,1);
line(58+l,44+h,58+l,41+h);
ellipse(50+l,92+h,350,76,30,30);
line(58+l,61+h,58+l,63+h);
circle(58+l,58+h,3);
line(58+l,55+h,58+l,53+h);
circle(58+l,50+h,2);
line(58+l,48+h,58+l,47+h);
circle(58+l,45+h,1);
line(58+l,44+h,58+l,41+h);
setfillstyle(6,15);
floodfill(60+l-2,322+h+t-60,15);
//======================
===========Ist
tower====================
====//
setfillstyle(10,15);
floodfill(60+l-2,322+h+t-30,15);
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||
||||||||||||||||
||//
//++++++++++++++++++++++
+++++++++++TAJ mahal++++++
++++++++++++++++++//
//GGF################TOWE
R%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%//
rectangle(275,290,365,440);
inner
rectangle(268,283,372,440);
//inner
setfillstyle(1,15);
floodfill(274,294,15);
line(280,440,280,350);
//line(283,440,283,350);
ellipse(315,349,130,180,35,40);
ellipse(275,280,290,326,53,40);
////setcolor(15);
ellipse(51+l,132+h,340,216,4,15);
ellipse(62+l,131+h,327,216,4,15);
ellipse(72+l,132+h,327,216,2,15);
ellipse(42+l,132+h,327,216,2,15);
ellipse(57+l,107+h,0,170,16,5);
line(40+l,107+h,40+l,140+h);
line(75+l,107+h,75+l,140+h);
line(360,440,360,350);
ellipse(325,349,360,50,35,40);
ellipse(361,280,216,255,53,40);
setfillstyle(9,7);
floodfill(277,386,15);
putpixel(277,386,14);
line(34+l,107+h,40+l,107+h);
line(75+l,107+h,81+l,107+h);
line(34+l,107+h,28+l,102+h);
//slant
line(81+l,107+h,87+l,102+h);
line(280,360,359,360);
line(280,364,359,364);
setfillstyle(1,15);
floodfill(281,362,15);
line(28+l,102+h,34+l,98+h);
line(87+l,102+h,81+l,98+h);
line(34+l,98+h,58+l,95+h);
line(58+l,95+h,81+l,98+h);
rectangle(295+4,370,345-4,440);
rectangle(292+4,367,348-4,440);
setfillstyle(1,15);
floodfill(294+4,369,15);
rectangle(296,378,344,380);
floodfill(301,379,15);
ellipse(65+l,92+h,104,190,30,30);
ellipse(50+l,92+h,350,76,30,30);
line(58+l,61+h,58+l,63+h);
9
//
//
line(302,405,302,440);
line(338,405,338,440);
ellipse(327,405,108,180,25,20);
floodfill(249,426,15);
////setcolor(8);
rectangle(230+135,425,275+140,440)
;
//setfillstyle(1,15);
ellipse(313,405,360,74,25,20);
setfillstyle(7,15);
//putpixel(312,416,11);
//floodfill(312,406,15);
line(329,390,329,440);
line(310,391,310,440);
line(311,402,329,402);
line(311,422,329,422);
line(302,412,310,412);
line(329,412,338,412);
floodfill(231+160,426,15);
floodfill(249+159,426,15);
////setcolor(15);
line(415,290,415,440);
line(420,245,420,440);
line(415,240,415,205);
line(420,240,420,205);
line(302,428,310,428);
line(329,428,338,428);
//setfillstyle(7,15);
int p=-60;
line(302,405+p,302,440+p-20);
line(338,405+p,338,440+p-20);
ellipse(327,405+p,108,180,25,20);
//vertical
line(225,240,225,205);
line(230,240,230,205);
//vertical
line(222,240,425,240);
line(222,245,425,245);
//horz
ellipse(313,405+p,360,74,25,20);
setfillstyle(7,15);
floodfill(311,406,15);
line(329,390+p,329,440+p-20);
line(310,391+p,310,440+p-20);
line(311,402+p,329,402+p);
line(311,422+p-7,329,422+p-7);
line(302,412+p,310,412+p);
line(329,412+p,338,412+p);
ellipse(222,242.5,90,270,2.5,2.5);
ellipse(425,242.5,270,90,2.5,2.5);
rectangle(231,230,414,239);
ellipse(227,206,0,180,9,1);
ellipse(227,204,0,180,9,1);
putpixel(220,204,15);
putpixel(220,205,15);
putpixel(220,206,15);
putpixel(235,204,15);
putpixel(235,205,15);
putpixel(235,206,15);
ellipse(227,203,0,180,6,7);
line(227,195,227,192);
int r=190;
//??//////////////////////////////////2nd
portion/////////////////////
rectangle(245,260,400,440);
inner
rectangle(230,245,415,440);
//inner
line(225,245,225,440);
line(230,250,230,440);
//
//
rectangle(230,425,275,440);
setfillstyle(1,15);
floodfill(231,426,15);
ellipse(227+r,206,0,180,9,1);
ellipse(227+r,204,0,180,9,1);
10
putpixel(220+r,204,15);
putpixel(220+r,205,15);
putpixel(220+r,206,15);
putpixel(235+r,204,15);
putpixel(235+r,205,15);
putpixel(235+r,206,15);
line(322,6,324,4);
//???????????????????????????????????
//////////////////////////////////////////////////////////
//ellipse();
ellipse(321,258,48,130,140,50);
ellipse(321,255,48,130,140,50);
ellipse(227+r,203,0,180,6,7);
line(227+r,195,227+r,192);
ellipse(321,241,48,130,140,50);
ellipse(321,238,48,130,140,50);
//setfillstyle(6,11);
// line(265,79,277,70);
//////setcolor(4);
//line(385,81,380,76);
/*
//floodfill(305,424,15);
//floodfill(305,429,15);
//floodfill(325,424,15);
//floodfill(325,421,15);
//floodfill(332,420,15);
//floodfill(332,429,15);
*/
//while(!kbhit())
//{
delay(300);
setfillstyle(10,15);
ellipse(315,170,140,210,105,100);
ellipse(330,170,330,40,105,100);
floodfill(322,160,15);
setfillstyle(6,15);
ellipse(292,167,105,140,75,95);
ellipse(353,167,40,75,75,95);
floodfill(322,193,15);
//}
//line(319,26,319,480+h);//center
ellipse(323,78,350,190,60,8);
ellipse(323,77,350,190,60,8);
//ellipse(259,24,295,358,58,51);
ellipse(240,24,321,358,78,71);
ellipse(192,40,342,7,128,100);
///////////////////////////////////////////new/////////
///////////////////
rectangle(150,283,225,294);
ellipse(448,30,180,203,128,100);
ellipse(443,5,194,220,128,100);
ellipse(438,-9,203,234,128,100);
ellipse(198,-6,310,340,128,100);
//line(146,294,225,294);
line(150,298,225,298);
line(150,240,150,440);
line(146,240,146,440);
//pole
line(150,299,150,440);
line(146,299,146,440);
//pole
ellipse(319,30,0,360,7,2);
floodfill(320,29,15);
circle(319,24,3);
line(319,20,319,18);
circle(319,14,4);
line(319,9,319,0);
//ellipse(319,4,0,360,2,3);
circle(319,2,1);
line(316,6,322,6);
line(316,6,314,4);
r=-80;
int n=34;
ellipse(227+r,206+n,0,180,9,1);
ellipse(227+r,204+n,0,180,9,1);
putpixel(220+r,204+n,15);
11
putpixel(220+r,205+n,15);
putpixel(220+r,206+n,15);
putpixel(235+r,204+n,15);
putpixel(235+r,205+n,15);
putpixel(235+r,206+n,15);
r=-134;
n=49;
ellipse(227+r,206+n,0,180,9,1);
ellipse(227+r,204+n,0,180,9,1);
putpixel(220+r,204+n,15);
putpixel(220+r,205+n,15);
putpixel(220+r,206+n,15);
putpixel(235+r,204+n,15);
putpixel(235+r,205+n,15);
putpixel(235+r,206+n,15);
ellipse(227+r,203+n,0,180,6,7);
line(227+r,195+n,227+r,192+n);
l=128;
h=150;
ellipse(51+l,132+h-7,340,216,4,15);
ellipse(62+l,131+h-7,327,216,4,15);
ellipse(72+l,132+h-7,327,216,2,15);
ellipse(42+l,132+h-7,327,216,2,15);
ellipse(57+l,107+h,0,170,16,5);
line(40+l,107+h,40+l,140+h-7);
line(75+l,107+h,75+l,140+h-7);
ellipse(227+r,203+n,0,180,6,7);
line(227+r,195+n,227+r,192+n);
line(146,294,97,302);
line(146,298,97,306);
line(146,283,97,291);
line(34+l,107+h,40+l,107+h);
line(75+l,107+h,81+l,107+h);
///////////////////////////////////////inner///////////
//////
line(34+l,107+h,28+l,102+h);
//slant
line(81+l,107+h,87+l,102+h);
//rectangle(275+k,290,365+k,440);
// inner
//rectangle(268+k,283,372+k,440);
//
//inner
line(28+l,102+h,34+l,98+h);
line(87+l,102+h,81+l,98+h);
line(34+l,98+h,58+l,95+h);
line(58+l,95+h,81+l,98+h);
//line(225,367,151,367);
rectangle(155,302,220,364);
rectangle(155,302+70,220,364+75);
ellipse(65+l,92+h,104,190,30,30);
int q=-133;
int d=-2;
line(302+q-5,405+d,302+q-5,440+d);
line(338+q+5,405+d,338+q+5,440+d
);
ellipse(327+q+5,405+d,108,180,35,3
0);
ellipse(50+l,92+h,350,76,30,30);
line(58+l,61+h,58+l,63+h);
circle(58+l,58+h,3);
line(58+l,55+h,58+l,53+h);
circle(58+l,50+h,2);
line(58+l,48+h,58+l,47+h);
circle(58+l,45+h,1);
line(58+l,44+h,58+l,41+h);
ellipse(313+q-5,406+d,360,74,35,30);
d=-77;
line(302+q-5,405+d,302+q-5,440+d);
line(338+q+5,405+d,338+q+5,440+d
);
ellipse(327+q,405+d,105,180,30,25);
line(100-5,240+15,1005,440);
//pole
line(96-5,240+15,96-5,440);
12
line(113,440,130,440);
floodfill(114+3,423,15);
ellipse(313+q,405+d,360,80,30,25);
putpixel(163,300,11);
setfillstyle(6,15);
floodfill(163,330,15);
floodfill(160,380,15);
int a=-76;
line(130-3,417+a,130-3,440+a-3);
line(113+3,420+a,113+3,440+a);
line(141,305,141,360);
line(101,310,101,365);
line(141,305,101,310);
line(141,360,101,365);
line(113+3,420+a,130-3,417+a);
putpixel(114,423,4);
floodfill(114+3,423+a,15);
int x=70;
line(141,305+x,141,440);
line(101,310+x,101,440);
line(141,305+x,101,310+x);
line(10,400+h,615,400+h);
//////////////////////////////////////////////right\\\\\
\\\\\\
q=-200;
line(302+q+4,405+d,302+q+4,440+d
);
line(338+q-1,405+d,338+q-1,440+d2);
ellipse(327+q,405+d,105,180,20,15);
ellipse(313+q+4,405+d,360,80,20,15)
;
int e=270;
rectangle(150+e,283,226+e,294);
line(146+e+4,294,225+e,294);
line(146+e+4,298,225+e,298);
d=1;
line(302+q+4,405+d,302+q+4,440+d
-2);
line(338+q-1,405+d,338+q-1,440+d2);
ellipse(327+q,405+d,105,180,20,15);
ellipse(313+q+4,405+d,360,80,20,15)
;
line(150+e+80,240,150+e+80,440);
//pole
line(146+e+80,240,146+e+80,440);
line(150+e+80,299,150+e+80,440);
//pole
line(146+e+80,299,146+e+80,440);
rectangle(178,415,197,439);
setfillstyle(7,15);
floodfill(179,416,15);
rectangle(178,415-75,197,440-76);
setfillstyle(7,15);
floodfill(179,415-75+1,15);
l=400;
h=+149;
ellipse(51+l,132+h-7,340,216,4,15);
ellipse(62+l,131+h-7,327,216,4,15);
ellipse(72+l,132+h-7,327,216,2,15);
ellipse(42+l,132+h-7,327,216,2,15);
ellipse(57+l,107+h,0,170,16,5);
line(40+l,107+h,40+l,140+h-7);
line(75+l,107+h,75+l,140+h-7);
line(130-3,417,130-3,440);
line(113+3,420,113+3,440);
line(113+3,420,130-3,417);
putpixel(114,423,4);
13
line(34+l,107+h,40+l,107+h);
line(75+l,107+h,81+l,107+h);
line(100-5+e+190,240+15,1005+e+190,440);
//pole
line(96-5+e+190,240+15,965+e+190,440);
line(34+l,107+h,28+l,102+h);
//slant
line(81+l,107+h,87+l,102+h);
line(28+l,102+h,34+l,98+h);
line(87+l,102+h,81+l,98+h);
r=325;
n+=15;
ellipse(227+r,206+n,0,180,9,1);
ellipse(227+r,204+n,0,180,9,1);
putpixel(220+r,204+n,15);
putpixel(220+r,205+n,15);
putpixel(220+r,206+n,15);
putpixel(235+r,204+n,15);
putpixel(235+r,205+n,15);
putpixel(235+r,206+n,15);
line(34+l,98+h,58+l,95+h);
line(58+l,95+h,81+l,98+h);
ellipse(65+l,92+h,104,190,30,30);
ellipse(50+l,92+h,350,76,30,30);
line(58+l,61+h,58+l,63+h);
circle(58+l,58+h,3);
line(58+l,55+h,58+l,53+h);
circle(58+l,50+h,2);
line(58+l,48+h,58+l,47+h);
circle(58+l,45+h,1);
line(58+l,44+h,58+l,41+h);
ellipse(227+r,203+n,0,180,6,7);
line(227+r,195+n,227+r,192+n);
rectangle(155+e,302,220+e,364);
rectangle(155+e,302+70,220+e,364+
75);
r=270;
n=n-15;
ellipse(227+r,206+n,0,180,9,1);
ellipse(227+r,204+n,0,180,9,1);
putpixel(220+r,204+n,15);
putpixel(220+r,205+n,15);
putpixel(220+r,206+n,15);
putpixel(235+r,204+n,15);
putpixel(235+r,205+n,15);
putpixel(235+r,206+n,15);
q=140;
d-=1;
line(302+q-5,405+d,302+q-5,440+d);
line(338+q+5,405+d,338+q+5,440+d
);
ellipse(327+q+5,405+d,108,180,35,3
0);
ellipse(313+q-5,406+d,360,74,35,30);
ellipse(227+r,203+n,0,180,6,7);
line(227+r,195+n,227+r,192+n);
d=-77;
line(302+q-5,405+d,302+q-5,440+d);
line(338+q+5,405+d,338+q+5,440+d
);
ellipse(327+q,405+d,105,180,30,25);
line(146+e+135,302,97+e+135,294);
line(146+e+135,306,97+e+135,298);
ellipse(313+q,405+d,360,80,30,25);
putpixel(163,300,11);
setfillstyle(6,15);
floodfill(163,330,15);
line(146+e+135,291,97+e+135,283);
14
floodfill(160,380,15);
/////////////////////////////
e=e-15;
line(141+e+150,305+5,141+e+150,3
60+5);
line(101+e+150,3105,101+e+150,365-5);
line(101+e+150,305,141+e+150,310)
;
line(101+e+150,360,141+e+150,365)
;
line(113+3+e,417+a,1303+e,420+a);
putpixel(114+e,423,4);
line(113+3+e,440,130-3+e,440);
floodfill(114+3+e,423+a,15);
q=204;
line(302+q+4,405+d,302+q+4,440+d
-2);
line(338+q-1,405+d,338+q1,440+d+2);
ellipse(327+q,405+d,105,180,20,15);
ellipse(313+q+4,405+d,360,80,20,15)
;
q=204;
int v=75;
line(141+e+150,305+5+v5,141+e+150,440);
line(101+e+150,310-5+v5,101+e+150,440);
line(101+e+150,305+v5,141+e+150,310+v-5);
//line(101+e+150,360+v,141+e+150,
365+v);
d=0;
line(302+q+4,405+d,302+q+4,440+d
-1);
line(338+q-1,405+d,338+q-1,440+d);
ellipse(327+q,405+d,105,180,20,15);
ellipse(313+q+4,405+d,360,80,20,15)
;
line(302+q+4,440,302+q+4,440);
e=e+18;
rectangle(178+e,415,197+e,439);
setfillstyle(7,15);
floodfill(179+e,416,15);
int f=-75;
rectangle(178+e,415+f,197+e,439+f)
;
setfillstyle(7,15);
floodfill(179+e,416+f,15);
setfillstyle(10,15);
floodfill(322,160,15);
setfillstyle(6,15);
e+=130;
line(130-3+e,440+a-2,1303+e,417+a+2);
line(113+3+e,440+a2,113+3+e,420+a-2);
floodfill(322,193,15);
///////////////////////////////////////////////walls///
///////////
setfillstyle(9,15);
floodfill(110,294,15);
floodfill(210,290,15);
floodfill(430,290,15);
floodfill(520,290,15);
/////////////////////////////////////////////poles
setfillstyle(6,15);
floodfill(93,394,15);
floodfill(148,394,15);
floodfill(227,394,15);
floodfill(417,394,15);
floodfill(498,394,15);
floodfill(553,394,15);
line(113+3+e,417+a,1303+e,420+a);
putpixel(114+e,423,4);
floodfill(114+3+e,423+a,15);
a=1;
line(130-3+e,440+a-2,1303+e,417+a+2);
line(113+3+e,440+a2,113+3+e,420+a-2);
15
#include<stdio.h>
#include<string.h>
setfillstyle(9,15);
floodfill(185,224,15);
floodfill(465,224,15);
class telephone
{
char name[25];
char address[40];
char phoneno[15];
public:
telephone(){ }
telephone(char nam[25], char
add[40], char phone[15])
{
strcpy(name,nam);
strcpy(address,add);
strcpy(phoneno,phone);
}
void init();
void button(int x1,int y1,int x2,int
y2,char str[]);
int press(int,int,int,int);
int unpress(int,int,int,int);
int mouseini();
int showmp();
int hidemp();
int getmp(int *button,int *x,int *y);
int setmp();
int click(int x1,int y1,int x2,int
y2,char str[]);
int screen();
void login();
void search();
void delete1();
void insert();
void update();
void display()
{
cout<<"
while(!kbhit())
{
delay(40);
putpixel(random(640),random(248),ra
ndom(15));
}
getch();
cleardevice();
setcolor(13);
rectangle(1,1,639,479);
rectangle(15,15,624,464);
//setcolor(LIGHTBLUE);
setfillstyle(6,11);
floodfill(2,2,13);
settextstyle(7,0,3);
setcolor(12);
//delay(1000);
getch();
return 0;
}
Name
: "<<name;
cout<<"
Address
: "<<address;
cout<<"
Phone Number: "<<phoneno;
}
int compare(char nam1[25])
{
if(strcmp(nam1,name)==0)
return 1;
else
#include<iostream.h>
#include<fstream.h>
#include<graphics.h>
#include<process.h>
#include<io.h>
#include<dos.h>
#include<conio.h>
16
return 0;
}
};
void telephone::login()
{
setcolor(15);
line (320-150,320-13,320+150,32013);
line
(320150,320+12,320+150,320+12);
line
(320-150,320-13,320150,320+12);
line (320+150,320+12,320+150,32013);
int s=30,w;
gotoxy(20,23);
cout<<"LOADING . . .";
for
(int
x1=171,x2=171,y1=308,y2=331,y=1,
S=0;x1<470;x1++,x2++,y++,S++)
{
setcolor(1);
line (x1,y1,x2,y2);
w=(x1-169)/3;
for (int i=34; i<=78; i++)
{
gotoxy(i,23) ;
cout <<" " ;
}
gotoxy(34,23); cout<<w<<"%";
if (x2>270) s=45; if (x2>370) s=10;
if (x2==320) delay(999); else
delay(s);
}
delay(800);
for (int i=27; i<=78; i++)
{
gotoxy(i,23) ;
cout <<" " ;
}
}
outtextxy(250,250,"Inserting
Record.....");
file.close();
delay(3000);
}
void telephone::init()
{
cout<<"
Enter Name
: ";
cin.getline(name,25);
cout<<"
Enter
Address
:
";
cin.getline(address,40);
cout<<"
Enter
Phone
Number:
";
cin.getline(phoneno,15);
}
void telephone::delete1()
{
telephone tel1;
fstream file ;
char nam[25],nam1[25];
strcpy(nam1,"");
cout<<"Enter the Name to be
deleted: ";
cin>>nam;
file.open("Phone.txt", ios::in) ;
fstream temp ;
temp.open("temp.txt", ios::out) ;
file.seekg(0,ios::beg) ;
while (file.read((char *) &tel1,
sizeof(telephone)))
{
if(!tel1.compare(nam))
temp.write((char *) &tel1,
sizeof(telephone)) ;
else
strcpy(nam1,nam);
}
file.close() ;
temp.close() ;
setcolor(7);
if(strlen(nam1)!=0)
{
file.open("Phone.txt", ios::out) ;
temp.open("temp.txt", ios::in) ;
temp.seekg(0,ios::beg) ;
while (temp.read((char *) &tel1,
sizeof(telephone)))
void telephone::insert()
{
telephone tel1;
fstream file;
file.open("Phone.txt",ios::app);
tel1.init();
file.write((char *) &tel1, sizeof(tel1));
setcolor(7);
17
}
file.close() ;
temp.close() ;
char nam[25],add[40],ph[15];
file.open("Phone.txt",ios::app);
cout<<"
Enter Name
: ";
cin.getline(nam,25);cin.getline(nam,25
);
cout<<"
Enter
Address
:
";
cin.getline(add,40);
cout<<"
Enter
Phone
Number:
";
cin.getline(ph,15);
tel1=telephone(nam,add,ph);
file.write((char *) &tel1, sizeof(tel1));
file.close();
outtextxy(250,250,"Updating
Record.....");
}
else
outtextxy(250,250,"Record not
found");
delay(3000);
}
file.write((char
*)
&tel1,
sizeof(telephone)) ;
}
file.close() ;
temp.close() ;
outtextxy(250,250,"Deleting
Record.....");
}
else
outtextxy(250,250,"Record not
found");
delay(3000);
}
void telephone::update()
{
telephone tel1;
fstream file ;
char nam[25],nam1[25];
strcpy(nam1,"");
cout<<"Enter the Name to be
updated: ";
cin>>nam;
file.open("Phone.txt", ios::in) ;
fstream temp ;
temp.open("temp.txt", ios::out) ;
file.seekg(0,ios::beg) ;
while (file.read((char *) &tel1,
sizeof(telephone)))
{
if(!tel1.compare(nam))
temp.write((char *) &tel1,
sizeof(telephone)) ;
else
strcpy(nam1,nam);
}
file.close() ;
temp.close() ;
setcolor(7);
if(strlen(nam1)!=0)
{
file.open("Phone.txt", ios::out) ;
temp.open("temp.txt", ios::in) ;
temp.seekg(0,ios::beg) ;
while (temp.read((char *) &tel1,
sizeof(telephone)))
{
file.write((char
*)
&tel1,
sizeof(telephone)) ;
void telephone::search()
{
fstream file;
telephone tel1;
int i=1;
char nam[25];
file.open("Phone.txt",ios::in);
cout<<"Enter name to be Searched:
";
cin>>nam;
file.seekg(0,ios::beg);
while(file.read((char
*)
&tel1,
sizeof(telephone)))
{
if(tel1.compare(nam))
{
tel1.display();
i=0;
break ;
}
}
file.close() ;
if(i)
18
{
setcolor(7);
outtextxy(250,250,"Record
found");
}
getch();
}
void telephone:: button(int
y1,int x2,int y2,char str[])
{
int xc,yc,i=0,l=0;
while(i<strlen(str))
{
l+=4;
i++;
}
xc=(x2-x1)/2+x1-l;
yc=(y2-y1)/2+y1;
unpress(x1,y1,x2,y2);
settextstyle(0,0,0);
setcolor(11);
outtextxy(xc,yc,str);
}
line(x1,y2,x2,y2);
line(x2,y1,x2,y2);
return 0;
}
not
x1,int
outtextxy(100,30,"TELEPHONE");
outtextxy(600,30,"DIRECTORY");
setmp();
button(250,100,400,150,"Insert");
button(250,150,400,200,"Delete");
button(250,200,400,250,"Update");
button(250,250,400,300,"Search");
button(250,300,400,350,"Exit");
while(1)
{
if(click(250,100,400,150,"Insert")==
0)
{
cleardevice();
insert();
return 0;
}
if(click(250,150,400,200,"Delete")==
0)
{
cleardevice();
delete1();
return 0;
}
if(click(250,200,400,250,"Update")=
=0)
{
cleardevice();
update();
return 0;
}
if(click(250,250,400,300,"Search")==
0)
{
cleardevice();
search();
return 0;
}
if(click(250,300,400,350,"Exit")==0)
exit(0);
}
}
void main()
{
char
user[25]="User
Name",*pass,*pass1="user";
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"");
while(1)
{
cleardevice();
settextstyle(0,0,1);
outtextxy(250,250,"User Name:");
outtextxy(250,265,"Password :");
outtextxy(335,250,user);
pass=getpass("");
if(strcmp(pass,pass1)==0)
{
cleardevice();
telephone tel;
char op[8],cp[8],np[8];
tel.login();
while(1)
{
cleardevice();
tel.mouseini();
tel.showmp();
tel.screen();
}
}
else
{
cleardevice();
settextstyle(0,0,2);
outtextxy(250,250,"Illegal User....");
delay(3000);
}
}
}
char ch='4';
char ch1='1';
char ch2='1';
int pts1[5][3];
float tx,ty,tz,d=.5;
void
assign(float,float,float,float,float,float,fl
oat,float,float);
void
scan_line(float,float,float,float,float,flo
at,float,float,float);
void
drawpyramid(float,float,float,float,float
,float);
void call_assign(void);
void display(void);
void tranform(void);
void draw(void);
void drawscale(void);
float
pts[5][3]={-100,0,0,
0,0,45,
100,0,0, 0,0,-45, 0,130,0};
float
pts2[5][3]={228,273,0,
305,295,0, 428,273,0, 350,250,0
,328,143,0};
float
pt[5][3]={-100,0,0,
0,0,45,100,0,0,0,0-45,0,130,0};
void main()
{
int i;
float sx,sy,sz=1;
struct palettetype pal;
int gd,gm;
detectgraph(&gd,&gm);
Rotation of triangle
#include<stdio.h>
#include<iostream.h>
#include<dos.h>
#include<process.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
initgraph(&gd,&gm,"c:\tc\bgi");
getpalette(&pal);
firstpage();
for(i=16;i>0;i--)
setrgbpalette(pal.colors[i],
0,4*i,0);
//void
render(float,float,float,
float,float,float,
float,float,float,float,float,float);
void initialize(void);
void firstpage(void);
void call_first(void);
float
intensity,alpha,thita,tempy,tempz,tem
px;
L1: display();
while(ch1!='4')
{
ch='2';
L2: call_assign();
clearviewport();
21
gotoxy(1,2);
cout<<"1. Translation";
cout<<"2. Rotation";
cout<<"3. Scaling ";
cout<<"4. Back ";
ch1=getch();
if(ch1=='4')
{
clearviewport();
goto L1;
}
}
if(ch1=='3')
{
clearviewport();
cout<<"Enter
sx:";
cin>>sx;
cout<<"Enter
sy:";
cin>>sy;
for(i=0;i<5;i++)
{
pts2[i][0]=abs(pts2[i]
[0]*sx+200*(1-sx));
pts2[i][1]=abs(pts2[i]
[1]*sy+200*(1-sy));
}
drawscale();
getch();
}
if(ch1=='1')
{
clearviewport();
while(ch1!='4')
{
gotoxy(2,2);
cout<<"a.
X+";
cout<<" b. X-";
cout<<" c. Y+"; cout<<"
d. Y- ";
cout<<"
e.
Z+";
cout<<" f. Z-";
cout<<" g. Back";
call_assign();
ch1=getch();
clearviewport();
if(ch1=='g')
goto L2;
if(ch1=='a')
tx=5;
if(ch1=='b')
tx=-5;
if(ch1=='c')
ty=5;
if(ch1=='d')
ty=-5;
if(ch1=='e')
tz=10;
if(ch1=='f')
tz=-10;
if(ch1=='2')
{
while(ch2!='4')
{
clearviewport();
gotoxy(1,2);
cout<<"1.X-axis
rotation";
gotoxy(1,3);
cout<<"2.Y-axis
rotation";
gotoxy(1,4);
cout<<"3.Z-axis
rotation";
gotoxy(1,5);
cout<<"4.Back";
ch2=getch();
if(ch2=='4')
break;
if(ch2=='1')
{
alpha=0;
while(alpha<360)
{
alpha=alpha+10
;
thita=(alpha*3.1
42)/180;
initialize();
for(i=0;i<5;i++)
{
pts[i][0]+=tx;
pts[i][1]+=ty;
pts[i][1]+=tz;
}
}
22
for(i=0;i<5;i++)
{
alpha=
alpha+10;
tempy=(pts1[i][1]*cos(thita)+pts1[i]
[2]*sin(thita));
thita=(alpha*3.142)/180;
initializ
e();
pts1[i][2]=(pts1[i][1]*sin(thita)-pts1[i]
[2]*cos(thita));
pts1[i]
[1]=tempy;
}
clearviewport();
draw();
delay(100);
}
}
for(i=0
;i<5;i++)
{
tempx=(pts1[i][0]*cos(thita)-pts1[i]
[1]*sin(thita));
pts1[i][1]=(pts1[i][0]*sin(thita)
+pts1[i][1]*cos(thita));
pts1[i]
[0]=tempx;
if(ch2=='2')
{
}
clearvi
alpha=0;
while(alpha<360)
{
alpha=alpha+10
ewport();
thita=(alpha*3.1
ewport();
draw();
delay(
100);
clearvi
42)/180;
draw();
initialize();
for(i=0;i<5;i++)
{
}
}
}
}
}
closegraph();
restorecrtmode();
}
void initialize()
{
pts1[0][0]=-100;
pts1[0][1]=-65;
pts1[0][2]=0;
pts1[1][0]=0;
pts1[1][1]=-65;
pts1[1][2]=-45;
pts1[2][0]=100;
pts1[2][1]=-65;
pts1[2][2]=0;
pts1[3][0]=0;
pts1[3][1]=-65;
pts1[3][2]=45;
pts1[4][0]=0;
tempz=(pts1[i][2]*cos(thita)+pts1[i]
[0]*sin(thita));
pts1[i][0]=(pts1[i][2]*sin(thita)-pts1[i]
[0]*cos(thita));
pts1[i]
[2]=tempz;
}
clearviewport();
draw();
delay(100);
}
}
if(ch2=='3')
{
alpha=0;
while(alpha<360)
{
23
pts1[4][1]=65;
pts1[4][2]=0;
cout<<"1.
Visible Surface Detection ";
gotoxy(2,3);
cout<<"2.
Surface Rendering";
gotoxy(2,4);
cout<<"3.
Transformations";
gotoxy(2,5);
cout<<"4.
Wireframe Display";
gotoxy(2,6);
cout<<"5.
Exit
";
call_assign();
ch=getch();
if(ch=='5')
exit(0);
clearviewport();
if(ch=='3')
break;
}
}
void call_assign(void)
{
assign(pts[0][0],pts[0][1],pts[0]
[2],pts[1][0],pts[1][1],pts[1][2],pts[4][
0],pts[4][1],pts[4][2]);
}
void firstpage()
{
clearviewport();
setcolor(WHITE);
settextstyle(2,HORIZ_DIR,5);
outtextxy(250,15,"A Project
on");
setcolor(GREEN);
settextstyle(3,HORIZ_DIR,4);
outtextxy(170,25,"PYRAMID
MODELING");
rectangle(300,120,580,320);
rectangle(295,115,585,325);
setcolor(6);
settextstyle(4,HORIZ_DIR,3);
outtextxy(50,100,
"OPTIONS");
settextstyle(3,HORIZ_DIR,1);
setcolor(11);
outtextxy(20,150,"1. VISIBLE
SURFACE DETECTION");
outtextxy(20,190,"2.
SURFACE RENDERING");
outtextxy(20,230,"3.
TRANSFORMATIONS");
outtextxy(20,270,"4.
WIREFRAME DISPLAY");
outtextxy(20,310,"5. EXIT");
assign(pts[1][0],pts[1][1],pts[1]
[2],pts[2][0],pts[2][1],pts[2][2],pts[4][
0],pts[4][1],pts[4][2]);
assign(pts[2][0],pts[2][1],pts[2]
[2],pts[3][0],pts[3][1],pts[3][2],pts[4][
0],pts[4][1],pts[4][2]);
call_first();
//display();
setcolor(WHITE);
getch();
cleardevice();
clearviewport();
assign(pts[0][0],pts[0][1],pts[0]
[2],pts[4][0],pts[4][1],pts[4][2],pts[3][
0],pts[3][1],pts[3][2]);
}
void call_first(void)
{
assign(pt[0][0],pt[0][1],pt[0][2],pt[1]
[0],pt[1][1],pt[1][2],pt[4][0],pt[4
][1],pt[4][2]);
}
void display(void)
{ while(ch!='3')
{ clearviewport();
assign(pt[1][0],pt[1][1],pt[1][2],pt[2]
[0],pt[2][1],pt[2][2],pt[4][0],pt[4
][1],pt[4][2]);
gotoxy(2,2);
24
if (intensity>15)
intensity=15;
assign(pt[2][0],pt[2][1],pt[2][2],pt[3]
[0],pt[3][1],pt[3][2],pt[4][0],pt[4
][1],pt[4][2]);
z1=55-z1;
x1=x1+300+(d*z1);
(d*z1);
z2=55-z2;
x2=x2+300+(d*z2);
(d*z2);
z3=55-z3;
x3=x3+300+(d*z3);
(d*z3);
assign(pt[0][0],pt[0][1],pt[0][2],pt[4]
[0],pt[4][1],pt[4][2],pt[3][0],pt[3
][1],pt[3][2]);
}
y1=300-y1y2=300-y2y3=300-y3-
if(ch=='1')
{ if(intensity==0) return;
drawpyramid(x1,y1,x2,y2,x3,y3);
return;
}
if(ch=='3')
exit(0);
void
drawpyramid(float
x1,float
y1,float x2,float y2,float x3,float y3)
{
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
}
if(ch=='4')
drawpyramid(x1,y1,x2,y2,x3,y3);
if(ch=='2')
{
if(intensity==0) return;
if ((y1>y2) && (y1>y3) && (y2>y3))
scan_line(x1,y1,z1,x2,y2,z2,x3,y3,z
3);
if ((y1>y2) && (y1>y3) && (y3>y2))
scan_line(x1,y1,z1,x3,y3,z3,x2,y2,z
2);
A=y1*(z2-z3)+y2*(z3-z1)+y3*(z1-z2);
B=z1*(x2-x3)+z2*(x3-x1)+z3*(x1-x2);
C=x1*(y2-y3)+x2*(y3-y1)+x3*(y1y2);
temp=sqrt(A*A+B*B+C*C);
templ=sqrt(Xl*Xl+Yl*Yl+Zl*Zl);
X=(float)Xl/templ; Y=(float)Yl/templ;
Z=(float)Zl/templ;
An=(A/temp);
Bn=(float)B/temp;
Cn=(float)C/temp;
intensity=15*(An*X+Bn*Y+Cn*Z);
if ((y3>y1) && (y3>y2) && (y2>y1))
scan_line(x3,y3,z3,x2,y2,z2,x1,y1,z
1);
if (intensity<0)
intensity=0;
25
}
}
putpixel(tempx+i,tempy,intensity);
}
else
{
for(i=0;i+tempx1<=tempx;i++)
putpixel(tempx1+i,tempy,intensity
);
}
tempy--;
}
}
void draw()
{ int i;
for(i=0;i<5;i++)
{
pts1[i][2]=50+pts1[i][2]+50;
pts1[i][0]=pts1[i]
[0]+300+.5*pts1[i][2];
pts1[i][1]=200+65-pts1[i]
[1]-.5*pts1[i][2];
}
line(pts1[0][0],pts1[0][1],pts1[1]
[0],pts1[1][1]);
line(pts1[1][0],pts1[1][1],pts1[2]
[0],pts1[2][1]);
line(pts1[2][0],pts1[2][1],pts1[3]
[0],pts1[3][1]);
line(pts1[3][0],pts1[3][1],pts1[0]
[0],pts1[0][1]);
line(pts1[0][0],pts1[0][1],pts1[4]
[0],pts1[4][1]);
line(pts1[1][0],pts1[1][1],pts1[4]
[0],pts1[4][1]);
line(pts1[2][0],pts1[2][1],pts1[4]
[0],pts1[4][1]);
line(pts1[3][0],pts1[3][1],pts1[4]
[0],pts1[4][1]);
}
void drawscale()
{
line(pts2[0][0],pts2[0][1],pts2[1]
[0],pts2[1][1]);
line(pts2[1][0],pts2[1][1],pts2[2]
[0],pts2[2][1]);
line(pts2[2][0],pts2[2][1],pts2[3]
[0],pts2[3][1]);
line(pts2[3][0],pts2[3][1],pts2[0]
[0],pts2[0][1]);
line(pts2[0][0],pts2[0][1],pts2[4]
[0],pts2[4][1]);
line(pts2[1][0],pts2[1][1],pts2[4]
[0],pts2[4][1]);
line(pts2[2][0],pts2[2][1],pts2[4]
[0],pts2[4][1]);
line(pts2[3][0],pts2[3][1],pts2[4]
[0],pts2[4][1]);
}
setfillstyle(1,14);
circle(x+100,y+100,R);
floodfill(x+100,y+100,14);
setcolor(14);
setfillstyle(1,14);
circle(xx+100,yy+100,R);
floodfill(xx+100,yy+100,14);
setcolor(14);
setfillstyle(1,14);
circle(X+100,Y+100,R);
floodfill(X+100,Y+100,14);
putpixel(X+100,Y+100,4);
delay(100);
setcolor(0);
setfillstyle(1,0);
circle(x+100,y+100,R);
floodfill(x+100,y+100,0);
#define R 5
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>
#include<stdlib.h>
void main()
setcolor(0);
setfillstyle(1,0);
circle(xx+100,yy+100,R);
floodfill(xx+100,yy+100,0);
{
void orbit(void);
int d=DETECT,m;
initgraph(&d,&m,"e:\tcc\bgi");
setcolor(0);
setfillstyle(1,0);
circle(X+100,Y+100,R);
floodfill(X+100,Y+100,0);
float
xx,yy,aa=15,bb=50,x,y,X,Y,a=34,b=0,
A=100,B=60,ex,sq;
setcolor(14);
// orbit();
if(kbhit())
exit(1);
orbit();
}
for(float i=0;i<=720;i+=.1)
{
getch();
}
x=a*cos(i+10)-a*sin(i+10);
y=b*sin(i+10)+a*cos(i+10);
void orbit()
{
for(float i=0;i<=60;i+=1)
{
X=A*cos(i+20)-B*sin(i+20+90);
Y=B*sin(i+20)+B*cos(i+20+90);
float
xx,yy,aa=15,bb=50,x,y,X,Y,a=34,b=0,
A=100,B=60,ex,sq;
x=a*cos(i)-a*sin(i);
y=b*sin(i)+a*cos(i);
xx=aa*cos(i);
yy=bb*sin(i);
setcolor(14);
27
}
void findday()
{
X=A*cos(i)-B*sin(i+90);
Y=B*sin(i)+B*cos(i+90);
int
k=1,m=11,mon,D,C,f,i,y,total=0,t,I,d,x
1=115,y1=160,q,r,v;
static int s=0;
char st2[3],st3[9],st4[5];
int
days[]={31,28,31,30,31,30,31,31,30,3
1,30,31};
char
*month[]={"JANUARY","FEBRUARY","M
ARCH","APRIL","MAY","JUNE","JULY","A
UGUST
","SEPTEMBER","OCTOBER","NOVEMBE
R","DECEMEBER"};
restorecrtmode();
cout<<"Enter year : ";
cin>>y;
cout<<"Enter month : ";
cin>>mon;
if(mon>12)
{
cout<<" Invalid entry !.....";
delay(1000);
setgraphmode(getgraphmode());
menu();
}
y-=1;
C=y/100;
D=y%100;
f=(k+((13*m-1)/5)+D+(D/4)+(C/4)(2*C));
i=f%7;
if(i<0)
i+=7;
y++;
if(y%4==0)
days[1]=29;
for(t=0;t<mon-1;t++)
{
total+=days[t];
}
I=total%7;
d=I+i;
if(d>=7)
d=d%7;
setgraphmode(getgraphmode());
cal();
xx=aa*cos(i);
yy=bb*sin(i);
putpixel(x+100,y+100,14);
putpixel(X+100,Y+100,14);
putpixel(xx+100,yy+100,14);
}
}
v=mon-1;
strcpy(st3,month[v]);
itoa(y,st4,10);
settextstyle(2,0,8);
outtextxy(100,90,st3);
outtextxy(250,90,st4);
q=days[mon-1];
settextstyle(1,0,2);
setcolor(15);
for(r=1;r<=d;r++)
{
x1+=62;
s++;
}
for(r=1;r<=q;r++)
{
itoa(r,st2,10);
if(s>=6)
{
outtextxy(x1,y1,st2);
y1+=30;
x1=112;
s=0;
continue;
}
outtextxy(x1,y1,st2);
x1+=60;
s++;
}
s=0;
getch();
menu();
}
void menu()
{
cleardevice();
int b,xx,yy;
initmouse();
restrictmouse(0,0,getmaxx(),getmax
y());
setbkcolor(0);
settextstyle(10,0,2);
outtextxy(100,70,"***********MENU**
*********
");
outtextxy(100,150,"=> MONTH'S
CALENDAR
");
outtextxy(100,200,"=> EXIT
");
settextstyle(8,0,1);
outtextxy(350,300,"Hello World");
showmouse();
while(!kbhit())
{
getmousestatus(&b,&xx,&yy);
if(xx>=100&&yy>=150&&xx<=50
0&&yy<=200)
{
getmousestatus(&b,&xx,&yy);
if(b&1==1)
{
hidemouse();
cleardevice();
findday();
}
}
if(xx>=100&&yy>=200&&xx<=30
0&&yy<=260)
{
getmousestatus(&b,&xx,&yy);
if(b&1==1)
{
hidemouse();
cleardevice();
setbkcolor(0);
setcolor(15);
settextstyle(10,0,5);
outtextxy(100,200,"EXITING");
int o=0;
for(int n=0;n<10;n++)
{
outtextxy(380+o,200,".");
o+=20;
delay(200);
}
exit(0);
}
}
}
}
void cal()
{
cleardevice();
int
l=100,t=125,r=155,b=185,g,x=110,y
=127;
char
*day[]={"SUN","MON","TUE","WED","T
HU","FRI","SAT"};
29
char st1[4];
setbkcolor(0);
settextstyle(10,0,7);
setcolor(15);
outtextxy(100,-40,"C");
settextstyle(10,0,6);
outtextxy(160,-20,"ALENDAR");
setfillstyle(1,BLUE);
bar(85,115,530,345);
setfillstyle(1,0);
bar3d(l,t,r,b,0,0);
bar3d(l,t+30,r,b+30,0,0);
bar3d(l,t+60,r,b+60,0,0);
bar3d(l,t+90,r,b+90,0,0);
bar3d(l,t+120,r,b+120,0,0);
bar3d(l,t+150,r,b+150,0,0);
bar3d(l,t+180,r,b+150,0,0);
bar3d(l+60,t,r+60,b,0,0);
bar3d(l+60,t+30,r+60,b+30,0,0);
bar3d(l+60,t+60,r+60,b+60,0,0);
bar3d(l+60,t+90,r+60,b+90,0,0);
bar3d(l+60,t+120,r+60,b+120,0,0);
bar3d(l+60,t+150,r+60,b+150,0,0);
bar3d(l+60,t+180,r+60,b+150,0,0);
bar3d(l+120,t,r+120,b,0,0);
bar3d(l+120,t+30,r+120,b+30,0,0);
bar3d(l+120,t+60,r+120,b+60,0,0);
bar3d(l+120,t+90,r+120,b+90,0,0);
bar3d(l+120,t+120,r+120,b+120,0,0
);
bar3d(l+120,t+150,r+120,b+150,0,0
);
bar3d(l+120,t+180,r+120,b+150,0,0
);
bar3d(l+180,t,r+180,b,0,0);
bar3d(l+180,t+30,r+180,b+30,0,0);
bar3d(l+180,t+60,r+180,b+60,0,0);
bar3d(l+180,t+90,r+180,b+90,0,0);
bar3d(l+180,t+120,r+180,b+120,0,0
);
bar3d(l+180,t+150,r+180,b+150,0,0
);
bar3d(l+180,t+180,r+180,b+150,0,0
);
bar3d(l+240,t,r+240,b,0,0);
bar3d(l+240,t+30,r+240,b+30,0,0);
bar3d(l+240,t+60,r+240,b+60,0,0);
bar3d(l+240,t+90,r+240,b+90,0,0);
bar3d(l+240,t+120,r+240,b+120,0,0
);
bar3d(l+240,t+150,r+240,b+150,0,0
);
bar3d(l+240,t+180,r+240,b+150,0,0
);
bar3d(l+300,t,r+300,b,0,0);
bar3d(l+300,t+30,r+300,b+30,0,0);
bar3d(l+300,t+60,r+300,b+60,0,0);
bar3d(l+300,t+90,r+300,b+90,0,0);
bar3d(l+300,t+120,r+300,b+120,0,0
);
bar3d(l+300,t+150,r+300,b+150,0,0
);
bar3d(l+300,t+180,r+300,b+150,0,0
);
bar3d(l+360,t,r+360,b,0,0);
bar3d(l+360,t+30,r+360,b+30,0,0);
bar3d(l+360,t+60,r+360,b+60,0,0);
bar3d(l+360,t+90,r+360,b+90,0,0);
bar3d(l+360,t+120,r+360,b+120,0,0
);
bar3d(l+360,t+150,r+360,b+150,0,0
);
bar3d(l+360,t+180,r+360,b+150,0,0
);
settextstyle(1,0,2);
setcolor(15);
for(g=0;g<7;g++)
{
strcpy(st1,day[g]);
outtextxy(x,y,st1);
x+=60;
}
}
initmouse()
{
i.x.ax=0;
int86(0x33,&i,&o);
return(o.x.ax);
}
showmouse()
{
i.x.ax=1;
int86(0x33,&i,&o);
return(o.x.ax);
}
hidemouse()
{
i.x.ax=2;
int86(0x33,&i,&o);
return(o.x.ax);
30
}
void restrictmouse(int x1,int y1,int
x2,int y2)
{
i.x.ax=7;
i.x.cx=x1;
i.x.dx=x2;
int86(0x33,&i,&o);
i.x.ax=8;
i.x.cx=y1;
i.x.dx=y2;
int86(0x33,&i,&o);
}
void getmousestatus(int *button,int
*x,int *y)
{
i.x.ax=3;
int86(0x33,&i,&o);
*button=o.x.bx;
*x=o.x.cx;
*y=o.x.dx;
}
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();
}
#include<dos.h>
#include<iostream.h>
#include<graphics.h>
#include<math.h>
#include<conio.h>
void main()
{
#include<iostream.h>
#include<dos.h>
#include<stdio.h>
#include<math.h>
#include<conio.h>
#include<graphics.h>
#include<process.h>
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++)
{
int gd=DETECT,gm;
double x1,x2,y1,y2;
void show_message()
{
char
*mess[]={"-","=","[","
","3","D","-","T","r","a","n","s",
"f","o","r","m","a","t","i","o","n","
","]","=","-"};
int xx=28,xxx=52,i,j;
_setcursortype(_NOCURSOR);
for(float i=90;i<270;i+=10)
{
y=cos(((i*22/7)/180))/j;
31
for(i=0,j=24;i<15,j>=12;i+
clearviewport();
for(i=0;i<20;i++)
{
edge[i][0]=edge[i][0]*a;
edge[i][1]=edge[i][1]*b;
edge[i][2]=edge[i][2]*c;
}
draw_cube(edge);
closegraph();
}
+,j--)
{
gotoxy(xx,1);
cout<<mess[i];
xx++;
gotoxy(xxx,1);
cout<<mess[j];
xxx--;
delay(50);
}
_setcursortype(_NORMALCURSOR);
}
void draw_cube(double edge[20][3])
{
initgraph(&gd,&gm,"..\bgi");
int i;
clearviewport();
for(i=0;i<19;i++)
{
x1=edge[i][0]+edge[i]
[2]*(cos(2.3562));
y1=edge[i][1]-edge[i]
[2]*(sin(2.3562));
x2=edge[i+1]
[0]+edge[i+1][2]*(cos(2.3562));
y2=edge[i+1][1]edge[i+1][2]*(sin(2.3562));
line(x1+320,240y1,x2+320,240-y2);
}
line(320,240,320,25);
line(320,240,550,240);
line(320,240,150,410);
getch();
closegraph();
}
cin>>ch;
switch(ch)
{
case 1:
cout<<"
" Enter The Angle ":=";
cin>>theta;
case 3:
cout<<"
" Enter The Angle ":=";
cin>>theta;
theta=(theta*3.14)/180;
for(i=0;i<20;i++)
{
edge[i]
[2]=edge[i][2];
theta=(theta*3.14)/180;
for(i=0;i<20;i++)
{
edge[i]
[0]=edge[i][0];
temp=edge[i][0];
temp1=edge[i][1];
temp=edge[i][1];
edge[i]
[0]=temp*cos(theta)temp1*sin(theta);
temp1=edge[i][2];
edge[i]
edge[i]
[1]=temp*cos(theta)temp1*sin(theta);
[1]=temp*sin(theta)
+temp1*cos(theta);
edge[i]
}
draw_cube(edge);
break;
[2]=temp*sin(theta)
+temp1*cos(theta);
}
draw_cube(edge);
break;
}
}
void reflect(double edge[20][3])
{
int ch;
int i;
clrscr();
cout<<"
-=[
Reflection
About ]=-";
cout<<"
case 2:
cout<<"
" Enter The Angle ":=";
cin>>theta;
theta=(theta*3.14)/180;
for(i=0;i<20;i++)
{
edge[i]
[1]=edge[i][1];
temp=edge[i][0];
temp1=edge[i][2];
edge[i]
[0]=temp*cos(theta)
+temp1*sin(theta);
edge[i][2]=temp*sin(theta)+temp1*cos(theta);
}
draw_cube(edge);
break;
33
edge[i]
cout<<"
2:==>" Y-Axis "";
cout<<"
3:==>" Z-Axis "";
cout<<"
[0]=edge[i][0];
edge[i][1]=edge[i][1];
edge[i][2]=edge[i][2];
}
draw_cube(edge);
break;
case 2:
for(i=0;i<20;i++)
{
edge[i]
[1]=edge[i][1];
edge[i][0]=edge[i][0];
edge[i][2]=edge[i][2];
}
draw_cube(edge);
break;
case 3:
for(i=0;i<20;i++)
{
edge[i]
[2]=edge[i][2];
edge[i][0]=edge[i][0];
edge[i][1]=edge[i][1];
}
draw_cube(edge);
break;
}
}
case 2:
cout<<"
" Enter Q ":=";
cin>>q;
for(i=0;i<20;i++)
{
edge[i]
[1]=edge[i][1]/(edge[i][1]*q+1);
edge[i]
[0]=edge[i][0]/(edge[i][1]*q+1);
edge[i]
[2]=edge[i][2]/(edge[i][1]*q+1);
}
draw_cube(edge);
break;
case 3:
cout<<"
" Enter R ":=";
cin>>r;
for(i=0;i<20;i++)
{
edge[i]
[2]=edge[i][2]/(edge[i][2]*r+1);
edge[i]
[0]=edge[i][0]/(edge[i][2]*r+1);
edge[i]
[1]=edge[i][1]/(edge[i][2]*r+1);
}
draw_cube(edge);
break;
}
closegraph();
}
void main()
{
int choice;
double edge[20][3]=
{
100,0,0,
100,100,0,
0,100,0,
0,100,100,
0,0,100,
0,0,0,
100,0,0,
100,0,100,
100,75,100,
75,100,100,
100,100,75,
100,100,0,
100,100,75,
100,75,100,
75,100,100,
0,100,100,
0,100,0,
0,0,0,
0,0,100,
100,0,100
};
while(1)
{
clrscr();
show_message();
cout<<"
draw_cube(edge);
break;
case 2:
scale(edge);
break;
case 3:
rotate(edge);
break;
case 4:
reflect(edge);
break;
case 5:
translate(edge);
break;
case 6:
perspect(edge);
break;
case 7:
exit(0);
default:
cout<<"
a" Press A Valid Key...!!! "";
getch();
35
break;
}
closegraph();
poly[14]=96;
poly[15]=119;
poly[16]=88;
poly[17]=113;
poly[18]=89;
poly[19]=105;
poly[20]=105;
poly[21]=105;
setcolor(8);
drawpoly(11,poly);
setfillstyle(1,8);
floodfill(94,108,8);
setcolor(14);
poly1[0]=105;
poly1[1]=105;
poly1[2]=103;
poly1[3]=108;
poly1[4]=101;
poly1[5]=109;
poly1[6]=101;
poly1[7]=111;
poly1[8]=100;
poly1[9]=108;
poly1[10]=98;
poly1[11]=108;
poly1[12]=96;
poly1[13]=111;
poly1[14]=96;
poly1[15]=119;
drawpoly(8,poly1);
line(105,105,110,105);
setfillstyle(1,14);
floodfill(106,110,14);
floodfill(111,112,14);
setcolor(2);
for(variable1=0;variable1<=5;variabl
e1+=2)
ellipse(100,101,0,180,10,variable1);
setcolor(4);
for(variable1=0;variable1<=5;variabl
e1+=3)
ellipse(100,105,0,180,20,variable1);
line(80,105,120,105);
setfillstyle(1,0);
fillellipse(107,111,1,2);
setcolor(0);
arc(107,111,70,160,3);
setcolor(6);
setfillstyle(1,6);
fillellipse(99,112,1,3);
}}
setfillstyle(1,4);
fillellipse(99,115,2,2);
setcolor(8);
for(variable1=0;variable1<=3;variabl
e1++)
ellipse(107,118,70,180,4,variable1);
setcolor(4);
line(93,128,108,133);
line(108,133,110,138);
line(110,138,93,133);
line(93,133,93,128);
setfillstyle(2,4);
floodfill(96,131,4);
setcolor(2);
ellipse(100,193,20,70,15,60);
ellipse(101,184,120,170,15,60);
line(93,133,105,137);
line(86,174,114,173);
setfillstyle(1,2);
floodfill(90,170,2);
setcolor(3);
line(104,140,102,150);
line(94,140,94,151);
line(94,140,103,140);
line(100,150,108,165);
line(100,165,108,165);
line(94,151,100,165);
setcolor(14);
line(102,166,107,166);
line(103,168,109,168);
line(102,166,103,168);
line(107,166,109,168);
setfillstyle(1,14);
floodfill(105,167,14);
setcolor(0);
line(102,169,110,169);
setfillstyle(9,2);
floodfill(100,145,3);
setcolor(12);
getimage(78,95,122,202,p1);
line(108,175,106,195);
line(92,175,94,195);
line(108,175,92,175);
line(106,195,94,195);
setfillstyle(6,12);
floodfill(100,180,12);
setcolor(8);
setfillstyle(6,8);
ellipse(103,200,0,180,10,3);
line(93,200,113,200);
floodfill(103,199,8);
getimage(78,95,122,202,p2);
putimage(78,95,p2,1);
putimage(78,95,p1,1);
setcolor(12);
setfillstyle(6,12);
int po[100],pol[100];
po[0]=110;
po[1]=174;
po[2]=120;
po[3]=196;
po[4]=108;
po[5]=196;
po[6]=96;
po[7]=174;
po[8]=110;
po[9]=174;
drawpoly(5,po);
pol[0]=96;
pol[1]=174;
pol[2]=89;
pol[3]=174;
pol[4]=87;
pol[5]=196;
pol[6]=97;
pol[7]=196;
pol[8]=101;
pol[9]=184;
drawpoly(5,pol);
floodfill(103,177,12);
floodfill(93,177,12);
setcolor(8);
setfillstyle(6,8);
ellipse(119,200,0,180,10,3);
ellipse(97,200,0,180,10,3);
line(109,200,129,200);
line(107,200,87,200);
floodfill(119,199,8);
floodfill(97,199,8);
getimage(78,95,130,202,p1);
putimage(78,95,p1,1);
putimage(x-5,350,p1,1);
setcolor(15);
rectangle(0,458,getmaxx()
+10,getmaxy());
setfillstyle(6,15);
floodfill(10,464,15);
setfillstyle(6,15);
fillellipse(400,100,60,40);
int v=0,v1=0,v2[1000],l1,l2,l3;
37
here1:
ch=getch();
if(ch== 77)
{
x=x+5;
//sound(3000);
}
else if (ch== 72)
{
v=350;
for(int i=y,j=y-200,k=y+107;i>=y200;i-=4,j+=4,k--)
{
if(i>=250)
{
if(x%2==0)
{
//sound(i+100);
delay(15);
if(i==y)
putimage(x,i+4,p1,1);
putimage(x,i+4,p1,1);
putimage(x,i,p1,2);
if(!kbhit())
z = 10;
while(kbhit())
{
z+=2;
if (z>100)break;
v2[i]=getch();
delay(15);
switch(v2[i])
{
case 77:
x=x+10;
for(l1=x+50;l1<=getmaxx();l1++)
{
while(kbhit())
{
int t =
getch();
switch(t)
{
case 77:
x=x+10;
putimage(x,i,p1,1);
putimage(x-10,i,p1,1);
break;
case 75:
x=x-10;
putimage(x,i,p1,1);
putimage(x+10,i,p1,1);
break;
}
}
delay(3);
setcolor(0);
putimage(x,i,p1,1);
setfillstyle(1,4);
putimage(x-10,i,p1,1);
break;
case 75:
x=x-10;
fillellipse(l1-2,l2,5,5);
if(!
kbhit())ungetch(t);
}
default:
break;
case 27:
goto
putimage(x,i,p1,1);
putimage(x+10,i,p1,1);
break;
case 32:
l2=i;
here2;
}
}
38
{
ungetch(v2[i]);
if(x%2==0)
{
}
else
{
////sound(i+100);
delay(15);
if(i==y)
putimage(x,i+4,p2,1);
putimage(x,i+4,p2,1);
putimage(x,i,p2,2);
if(!kbhit())
z = 10;
while(kbhit())
{
z+=2;
if (z>100)break;
v2[i]=getch();
delay(15);
switch(v2[i])
{
case 77:
x=x+10;
////sound(j+100);
delay(15);
if(j==y)
putimage(x,i4,p,1);
putimage(x,j4,p1,1);
putimage(x,j,p1,2);
}
else
{
////sound(i+100);
delay(15);
if(j==y)
putimage(x,i4,p,1);
putimage(x,j4,p2,1);
putimage(x,i,p2,1);
putimage(x,j,p2,2);
putimage(x-10,i,p2,1);
}
break;
case 75:
x=x-10;
}
}
}
else if (ch== 75)
{
x=x-5;
////sound(3000);
}
else if (ch== 27)
goto here2;
else goto here;
if(ch==77||ch==75)
{
if(x%2==0)
{
if(r==1)
{
if(ch==77)
putimage(x-5,y,p2,1);
if(ch==75)
putimage(x+5,y,p2,1);
}
putimage(x,y,p1,1);
putimage(x,i,p2,1);
putimage(x+10,i,p2,1);
break;
case 32:
default:
break;
case 27:
goto
here2;
}
}
ungetch(v2[i]);
}
}
if(i<250)
39
}
else
{
//radius = (x1+x2)/2;
for(;!kbhit();)
{
delay(300);
cleardevice();
//1st box
line(x1,y1,x2,y2);
line(x1,y1-20,x2,y2-20);
line(x3,y3,x4,y4);
line(x3,y3-20,x4,y4-20);
line(x1,y1,x4,y4);
line(x1,y1-20,x4,y4-20);
line(x2,y2,x3,y3);
line(x2,y2-20,x3,y3-20);
if(r==1)
{
if(ch==77)
putimage(x-5,y,p1,1);
if(ch==75)
putimage(x+5,y,p1,1);
}
if(r==0)
putimage(x10,350,p1,1);
putimage(x,y,p2,1);
}
r=1;
}
here:
nosound();
goto here1;
here2:
nosound();
}
<stdio.h>
<dos.h>
<graphics.h>
<conio.h>
#define
MAGFY
//
//
//
//2nd box
line(x1,y1,x1,y1-20);
line(x2,y2,x2,y2-20);
line(x3,y3,x3,y3-20);
line(x4,y4,x4,y4-20);
//some point which will be
moving around 3Dbox
//line(x2+40,y2-20,x2+40,y220);
//rectangle(x2,y2,x4,y4);
//
//1st Quadrant
if(x1>CEN_X && y1<CEN_Y)
x1--,y1--;
if(x1==CEN_X && y1<CEN_Y)
x1--,y1++;
if(x1<CEN_X && y1<CEN_Y)
x1--,y1++;
if(x1<CEN_X && y1==CEN_Y)
x1++,y1++;
if(x1<CEN_X && y1>CEN_Y)
x1++,y1++;
if(x1==CEN_X && y1>CEN_Y)
x1++,y1--;
if(x1>CEN_X && y1>CEN_Y)
x1++,y1--;
if(x1>CEN_X && y1==CEN_Y)
x1--,y1--;
20
class Bline
{
private:
int
CEN_X,CEN_Y,radius,X,Y,i,j;
public:
void line1(int x1,int y1,int x2,int
y2,int x3,int y3,int x4,int y4);
};
//2nd Quadrant
if(x2>CEN_X && y2<CEN_Y)
x2--,y2--;
if(x2==CEN_X && y2<CEN_Y)
x2--,y2++;
int main()
{
int GD=DETECT,GM;
Bline line1;
initgraph(&GD,&GM,"c:\tc\bgi");
//according to your own computer
(TC\BIN) Directory
line1.line1(5*MAGFY,7*MAGFY,1*MAGF
Y,3*MAGFY,3*MAGFY,1*MAGFY,7*MAG
FY,5*MAGFY);
//3rd Quadrant
if(x3>CEN_X && y3<CEN_Y)
x3--,y3--;
if(x3==CEN_X && y3<CEN_Y)
x3--,y3++;
if(x3<CEN_X && y3<CEN_Y)
x3--,y3++;
if(x3<CEN_X && y3==CEN_Y)
x3++,y3++;
if(x3<CEN_X && y3>CEN_Y)
x3++,y3++;
if(x3==CEN_X && y3>CEN_Y)
x3++,y3--;
if(x3>CEN_X && y3>CEN_Y)
x3++,y3--;
if(x3>CEN_X && y3==CEN_Y)
x3--,y3--;
getch();
restorecrtmode();
closegraph();
return 0;
}
//4th Quadrant
if(x4>CEN_X && y4<CEN_Y)
x4--,y4--;
if(x4==CEN_X && y4<CEN_Y)
x4--,y4++;
if(x4<CEN_X && y4<CEN_Y)
x4--,y4++;
if(x4<CEN_X && y4==CEN_Y)
x4++,y4++;
if(x4<CEN_X && y4>CEN_Y)
x4++,y4++;
if(x4==CEN_X && y4>CEN_Y)
x4++,y4--;
if(x4>CEN_X && y4>CEN_Y)
x4++,y4--;
if(x4>CEN_X && y4==CEN_Y)
x4--,y4--;
}
}
41
ellipse(210,133,0,360,10,10);//left eye
ball
ellipse(265,133,0,360,10,10);//right
eye ball
ellipse(210,133,0,360,3,3);//left
eye
ball
ellipse(265,133,0,360,3,3);//right eye
ball
ellipse(238,160,0,360,10,13);//nose
arc(240,125,228,312,68);//mouth
arc(240,120,230,310,72);//mouth
setfillstyle(1,4);
floodfill(238,160,15);//nose
setfillstyle(1,15);
floodfill(210,113,15);
floodfill(265,113,15);
setfillstyle(1,9);
floodfill(210,100,15);
setfillstyle(1,1);
floodfill(315,80,15);
moveto(203,220);
lineto(203,260);
lineto(183,260);
lineto(183,350);
lineto(293,350);
lineto(293,260);
lineto(273,260);
lineto(273,220);
moveto(183,350);
lineto(173,460);
lineto(213,460);
lineto(238,400);
lineto(263,460);
lineto(303,460);
lineto(293,350);
moveto(173,460);
lineto(143,478);
lineto(213,478);
lineto(213,460);
moveto(263,460);
lineto(263,478);
lineto(333,478);
lineto(303,460);
line(238,400,238,350);
//right hand
moveto(183,260);
lineto(113,310);
lineto(183,375);
moveto(183,280);
lineto(137,310);
lineto(181,353);
setfillstyle(2,13);
floodfill(190,300,15);
setfillstyle(1,5);
floodfill(223,400,15);
setfillstyle(1,5);
floodfill(253,400,15);
setfillstyle(1,6);
floodfill(173,470,15);
floodfill(303,470,15);
//fingers
secondleft();
ellipse(413.5,228,0,180,3.5,3.5);
line(420,240,433,240);
line(423,247,440,247);
line(413,240,410,228);
line(417,228,420,240);
ellipse(433,243.5,-90,90,3.5,3.5);
line(423,254,440,254);
ellipse(440,250.5,-90,90,3.5,3.5);
ellipse(430,257,-90,90,3,3);
line(413,260,430,260);
area=imagesize(409,224,444,261);
buf=malloc(area);
getimage(409,224,444,261,buf);
while(!kbhit())
{
if(i==0)
{
setfillstyle(1,15);
setcolor(15);
ellipse(210,133,0,360,10,10);//left eye
ball
ellipse(265,133,0,360,10,10);//right
eye ball
setcolor(0);
ellipse(210,133,0,360,3,3);//left
eye
ball
ellipse(265,133,0,360,3,3);//right eye
ball
floodfill(210,133,15);
floodfill(265,133,15);
setcolor(0);
putimage(391,209,buf,1);
firstleft();
setcolor(15);
secondleft();
putimage(409,224,buf,0);
i=1;
}
42
else
{
setfillstyle(1,0);
setcolor(0);
ellipse(210,133,0,360,10,10);//left eye
ball
ellipse(265,133,0,360,10,10);//right
eye ball
floodfill(210,133,0);
floodfill(265,133,0);
setcolor(15);
ellipse(210,133,0,360,3,3);//left
eye
ball
ellipse(265,133,0,360,3,3);//right eye
ball
floodfill(210,133,15);
floodfill(265,133,15);
setcolor(0);
putimage(409,224,buf,1);
secondleft();
setcolor(15);
firstleft();
putimage(391,209,buf,0);
i=0;
}
delay(300);
}
getch();
}
void firstleft()
{
moveto(293,260);
lineto(353,276);
lineto(395,223);
moveto(293,280);
lineto(355,296);
lineto(395,245);
}
void secondleft()
{
moveto(293,260);
lineto(363,280);
lineto(413,240);
moveto(293,280);
lineto(363,300);
lineto(413,260);
}
#include<string.h>
#include<math.h>
#include<graphics.h>
#include<dos.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<process.h>
#include<time.h>
void main();
int temp_life;
int
i=8,j=18,a[20]
[20],ri,rj,max=2,speed=2,op_graph=0
;
int score=0,nbox=5,life=5,level=1;
clock_t start, end;
void draw(int);
void drawbox(int);
void decr();
void genbox();
void shotbox(int);
void strt();
void putscore(int);
void lifebox(int );
int
global=9;int
open_times=0,prev_card=0,comp=0;
void card(int left,int top,int right,int
bottom)
{
int x,y;
long int er=0;
if(global==9)
er=2000;
else
er=200;
for (long double g=0;g<er;g++)
{
x=random(right);
y=random(bottom);
if(x<left)
{
g--;
continue;
}
if(y<top)
43
{
g--;
continue;
}
int number=game[z];
char string[5];
setcolor(BLACK);
settextstyle(TRIPLEX_FONT,HORIZ_DIR
,1);
outtextxy(left[z]
+25,top[z]+35,itoa(number,
string,
10));
int colors=random(15);
if(colors==1||
colors==10)
{
g--;
continue;
}
setcolor(BLACK);
if(open_times==0)
prev_card=z;
if(open_times==1)
setfillstyle(SOLID_FILL,colors);
bar3d(x-4,y4,x+4,y+4,1,1);
if(game[z]==game[prev_card])
game[prev_card]=game[z]=-100;
open_times++;
}
}
void
open(int
left[],int
top[],int
right[],int bottom[],int game[],int z)
{
sound(900);
delay(16);
nosound();
if(open_times==2)
for(int
k=0,t=19,b=99;k<4;k+
+,t+=120,b+=121)
cards
//displaying
for(int
i=0,l=55,r=125;i<4;i+
+,l+=150,r+=150)
{
sound(1000);
delay(60);
nosound();
int x;
global=909;
for(int
j=left[z],k=top[z],l=right[z],i=bottom[
z];j<=right[z];j++)
{
if(k==0
&&
i==0)
delay(90);
card(l,t,r,b);
open_times=0;
}
setfillstyle(SOLID_FILL,BLACK);
bar(j+1,k,l+1,i+1);
setcolor(WHITE);
rectangle(j+1,k,l+1,i+1);
sound(j*20);
delay(5);
nosound();
}
}
void menu(int a,int b,int c,int d,int e)
{
setcolor(a);
settextstyle(TRIPLEX_FONT,HORIZ_DI
R,7);
outtextxy(22,100,"1. BRICKS");
setcolor(b);
44
settextstyle(TRIPLEX_FONT,HORIZ_DI
R,7);
outtextxy(22,200,"2. PAIRS II");
delay(50);
line(x[z],y[z],x[k],y[k]);
nosound();
}
setcolor(c);
settextstyle(TRIPLEX_FONT,HORIZ_DI
R,4);
outtextxy(15,300,"3. HELP");
for(int h=0;h<500;h++)
{
sound(h*9);
setfillstyle( random(12),random(15) );
bar3d(random(640),random(480),rand
om(640),random(480),random(30),
random(18));
}
op_graph++;
}
void loading()
{
cleardevice();
setcolor(13);
settextstyle(TRIPLEX_FONT,HORIZ_DI
R,0);
setusercharsize(2, 1, 1, 1);
outtextxy(138,198,"LOADING");
//LOADING
setcolor(13);
settextstyle(TRIPLEX_FONT,HORIZ_DIR
,0);
setusercharsize(2, 1, 1, 1);
setcolor(d);
settextstyle(TRIPLEX_FONT,HORIZ_DI
R,4);
outtextxy(15,350,"4. CREDITS");
setcolor(e);
settextstyle(TRIPLEX_FONT,HORIZ_DI
R,4);
outtextxy(15,400,"5. EXIT");
}
void open_graph()
{
int
x_center = 320, y_center =
240, rad = 220;
int z,k,x[10],y[10];
setcolor(4);
for(int xi=30;xi>4;xi--)
{
sound(xi*20);
settextstyle(GOTHIC_FONT,HORIZ_D
IR,xi);
outtextxy(xi,220,"Gaming begins
here......");
delay(320);
cleardevice();
}
setcolor(10);
for (z=0;z<10;z++)
{
x[z]=x_center+rad*cos(36*z*3.14
159/180);
y[z]=y_center+rad*sin(36*z*3.14
159/180);
}
for (z=0;z<10;z++)
for (k=0;k<10;k++)
{
sound(k*200);
setcolor(BLUE);
rectangle(119,199,421,231);
rectangle(118,198,422,232);
setcolor(10);
for(int ii=120;ii<=420;ii++)
{
line(ii,200,ii,230);
sound(ii+1500);
delay(10);
nosound();
}
}
void gameover()
{
cleardevice();
settextstyle(GOTHIC_FONT,0,10);
cout<<"a";
for(int g=0;g<450;g++)
{
sound(g*10);
45
delay(3);
setcolor(LIGHTRED);
if(g%20==0)
{cleardevice();setcolor(12);}
outtextxy(70,g,"game over");
nosound();
}
main();
}
if(move<1)move=5;
if(move>5)move=1;
if(move==1) menu(10,8,8,8,8);
if(move==2) menu(8,10,8,8,8);
if(move==3)
menu(8,8,10,8,8);
//7 gray 14-yellow
if(move==4) menu(8,8,8,10,8);
if(move==5) menu(8,8,8,8,10);
void main()
{
int gdriver = DETECT, gmode;
initgraph(&gdriver,
&gmode,
"c:\tc\bgi");
cleardevice();
if(op_graph==0) open_graph();
lion=getch();
sound(1700);
delay(7);
nosound();
}
cleardevice();
if(move==5) exit(0);
settextstyle(TRIPLEX_FONT,HORIZ_DI
R,0);
for(int si=1;si<10;si++)
{
sound(si*850);
setcolor(LIGHTCYAN);
setusercharsize(si,1,si,1);
outtextxy(13,150,"GAME PACK");
delay(250);
nosound();
cleardevice();
}
randomize();
setfillstyle(3,RED);
bar3d(0,
0,639,479,
0);//background
if(move==1)
{
//bricks video game shooting prg.
loading();
int gd=DETECT,gm;
initgraph(&gd,&gm,"D:\CPP\TC\BGI");
setcolor(10);
outtextxy(500,75,"score :");
outtextxy(500,150,"level :");
outtextxy(500,225,"Life");
lifebox(10);
putscore(10);
strt();
}
/*
PAIRS II
0,
setcolor(WHITE);
settextstyle(4,HORIZ_DIR,7);
outtextxy(220,25,"MENU");
char lion;
int move=5;
*/
if(move==2)
{
int
a[8],game[16],i=0,z=8,k,flag,temp,t,b,
l,j=0,u=0,o=0,p=0;
int
left[16],top[16],right[16],bottom[16];
lion=getch();
while(lion!=27)
{
if(lion==13) break;
if(lion=='P') move++;
if(lion=='H') move--;
46
randomize();
else
{
a[i++]=temp;
game[z++]=temp;
}
}
loading();
for(int ii=0;ii<=640;ii++)
line(ii,0,ii,480);
setcolor(1);
for(ii=0;ii<=640;ii++)
line(0,ii,640,ii);
setcolor(3);
for(ii=640;ii>=0;ii--)
line(ii,0,ii,480);
setcolor(BLUE);
for(ii=640;ii>=0;ii--)
line(0,ii,640,ii);
setcolor(RED);
for(ii=0;ii<=640;ii++)
{
sound(ii*5);
line(640,ii,ii,480);
delay(5);
nosound();
}
setfillstyle(11,RED);
setcolor(YELLOW);
bar(0, 0,638,478);//backgrond
for(k=0,t=19,b=99;k<4;k+
+,t+=120,b+=121)
//displaying
cards
for(i=0,l=55,r=125;i<4;i+
+,l+=150,r+=150)
{
left[j++]=l;
top[u++]=t;
right[o++]=r;
bottom[p++]=b;
sound(i*200);
card(l,t,r,b);
}
nosound();
for(int you=1;you<=20;you++)
{
if(you%2)
setcolor(LIGHTGREEN);
else
setcolor(RED);
for(k=0,t=15,b=103;k<4;k+
+,t+=120,b+=121)
//high light
cursor
setcolor(0);
for(ii=0;ii<=640;ii++)
{
sound(ii*5);
line(0,ii,640,480);
delay(2);
nosound();
}
//selecting
8
nos
(1-100)without
repeating
randomize();
a[0]=random(100);
while(i!=8)
{
redo:
temp=random(100);
flag=1;
for(k=0;k<=i;k++)
if(a[k]==temp){flag=5;break;}
if (flag==5) goto redo;
47
for(i=0,l=50,r=130;i<4;i+
+,l+=150,r+=150)
for(int we=1;we<=5;we++)
{
sound(we*900);
rectangle(l-we,t-we,r+we,b+we);
nosound();
}
delay(100);
}
{
setcolor(BLACK);
if(m==pntr)
{
setcolor(LIGHTGREEN);
if(game[pntr-1]==-100)
setcolor(LIGHTRED);
}
setcolor(0);
char ch=getch();
int pntr=0,turn=1;
for(int
we=1;we<=5;we++)
while(ch!=27)
{
rectangle(lwe,t-we,r+we,b+we);
m++;
if(ch=='M') pntr++;
if(ch=='K') pntr--;
if(ch=='H') pntr=pntr-4;
if(ch=='P') pntr+=4;
}
if(var_new34)
if(ch==13)
open(left,top,right,bottom,game,pntr1);
//open card
if(pntr>=17)
pntr=pntr-16;
if(pntr<1)
pntr=pntr+16;
int y=0;
for(int wer=0;wer<16;wer++)
if(game[wer]==-100)
y++;
if(y==16) gameover();
int m=1;
if(open_times==1)
if(pntr-1==prev_card)
{
ch=getch();
continue;
}
int var_new34=9;
ch=getch();
sound(2500);
delay(6);
nosound();
}
if(ch==27) main();
if(game[pntr-1]==-100)
var_new34=0;
end:
if(move==3)
{
char ctrl;
do
{
char help_topic[]="
for(k=0,t=15,b=103;k<4;k+
+,t+=120,b+=121)
//high light
cursor
for(i=0,l=50,r=130;i<4;i+
+,l+=150,r+=150)
48
*******************HELP***************
******
USERS
MANUAL
1. PAIRS II
The general outline of the game is as
follows.
*
It is basically a card game.
* One can flip and see only two cards
at a
time simultaneously in the given set of
cards.
* One has to match the
cards in the given set.
* One wins the game if all the matches
are made
correctly.
* This game is a time-trailed game i.e.
one's score becomes
invalid if it exceeds the tine limit.
* To navigate one can use the arrow
keys.
* To open the card you can hit enter.
";
char help_brick[]="
BRICKS
The general outline is as follows.
*It is
a brick game.
*It consist of a shooting box and we
have to shoot the
bricks.
*To move the shooting box right press
the right direction key and
to move left press the left direction
key.
*To shoot press the up
direction key.
*Basically there are 5 levels in the
game.
*You can win
each level when u reach the score of
2500.
*When u hit each brick you get
25 points.
ctrl=getch();
}while(ctrl!=27&&ctrl<28&&ctrl>25);
if(ctrl==27) main();
}
if(move==4)
{
cleardevice();
setcolor(LIGHTGREEN);
settextstyle(TRIPLEX_FONT,HORIZ_DI
R,0);
setusercharsize(1,1,1,1);
setcolor(LIGHTGREEN);
settextstyle(TRIPLEX_FONT,HORIZ_DI
R,6);
outtextxy(320,250,"&");
setcolor(LIGHTGREEN);
rectangle(1,1,638,478);//background
for(int ab=5,bc=420;ab<350;ab+
+,bc--)
{
sound(ab*620);
setfillstyle(6,BLACK);
bar(5, 130,637,250);
49
bar(9,350,635,450);
switch(op)
{
case 77:
draw(0);
if(i<15) i++;
draw(10);
break;
case 75:
draw(0);
if(i>0) i--;
draw(10);
break;
case 72:
shotbox(i);
break;
case 27:main();
}
}
setcolor(random(15));
settextstyle(TRIPLEX_FONT,HORIZ_DI
R,6);
settextstyle(TRIPLEX_FONT,HORIZ_DI
R,6);
sound(bc*2000);
delay(1);
nosound();
}
sleep(1);
main();
}
}//void main's block
void strt()
{
int op;
setcolor(0);
line(60+i*25,j*25,60+rj*25,ri*25);
}
}
void draw(int color)
{
int c;
c=getcolor();
setcolor(color);
setfillstyle(INTERLEAVE_FILL,color);
bar(50+25*i,j*25,75+25*i,j*25+25);
rectangle(50+25*i,j*25,75+25*i,j*25+
25);
setcolor(14);
rectangle(50,0,450,475);
for(ri=0;ri<19;ri++)
for(rj=0;rj<16;rj++)
a[ri][rj]=0;
randomize();
genbox();
drawbox(12);
start=clock();
op=getch();
while(1)
{
while(!kbhit())
{
setcolor(c);
}
end = clock();
if((end - start) / CLK_TCK > speed)
{
decr();
start=clock();
}
void genbox()
{
int x;
for(x=0;x<nbox;x++)
{
rj=rand()%16;
if(a[0][rj]==1) x--;
a[0][rj]=1;
}
}
}
while(kbhit())
{
op=getch();
50
void decr()
{
if(max<17)
{
drawbox(0);
for(ri=max;ri>=0;ri--)
for(rj=0;rj<16;rj++)
a[ri+1][rj]=a[ri][rj];
for(rj=0;rj<16;rj++)
a[0][rj]=0;
genbox();
drawbox(12);
}
else
{
printf("a");
lifebox(0);
--life;
lifebox(10);
if(life==0) gameover();
file://for(r=18;r>=ri;r--)
setcolor(13);
line(60+i*25,j*25,60+rj*25,ri*25);
sound(480);
delay(25);
nosound();
putscore(0);
if(score%100==0 && score!=0 )
{
putscore(0);
level++;
putscore(10);
if(speed==1)
if(nbox==5) nbox=7;
else if(nbox==7) nbox=9;
else if(nbox==9) nbox=11;
else
{
setcolor(10);
drawbox(12);
cout<<"a";
cleardevice();
gameover();
main();
}
else speed--;
putscore(0);
score++;
putscore(10);
strt();break;}
else{
score++;
putscore(10);
break;}}
drawbox(12);
setcolor(0);
line(60+i*25,j*25,60+rj*25,ri*25);
else {drawbox(0);strt();}
}
}
void drawbox(int c)
{
setcolor(c);
for(ri=0;ri<18;ri++)
for(rj=0;rj<16;rj++)
if(a[ri][rj]==1)
{
max=ri;
setfillstyle(INTERLEAVE_FILL,c);
bar(50+rj*25,ri*25,50+rj*25+25,ri*
25+25);
if(c!=0) setcolor(14);
rectangle(50+rj*25,ri*25,50+rj*25
+25,ri*25+25);
}
setcolor(14);
rectangle(50,0,450,475);
}
51
char*img1,*img2;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\tc\bgi");
x=getmaxx()/2,y=getmaxy()/2;
}
void putscore(int color)
{
char str[20];
int c;
c=getcolor();
setcolor(color);
itoa(score*25,str,10);
outtextxy(550,75,str);
itoa(level,str,10);
outtextxy(550,150,str);
setcolor(c);
}
backfrm();
splace_form();
initmouse();
while(1)
{
getmousepos(&stat ,&px ,&py);
delay(11);
if(stat==1)
break;
}
mainfrm();
backfrm();
dpaddal();
backfrm();
dball();
backfrm();
lavel(1);
printlevel();
restrictmouseptr(16,500,540,500);
while(!kbhit())
{
delay(10);
movepaddal();
moveball();
}
getch();
}
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
#include<dos.h>
#include<mouse.h>
#include<string.h>
//---------------------move ball---------------///
moveball()
{
setfillstyle(SOLID_FILL,1);
bar(bx-2,by-2,bx+12,by+12);
putimage(bx,by,ball,COPY_PUT);
balldir();
if(!strcmp(dir,"bl"))
bx=bxspeed,by+=byspeed;
if(!strcmp(dir,"br"))
bx+=bxspeed,by+=byspeed;
int
x,y,a,b,i,area,px,py,stat,bx=20,by=20
0,bxspeed=2,byspeed=2,scr=0;
static int sq[15][15];
char
*paddal,*ball,dir[3]="br",score[4]="ss"
;
void main()
{
52
if(!strcmp(dir,"tl"))
bx=bxspeed,by-=byspeed;
if(!strcmp(dir,"tr"))
bx+=bxspeed,by-=byspeed;
}
movepaddal()
{
setfillstyle(SOLID_FILL,1);
bar(16,450,612,460);
getmousepos(&stat ,&px ,&py);
putimage(px,450,paddal,COPY_PUT);
}
//-----------------------ball
diraction---------------//
balldir()
{
if(!strcmp(dir,"bl")
&&
by>440)
btp("tl");
if(!strcmp(dir,"br")
&&
by>440)
btp("tr");
if(!strcmp(dir,"tl")
&&
by<122&&sq[(by-55)/15][(bx16)/50]==0)
bts("bl");
if(!strcmp(dir,"tr")
&&
by<122&&sq[(by-55)/15][(bx16)/50]==0)
bts("br");
if(!strcmp(dir,"bl")
by<122&&sq[(by-55)/15][(bx16)/50]==0)
bts("tl");
if(!strcmp(dir,"br")
by<122&&sq[(by-55)/15][(bx16)/50]==0)
bts("tr");
if(!strcmp(dir,"tr")
&&
strcpy(dir,"br"),sndplay(500);
if(!strcmp(dir,"tl")
&&
strcpy(dir,"bl"),sndplay(500);
//-----------------paddal--------------------//
dpaddal()
{
int area;
setfillstyle(SOLID_FILL,15);
fillellipse(x,y,35,4);
area=imagesize(x-35,y-4,x+35,y+4);
// find area of image
paddal=malloc(area);
getimage(x-35,y-4,x+35,y+4,paddal);
//get image in *paddal
}
//------------------ball------------------------//
dball()
{
int area;
setfillstyle(SOLID_FILL,4);
fillellipse(x,y,5,5);
area=imagesize(x-5,y5,x+5,y+5); // find area of image
ball=malloc(area);
getimage(x-5,y-5,x+5,y+5,ball);
//get image in *ball
}
&&
&&
by<40)
by<40)
//-----------------------print
squar--------------//
squar(int a,int b ,int norm)
{
setfillstyle(SOLID_FILL,13);
if(b%2)
setfillstyle(SOLID_FILL,3);
if(norm==0)
setfillstyle(SOLID_FILL,1);
bar(b*50+16,a*15+55,b*50+63,a*
15+54+13);
if(!strcmp(dir,"bl")
&&
bx<20)
strcpy(dir,"br"),sndplay(500);
if(!strcmp(dir,"tr")
&&
bx>600)
strcpy(dir,"tl"),sndplay(500);
if(!strcmp(dir,"tl")
&&
bx<20)
strcpy(dir,"tr"),sndplay(500);
if(!strcmp(dir,"br") && bx>600)
strcpy(dir,"bl"),sndplay(500);
}
setfillstyle(SOLID_FILL,1);
bar(100,16,140,30);
setcolor(15);
settextstyle(2,0,6);
//-------------------------move
paddal---------------///
53
outtextxy(20,15,"Score -");
itoa(scr,score,10);
outtextxy(100,15,score);
line(xl,yt,xl,yb);
line(xl,yt,xr,yt);
}
}
/* Set_square */
}
//--------------------------sound-------------------------//
sndplay(int a)
{
sound(a);
delay(20);
nosound();
}
//-------------------------ball
tuoch
paddal---------------//
btp(char s[3])
{
if(bx>=px&&bx<=px+10)
bxspeed=2,byspeed=1,strcpy(dir,"tl")
;
if(bx>=px+11&&bx<=px+30)
bxspeed=2,byspeed=2,strcpy(dir,"tl")
;
if(bx>=px+31&&bx<=px+35)
bxspeed=1,byspeed=2,strcpy(dir,"tl")
;
if(bx>=px+35&&bx<=px+40)
bxspeed=1,byspeed=2,strcpy(dir,"tr")
;
if(bx>=px+41&&bx<=px+60)
bxspeed=2,byspeed=2,strcpy(dir,"tr")
;
if(bx>=px+61&&bx<=px+70)
bxspeed=2,byspeed=1,strcpy(dir,"tr")
;
sndplay(500);
if(bx<=px||bx>=px+70)
getch(),strcpy(dir,s) ;
}
//-------------------------ball
tuoch
square---------------//
bts(char s[3])
{ scr+=100;
squar((by-55)/15,(bx-16)/50,0);
sq[(by-55)/15][(bx-16)/50]=1;
strcpy(dir,s) ;
sndplay(500);
win();
printlevel();
//-----------------------backfrm-------------------//
backfrm()
{
setfillstyle(SOLID_FILL,1);
bar(15,15,615,465);
button(0,0,15,480,1);
button(615,0,630,480,1);
button(0,0,630,15,1);
button(0,465,630,480,1);
}
//---------------SPLACE
FORM---------------------------//
splace_form()
{
setcolor(4);
settextstyle(4,0,6);
outtextxy(x-145,y-200, " GAME");
outtextxy(x-145,y-50, "DX==BALL");
setcolor(2);
outtextxy(x-145,y-150, "--------");
settextstyle(1,0,1);
}
//-------------------------BUTTON-------------------------//
button(int xl,int yt,int xr,int yb, int
status)
{
setfillstyle(SOLID_FILL, LIGHTGRAY);
bar(xl, yt, xr, yb);
if (status) {
setcolor(WHITE);
line(xl,yt,xl,yb-1);
line(xl,yt,xr-1,yt);
setcolor(DARKGRAY);
line(xr,yb,xl,yb);
line(xr,yb,xr,yt);
}
else {
setcolor(DARKGRAY);
54
//
else
sndplay(1500),getch(),strcpy(dir,"tl") ;
}
int temp=0;
for(a=0;a<5;a++)
for(b=0;b<12;b++)
if( sq[a][b]==1) temp++;
//----------------------mainform--------------------------//
mainfrm()
{
backfrm();
setcolor(4);
settextstyle(4,0,6);
outtextxy(x-145,y-200, " GAME");
outtextxy(x-145,y-100, "DX==BALL");
setcolor(2);
outtextxy(x-145,y-150, "---------");
outtextxy(x-145,y-50, "---------");
settextstyle(1,0,3);
outtextxy(x-170,y+20, "do you wnat
to play the game");
setcolor(15);
outtextxy(x170,y+40,"------------------------");
if(temp==60)
{
setcolor(4);
settextstyle(4,0,4);
outtextxy(x-145,y, " You Win The
Game");
initmouse();
showmouseptr();
while(1)
{
getmousepos(&stat ,&px ,&py);
delay(11);
if(stat==1)
break;
}
mainfrm();
lavel(2);
printlevel();
restrictmouseptr(16,500,540,500);
}
button(x+100,y+100,x+150,y+125,1)
;
button(x-100,y+100,x-50,y+125,1);
setcolor(15);
settextstyle(2,0,6);
outtextxy(x-90,y+100, " No");
outtextxy(x+110,y+100,"Yes");
showmouseptr();
while(1)
{
getmousepos(&stat ,&px ,&py);
if(stat==1&&px>=420&&px<=470
&&py>=340 &&py<=365)
break;
if(stat==1&&px>=220&&px<=270
&&py>=340 &&py<=365)
exit();
// gotoxy(10,10);
// printf("%d ,%d ,%d",px,py ,stat);
}
hidemouseptr();
backfrm();
}
//-------------------win()-------------------------------//
win()
{
}
//-------------------------lavel-----------------------//
lavel(int lbl)
{
switch(lbl)
{
case 1:
for(a=0;a<5;a++)
for(b=0;b<12;b++)
sq[a][b]=0;
break;
case 2:
for(a=0;a<5;a++)
for(b=0;b<12;b++)
if(b<=a||b>a+5)
sq[a][b]=1;
break;
default:
for(a=0;a<5;a++)
for(b=0;b<12;b++)
if(b<=a||b>a+5)
sq[a][b]=1;
}
}
55
//------------------------print
level---------------//
printlevel()
{
for(a=0;a<5;a++)
for(b=0;b<12;b++)
{
if(sq[a][b]==0)
squar(a,b,1);
outtextxy(32,205,"* * * * * * * * * * * *
***************
*
* * * * * * * * * * * * * * * * * * *");
setfillstyle(XHATCH_FILL,i++);
delay(200);
floodfill(2,9,15);
if(i>=15)
i=0;
}
getch();
cleardevice();
closegraph();
}
/*******************END
OF
INTRO.H******************************
**/
// sq[a][b]=0;
}
}
/* main file:
blinky.h*/
#
#
#
#
#
#
#
#
settextstyle(1,0,1);
outtextxy(245,238,"DESIGNER");
while(!kbhit())
{
setcolor(i);
settextstyle(2,0,0);
outtextxy(32,170,"* * * * * * * * * * * *
**************
*
* * * * * * * * * * * * * * * * * * * *");
outtextxy(32,178,"*
*");
outtextxy(32,186,"*
*");
outtextxy(32,196,"*
*");
include
include
include
include
include
include
include
include
<iostream.h>
<conio.h>
<graphics.h>
<dos.h>
<time.h>
<stdlib.h>
<intro.h>
<backend.h>
int poly[8],toggle=1,z;
void
blink(int
fuzzy[],int
size,int
lazy,int paint)
{
for(int i=0;i<size;i++)
{
randomize();
z=random(5);
// random
if(!z) z=1;
poly[0]=fuzzy[i];
poly[1]=z*fuzzy[i+1];
poly[2]=0+fuzzy[i];
poly[3]=30+z*fuzzy[i+1];
56
poly[4]=30+fuzzy[i];
poly[5]=30+z*fuzzy[i+1];
cout<<"
4.Use default settings and exit";
cout<<"
5.Exit simulator";
cout<<"
Enter your choice--->";
cin>>ch;
switch(ch)
{
case 1:
cout<<"
choose type of blink rate:
slow/slow/fast/very
fast(enter
1/2/3/4)--->";
cin>>ch;
if(ch==1)
lazy=1000;
if(ch==2)
lazy=600;
if(ch==3)
lazy=100;
if(ch==4)
lazy=10;
break;
poly[6]=30+fuzzy[i];
poly[7]=0+z*fuzzy[i+1];
if(paint==1)
paint=z;
setfillstyle(1,paint);
fillpoly(4,poly);
delay(lazy);
setfillstyle(1,0);
fillpoly(4,poly);
}
}
int roundoff(int x)
{
int temp=0;
if(x%30!=0)
{
if(x<30)
return 30;
else
{
temp=x%30;
return(30*temp);
}
}
else return x;
}
very
case 2:
cout<<"
blink color: random or fixed color ?
(enter 1/2)--->";
cin>>paint;
break;
case 3:
cout<<"roughly estimate the
no. of blinks per second(multiples of
ten,max
50)--->";
cin>>size;
break;
case 4:
lazy=100;
paint=15;
size=20;
break;
case 5:
backend();
exit(0);
}
initgraph(&gd,&gm,"");
void main()
{
int gd,gm;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"");
intro();
int ch,lazy,paint,size;
flag:
cout<<"
CONTROL PANEL";
cout<<"
1.Change blink rate";
cout<<"
2.Change blink color";
cout<<"
3.Specify no. of blinks per second";
57
outtextxy(220,250,"HAVE A NICE
DAY !");
int i=0;
while(!kbhit())
{
delay(200);
setfillstyle(XHATCH_FILL,i++);
floodfill(2,9,15);
if(i>=15)
i=0;
}
for(int i=0;i<630;i+=30)
{
for(int j=0;j<470;j+=30)
{ delay(10);
rectangle(i,j,i+30,j+30);
}
}
int fuzzy[50],dummy=0;
while(!kbhit())
{
randomize();
for(i=0;i<size;i++)
{
dummy=random(480);
fuzzy[i]=roundoff(dummy);
}
dummy=random(480);
fuzzy[i+1]=roundoff(dummy);
blink(fuzzy,size,lazy,paint);
}
closegraph();
goto flag;
getch();
closegraph();
}
getch();
}
Code :
/**************************END
BLINKY.H*************************/
OF
#include <iostream.h>
#include <conio.h>
#include
//defining toupper
#
include
//exit(0)
# include <dos.h>
# include <stdlib.h>
# include <graphics.h>
# include <stdio.h>
/* back end:
BACKEND.H*/
# include <graphics.h>
# include <conio.h>
# include <dos.h>
void backend()
{
int gd=DETECT,gm;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\tc\bgi");
rectangle(0,5,630,400);
rectangle(12,15,618,390);
settextstyle(1,0,5);
outtextxy(180,60,"THANK YOU");
settextstyle(1,0,3);
outtextxy(160,128,"HOPE U LIKED IT
!");
settextstyle(1,0,1);
# define NULL 0
# define YES 1
# define NO 0
#define ESC 0x1b
Define the escape key
<ctype.h>
<process.h>
/*
*/
58
int GraphDriver;
/*
The
Graphics device driver
*/
int GraphMode;
/*
The
Graphics mode value
*/
int MaxXX, MaxYY;
/* The
maximum resolution of the screen */
int MaxColors;
/*
The
maximum # of colors available */
int ErrorCode;
/*
Reports
any graphics errors
*/
struct palettetype palette;
/* Used to read palette info*/
{
union REGS in,out;
in.x.ax=33;
int86(0x33,&in,&out);
}
void MousePos(int* x,int* y,int* click)
{
//stores back (x,y) values and
click type
//click=1: left click
//2: right click
//3: middle click
union REGS in,out;
in.x.ax=3;
int86(0x33,&in,&out);
*click=(int)out.x.bx;
*x=(int)out.x.cx;
*y=(int)out.x.dx;
}
/*-----------------------End
Of
Mouse
Methods----------*/
main
()
{
InitMouse();
/* get the maximum value of x
and y coordinates of the screen */
MaxX = getmaxx() ;
MaxY = getmaxy() ;
/* finding the center of the
screen */
MidX = MaxX / 2 ;
MidY = MaxY / 2 ;
case 'F' :
case 'f' :
speed = 3 ;
}
/* draw the four layer of bricks,
the paddle and the ball */
rectangle ( 0, 0, MaxX, MaxY 12 ) ;
bricks() ;
rectangle ( MidX - 25, MaxY - 7 12, MidX + 25, MaxY - 12 ) ;
floodfill ( MidX, MaxY - 1 - 12, 12
);
circle ( MidX, MaxY - 13 - 12,
12 ) ;
//
fillellipse ( MidX, MaxY - 13 12,12,12 ) ;
floodfill ( MidX, MaxY - 10 - 12,
12 ) ;
/* memory allocation for storing
the image of the paddle */
areareq = imagesize ( MidX 12, MaxY - 18, MidX + 12, MaxY - 8 ) ;
}
else
{
if
( BallY > 10 )
{
max = 20 ;
layer = 1 ;
}
else
{
while ( 1 )
{
flag = 0 ;
max = 10 ;
/* saving current x and y
coordinates of the ball */
OldX = BallX ;
OldY = BallY ;
layer = 0 ;
}
}
}
}
/* if the ball hits the right
boundary, move it to the left */
if ( BallX > ( MaxX - 24 - 1
))
{
bell ( 5 ) ;
BallX = MaxX - 24 1;
dx = -dx ;
}
/*
according
to
the
position of ball the layer of bricks is
determined
*/
if ( BallY > 40 )
{
max = 50 ;
layer = 4 ;
}
else
{
if ( BallY > 30 )
{
max = 40 ;
layer = 3 ;
}
else
{
if ( BallY >
20 )
{
max
= 30 ;
layer
=2;
/* if the ball
does not touch a brick at the top, left
or right */
if ( !flag )
{
/*
check if the ball has moved above the
current layer */
if
( BallY < totallayer[layer - 1] )
{
/* if there is a brick */
putimage ( OldX, OldY, m1,
OR_PUT ) ;
BallX = BallX + i ;
flag = 1 ;
/*
erase the image at the old coordinates
*/
break ;
}
/*
check whether there is a brick to the
left of the ball */
if
( bri[layer][ ( BallX - i + 10 ) / 32 ] ==
0)
{
/*
place the image of the ball at the new
coordinates */
putimage ( BallX, BallY, m1,
XOR_PUT ) ;
BallX = BallX - i ;
/*
flag = 1 ;
break ;
( speed ) ;
delay
}
}
/*
carry on moving the ball */
continue ;
62
cout<< score;
display latest score */
}
/* when ball touch
the brick control comes to this point */
bell ( 5 ) ; /* play
music */
/*
erase
/*
the
/* if
touched brick */
bottom */
delbrick ( ( BallX +
10 ) / 32, layer ) ;
/* if the brick hit is
on the extreme right */
if ( ( BallX + 10 ) /
32 == 19 )
line ( MaxX,
0, MaxX, 50 ) ;
/* redraw right
boundary */
/* if paddle missed
the ball */
if ( BallX < Base1 20 || BallX > Base1 + 50 )
{
/* continue
the decrement of the ball */
while ( BallY
< 177 )
{
/*
erase the image of the ball at the old
coordinates */
/* set appropriate
array element to 1 to indicate absence
of brick
*/
bri[layer][ ( BallX +
10 ) / 32 ] = 1 ;
BallY = BallY +
1 ; /* update the y coordinate */
dy = -dy ;
/*
change the current direction of the ball
*/
score += 10 ; /*
increment the score by 10 */
gotoxy ( 16, 25 ) ;
/*
saveing current x and y coordinates of
the ball */
OldX
= BallX ;
OldY
= BallY ;
63
cout<<"Press
any
continue ...
";
/*
update ballx and bally to move the
ball in correct direction */
BallX
= BallX + dx ;
BallY
= BallY + dy ;
}
key
to
decrement
chances */
the
total
chance-- ; /*
number of
restorecrtmode() ;
score -= 10 ;
/* decrement 10 points for each ball
lost */
gotoxy ( 16,
25 ) ;
cout<<
score; /* display latest score */
bell ( 1 ) ;
closegraph();
Close the graphics mode */
Initialize();
the graphics mode */
/*
/*
Intialize
setbkcolor(4);
SayGoodbye();
/*
Display the That's all Folks message */
/* erase one
of the available balls */
if ( chance )
closegraph();
/*
Return the system to text mode */
exit
(0);
}
}
/*
if
ball
is
collected on paddle */
bell ( 4 ) ;
BallY = 180 12 ; /* restore the y coordinate of ball
*/
dy = -dy ; /* move
the ball upwards */
}
/* if all the
balls are lost */
if ( !chance )
{
gotoxy ( 45, 25 ) ;
64
*/
//
//
//Base1 - 25 ;
if ( oo.h.ah == 75 )
Base1
=
bell ( 2 ) ;
SayGoodbye();
/* Display the That's all
Folks message */
closegraph() ;
restorecrtmode() ;
exit ( 0 ) ;
}
/* introduce delay for few
seconds */
delay ( speed ) ;
65
rectangle(1,1,600,195);
setbkcolor(4);
/* set the textstyle for
displaying instruction */
changetextstyle
( DEFAULT_FONT, HORIZ_DIR, 0 ) ;
outtextxy ( 150, 55, "
Instructions
");
changetextstyle
(4,
HORIZ_DIR, 5 );
outtextxy ( 130, 0, " B R I
C K S" ) ;
changetextstyle
( DEFAULT_FONT, HORIZ_DIR, 0 ) ;
outtextxy ( 30, 68, "Use
mouse to move the paddle" ) ; // can
also
use
KEYBOARD after activating keyboard
event (use LEFT and RIGHT keys to
move
the PADDLE
outtextxy ( 30, 88, "If you
don't collect the ball on the paddle,
you
lose the ball." ) ;
outtextxy ( 30, 108, "On
loosing a ball you loose 10 points." ) ;
outtextxy ( 30, 128, "On
taking a brick you gain 10 points." ) ;
changetextstyle(7,
HORIZ_DIR, 3);
outtextxy ( 100, 148,
"Press any key to continue ..." ) ;
bell ( 3 ) ; /* ring music */
fflush ( stdin ) ;
// if ( getch() == 0 )
//
getch() ;
MousePos(&Base1,&ydummy,&clickdu
mmy);
/* if paddle goes beyond
left boundary */
if ( Base1 < 0 )
Base1 = 0 ;
/* if paddle goes
beyond right boundary */
if ( Base1 > 589 )
Base1 = 589 ;
/* put the image of
the paddle at the proper position */
putimage ( Base1, Base2,
m2, XOR_PUT ) ;
//
}
}
closegraph();
Initialize();
SayGoodbye();
/*
Give user the closing screen
*/
closegraph();
/*
Return the system to text mode */
return(0);
}
/* This function creates the opening
screen and displyed instruction
related to the game
along with two option play or exit.After
selecting the paly option it
display
three levels of the game and
according to your choice you can
select
any
level.
This selected level is returned by this
function to the mainprogram
according to which
the speed is assigned to the ball*/
closegraph();
initgraph ( &graphdriver,
&graphmode, "c:\tc\bgi" ) ;
rectangle(2,2,620,195);
setbkcolor(4);
/* display the main menu */
while ( 1 )
{
screen()
{
int i, j, lx = 0, ly = 0, ch ;
66
changetextstyle(7,HORIZ_DIR,3);
outtextxy ( 60, 8, "Select the
level for play:" ) ;
outtextxy ( 150,50, "Slow ( S )" )
;
outtextxy ( 150, 100, "Medium (
M )" ) ;
outtextxy ( 150, 150, "Fast ( F )"
);
changetextstyle(4,HORIZ_DIR,5);
outtextxy
(
60,
8,
"Options Available:" ) ;
outtextxy ( 150, 55, "Play
( P )" ) ;
outtextxy ( 150, 125,
"Exit ( E )" ) ;
ch = 0 ;
clearviewport() ;
/* return the choice selected by
the user */
return ( ch ) ;
}
/* if a special key is
hit, flush the keyboard buffer */
if ( ( ch = getch() )
== 0 )
getch() ;
else
ch
=
toupper ( ch ) ;
/* store the
uppercase of the choice
made*/
}
if ( ch == 'P' )
break ;
if (ch == 'E')
exit ( 0 ) ;
}
// setviewport ( 1, 125 - 12, MaxX
- 1, MaxY - 1, 1 ) ;
// clearviewport() ;
closegraph();
initgraph
(
&graphdriver,
&graphmode, "c:\tc\bgi" ) ;
rectangle(2,2,620,195);
setbkcolor(4);
lx = lx + 32 ;
}
lx = 0 ;
ly = ly + 10 ;
}
67
case 1 :
for ( i = 0 ; i < 6 ;
i++ )
{
sound
( wave[i] * 1 ) ;
delay ( 30 ) ;
}
nosound() ;
break ;
*
case 2 :
for ( i = 0 ; i < 15 ;
b
i++ )
{
n = random
b
(6);
sound
( wave[n] * 2 ) ;
delay ( 100 )
;
}
nosound() ;
break ;
b
case 3 :
// while ( !kbhit() )
{
n = random
b
(6);
sound
( wave[n] * 2 ) ;
b
delay ( 100 )
;
}
nosound() ;
/*
flush
the
keyboard buffer */
/* plays different types of music */
bell ( int m_no )
{
/* natural frequencies of 7 notes
*/
float wave[6] = { 120.81,
136.83, 144.81, 154.61, 216, 240 } ;
int n, i ;
if ( getch() == 0 )
getch() ;
break ;
case 4 :
for ( i = 5 ; i >= 0 ;
i-- )
{
switch ( m_no )
{
sound
( wave[i] * 4 ) ;
68
delay ( 15 ) ;
}
nosound() ;
break ;
}
/*
*/
/*
SAYGOODBYE: Give a closing
screen to the user before leaving.
*/
/*
*/
case 5 :
sound ( wave[2] *
5);
delay ( 50 ) ;
nosound() ;
}
}
/*
void SayGoodbye(void)
{
struct viewporttype viewinfo;
Structure to read viewport
int h, w;
*/
/*
INITIALIZE:
Initializes
the
graphics system and reports
*/
/*
any errors which occured.
*/
/*
*/
/*
*/
void Initialize(void)
{
int xasp, yasp;
/*
Used to read the aspect ratio*/
GraphDriver = DETECT;
/*
Request auto-detection */
initgraph(
&GraphDriver,
&GraphMode, "c:\tc\bgi" );
ErrorCode = graphresult();
/* Read result of initialization*/
if( ErrorCode != grOk ){
/*
Error occured during init */
printf(" Graphics System Error:
%s
", grapherrormsg( ErrorCode ) );
exit( 1 );
}
h = viewinfo.bottom - viewinfo.top;
w = viewinfo.right - viewinfo.left;
cleardevice();
// StatusLine( "Press any key to
EXIT" );
getch();
cleardevice();
Clear the graphics screen */
/*
getpalette( &palette );
/*
Read the palette from board
*/
MaxColors = getmaxcolor() + 1;
/* Read maximum number of
colors*/
//}
/*
*/
/*
CHANGETEXTSTYLE: similar to
settextstyle, but checks for
*/
/*
errors that might occur while
loading the font file.
*/
MaxXX = getmaxx();
MaxYY = getmaxy();
/* Read size of screen
*/
69
/*
outtextxy(140,
WELCOME");
outtextxy(170,50,"
outtextxy(140,100,"
changetextstyle(7,
3);
bell(3);
outtextxy(110, 160,
key to continue...");
*/
void changetextstyle(int
direction, int charsize)
{
int ErrorCode;
font,
int
graphresult();
/*
clear error code
*/
settextstyle(font, direction, charsize);
ErrorCode = graphresult();
/* check result
*/
if( ErrorCode != grOk ){
/*
if
error occured
*/
closegraph();
printf(" Graphics System Error:
%s
", grapherrormsg( ErrorCode ) );
exit( 1 );
}
}
0,
"
TO ");
BRICKS");
HORIZ_DIR,
"Press any
<graphics.h>
<stdlib.h>
<stdio.h>
<conio.h>
<dos.h>
<time.h>
<bios.h>
#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
#define ENTER 13
#define ESC 27
#define YES 1
#define NO 0
int
x=320,y=100,marble=32,marble_colo
r=12;
void *p;
size_t area;
//
Matrix of board
int board[7][7]=
{
{-1,-1,1,1,1,-1,-1},
{-1,-1,1,1,1,-1,-1},
{ 1, 1,1,1,1, 1, 1},
{ 1, 1,1,1,1, 1, 1},
{ 1, 1,1,1,1, 1, 1},
{-1,-1,1,1,1,-1,-1},
{-1,-1,1,1,1,-1,-1}
Marble(320,220,0);
board[3][3]=0;
Init();
setcolor(0);
for(i=0;i<=220;i++)
{
rectangle(0+i,0+i,640-i,480-i);
delay(10);
}
for(i=0;i<=220;i++)
{
rectangle(100+i,100,540-i,380);
delay(8);
}
closegraph();
getch();
};
//----------------------------------------------------------------------//
Function
Prototypes
//----------------------------------------------------------------------void Marble(int x,int y,int c);
void G();
int check();
int GetXY(int X,int Y);
int GetBoard(int X,int Y);
void SetBoard(int X,int Y,int element);
void Blink(int x,int y,int c);
void DrawBoard();
int MakeMove(int X,int Y);
void Init();
int finish();
void win(char *text,int sx,int sy,int
ex,int ey,int ck);
void winp(int sx,int sy,int ex,int ey,int
state);
void Menu();
void LCD(int left,int top,int NUM);
void Lcd(int x,int y,int n);
void Intro();
void Drawborder(int x,int y);
void Background();
int load_game ();
int save_game();
}
void Marble(int x,int y,int c)
{
setfillstyle(1,c);
setcolor(c);
fillellipse(x,y,8,8);
if(c!=0)
{
if(c==15)
{setcolor(7);setfillstyle(1,7);}
else {setfillstyle(1,15);setcolor(15);}
fillellipse(x+3,y-2,1,2);
}
}
void mydelay(float secs)
{
clock_t start, end;
start = clock();
do
{
end = clock();
if(kbhit()) break;
}while(((end
start)/CLK_TCK)<secs);
}
void Intro()
{
int i;
char
pattern[8]
={0xfe,0xbc,0xda,0xe4,0xe2,0xc0,0x8
8,0x00};
setfillpattern(pattern,1);
bar(0,0,640,480);
settextstyle(1,0,5);
//----------------------------------------------------------------------//
Main
Function
//----------------------------------------------------------------------void main()
{
int i;
G();
Intro();
Background();
DrawBoard();
71
setcolor(10);
getch();
setcolor(0);
for(i=0;i<=320;i++)
{
rectangle(0+i,0,640-i,480);
delay(5);
}
// win("BRAINVITA",1,1,638,478,1);
}
void Drawborder(int x,int y)
{
setwritemode(COPY_PUT);
setcolor(0);
line(x+60,y-20,x+180,y-20);//
__
line(x+60,y+60,x+60,y-20);//
|
line(x-40,y+60,x+60,y+60);// __
line(x-40,y+60,x-40,y+180);// |
setcolor(15);
line(x-40,y+180,x+60,y+180);// __
setcolor(0);
line(x+60,y+180,x+60,y+280);// |
setcolor(15);
line(x+180,y-20,x+180,y+60);//
|
setcolor(0);
line(x+180,y+60,x+290,y+60);//
__
setcolor(15);
line(x+290,y+60,x+290,y+180);//
|
line(x+180,y+180,x+290,y+180);//
__
line(x+180,y+180,x+180,y+280);//
|
line(x+180,y+280,x+60,y+280);//
__
setwritemode(XOR_PUT);
}
win("BRAINVITA",145,45,505,400,1);
// winp(159,79,491,381,1);
win("Keys",24,45,135,290,1);
win("Help !",510,45,625,250,1);
setfillstyle(1,0);
bar(35,75,125,280);
bar(520,75,618,240);
winp(35,75,125,280,1);
winp(520,75,618,240,1);
setcolor(14);
settextstyle(2,0,4);
outtextxy(42,80,"Keys used");
setcolor(15);
outtextxy(42,100,"+ or- : color");
outtextxy(47,120," : Up");
outtextxy(47,140," : Down");
outtextxy(42,160,"<- : Left");
outtextxy(42,180,"-> : Right");
outtextxy(42,200,"Enter : Pick");
outtextxy(42,220,"S : save game");
outtextxy(42,240,"L : load game");
outtextxy(42,260,"Esc : Exit");
line(47,120,50,123);
line(47,120,43,123);
line(47,140,50,143);
line(47,140,43,143);
outtextxy(523,80,"Use Arrow Keys");
outtextxy(523,100,"to
move
around");
outtextxy(523,120,"then
press
enter");
outtextxy(523,140,"to select any");
outtextxy(523,160,"marble,then
jump");
outtextxy(523,180,"over another
to");
outtextxy(523,200,"remove it.");
win("",190,410,480,460,0);
setfillstyle(1,0);
bar(200,420,470,450);
settextstyle(1,0,3);
setcolor(10);
outtextxy(220,420,"Marbles :");
}
void Background()
{
int i;
setfillstyle(1,3);
bar(0,0,640,480);
for(i=0;i<=15;i++)
{
setcolor(i);
rectangle(0+i,0+i,640-i,480-i);
}
//----------------------------------------------------------------------//
Draw The Whole
Board on Screen
72
//-----------------------------------------------------------------------
registerfarbgidriver(EGAVGA_driver_f
ar);
registerfarbgifont(sansserif_font_far)
;
registerfarbgifont(small_font_far);
registerfarbgifont(gothic_font_far);
registerfarbgifont(triplex_font_far);
*/
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s
", grapherrormsg(errorcode));
exit(1);
}
area=imagesize(150,70,240,180);
p=malloc(area);
if(p==NULL)
{closegraph();exit(1);}
}
void DrawBoard()
{
int i,j,x=200,y=100;
x=200;y=100;
setfillstyle(1,1);
bar(x-40,y-20,x+290,y+280);
setfillstyle(1,7);
bar(x-41,y-21,x+60,y+60);
bar(x+180,y-21,x+290,y+60);
bar(x-41,y+180,x+60,y+290);
bar(x+180,y+180,x+290,y+290);
Drawborder(x,y);
Drawborder(x+1,y+1);
setfillstyle(1,12);
setcolor(11);
for(i=0;i<7;i++)
{
for(j=0;j<7;j++)
{
if(board[j][i]!=-1)
{
if(board[j][i]==1)
Marble(x,y,marble_color);
if(board[j][i]==0)
Marble(x,y,0);
}
x+=40;
}
x=200;
y+=40;
}
settextstyle(1,0,3);
}
//----------------------------------------------------------------------//
Check the board if
any move is possible
//----------------------------------------------------------------------int check() // a know bug is there
{
int i,j,flag;
flag=0;
for(i=0;i<7;i++)
{
for(j=0;j<7;j++)
if(board[j][i]!=-1)
{
if(board[j][i]==1)
{
if(board[j+1][i]==1)
{
if(board[j+2]
[i]==0)
flag++;
//----------------------------------------------------------------------//
Switch Into
Graphics mode
//----------------------------------------------------------------------void G()
{
int gdriver = DETECT, gmode,
errorcode;
/*
// for stand alone
}
if(board[j-1][i]==1)
{
73
if(board[j-2]
[i]==0)
flag++;
}
if(board[j][i+1]==1)
{
if(board[j]
}
x=200;
y+=40;
}
return flag;
[i+2]==0)
flag++;
}
if(board[j][i-1]==1)
{
if(board[j][i-
//----------------------------------------------------------------------//
check current position is
filled or not
//-----------------------------------------------------------------------
2]==0)
flag++;
}
}
}
}
//count marble
marble=0;
for(i=0;i<7;i++)
{
for(j=0;j<7;j++)
if(board[j][i]==1)
marble++;
}
return flag;
}
//----------------------------------------------------------------------//
Give the current x,y position on
board & find is it valid or not
//-----------------------------------------------------------------------
//----------------------------------------------------------------------//
Sets the board to 1 or 0
,represents filled & empty respectively
//-----------------------------------------------------------------------
for(j=0;j<7;j++)
{
if(board[j][i]!=-1)
{
if(x==X && y==Y)
board[j][i]=element;
}
x+=40;
}
x=200;
y+=40;
flag=NO;
if(marble_color==11)
Marble(X,Y,9);
else Marble(X,Y,11);
key = bioskey(0);
if(key==0x4800)//up
{
if(GetBoard(X,Y-80)==0
GetBoard(X,Y-40)==1)
{
Marble(X,Y,0);
SetBoard(X,Y,0);
Y-=40;
Marble(X,Y,0);
SetBoard(X,Y,0);
Y-=40;
SetBoard(X,Y,1);
y=Y;
flag=YES;
}
}
if(key==0x5000)//down
{
if(GetBoard(X,Y+80)==0
GetBoard(X,Y+40)==1)
{
Marble(X,Y,0);
SetBoard(X,Y,0);
Y+=40;
Marble(X,Y,0);
SetBoard(X,Y,0);
Y+=40;
SetBoard(X,Y,1);
y=Y;
flag=YES;
}
}
if(key==0x4b00)//left
{
if(GetBoard(X-80,Y)==0
GetBoard(X-40,Y)==1)
{
Marble(X,Y,0);
SetBoard(X,Y,0);
X-=40;
Marble(X,Y,0);
SetBoard(X,Y,0);
X-=40;
SetBoard(X,Y,1);
x=X;
}
}
//----------------------------------------------------------------------//
Blinks the cursor or
square
//----------------------------------------------------------------------void Blink(int x,int y,int c)
{
int i;
setcolor(c);
do
{
rectangle(x-10,y10,x+10,y+10);
rectangle(x-11,y11,x+11,y+11);
mydelay(0.5);
rectangle(x-10,y10,x+10,y+10);
rectangle(x-11,y11,x+11,y+11);
mydelay(0.5);
}while(!kbhit());
}
//----------------------------------------------------------------------//
When ENTER pressed
check for conditions & perform task
//----------------------------------------------------------------------int MakeMove(int X,int Y)
{
int flag,key;
75
&&
&&
&&
flag=YES;
setfillstyle(1,11);
Lcd(360,425,marble);
Blink(x,y,11);
ch=getch();
Lcd(360,425,marble);
if(ch==ESC) e=0;
if(GetXY(x,y)==1)
{
switch(ch)
{
case
UP :if(GetXY(x,y40)==1)
if(y>100) y=40;break;
case
DOWN
:if(GetXY(x,y+40)==1)
if(y<340)
y+=40;break;
case
LEFT :if(GetXY(x40,y)==1)
if(x>200) x=40;break;
case
RIGHT
:if(GetXY(x+40,y)==1)
if(x<440)
x+=40;break;
case
ENTER
:if(GetBoard(x,y)==1)
{
MakeMove(x,y);
}
break;
case ESC :e=0;break;
case '+': marble_color+
+;
}
}
if(key==0x4d00)//right
{
if(GetBoard(X+80,Y)==0
GetBoard(X+40,Y)==1)
{
Marble(X,Y,0);
SetBoard(X,Y,0);
X+=40;
Marble(X,Y,0);
SetBoard(X,Y,0);
X+=40;
SetBoard(X,Y,1);
x=X;
flag=YES;
}
}
if(kbhit()) getch();
setcolor(11);
if(flag==YES)
{
Marble(X,Y,marble_color);
}
else//invalid key
{
Marble(X,Y,marble_color);
sound(800);
delay(100);
nosound();
}
return flag;
}
&&
//----------------------------------------------------------------------//
Handles All the funtions &
Perform desired move
//-----------------------------------------------------------------------
if(marble_color>15) marble_color=2;
DrawBoard();
break;
case '-':marble_color--;
if(marble_color<2)
marble_color=15;
DrawBoard();
break;
case
's':case
'S':save_game();break;
case
'l':case
'L':load_game();break;
}//switch
}//if
void Init()
{
int i,j,e=1;
char ch;
setwritemode(XOR_PUT);
setcolor(15);
while(e)
{
76
if(check()==0) e=finish();
}//while
setwritemode(COPY_PUT);
win("Exit ?",220,155,425,240,1);
settextstyle(1,0,1);
setcolor(1);
outtextxy(240,180,"Play Again
[y/n] :");
opt=getch();
setfillstyle(1,3);
bar(17,402,624,464);
if(opt=='y' || opt=='Y')
{
for(i=0;i<7;i++)
{
for(j=0;j<7;j++)
if(board[j][i]!=-1) board[j][i]=1;
}
Marble(320,220,0);
board[3][3]=0;
marble=32;
Background();
DrawBoard();
f=1;
}
else f=0;
setwritemode(XOR_PUT);
return f;
}
void win(char *text,int sx,int sy,int
ex,int ey,int ck)
{
setfillstyle(1,7);
bar(sx,sy,ex,ey);
setfillstyle(1,7);
setcolor(15);
line(sx,sy,sx,ey);
line(sx,sy,ex,sy);
line(sx,sy,sx,ey);
line(sx,sy,ex,sy);
setcolor(0);
line(ex,sy,ex,ey);
line(ex,sy,ex,ey);
line(sx,ey,ex,ey);
line(sx,ey,ex,ey);
if(ck==1)
{
settextstyle(0,0,0);
setfillstyle(1,1);
bar(sx+2,sy+2,ex-2,sy+17);
setcolor(15);
outtextxy(sx+4,sy+4,text);
//for x
}
//----------------------------------------------------------------------//
Display
Final
Screen
//----------------------------------------------------------------------int finish()
{
int i,j,f;
char opt=0;
setwritemode(COPY_PUT);
f=0;
for(i=0;i<7;i++)
{
for(j=0;j<7;j++)
if(board[j][i]==1)
f++;
}
Lcd(360,425,marble);
// f-=1;
win("Done !",220,155,425,240,1);
setcolor(0);
settextstyle(1,0,1);
switch(f)
{
case 1:outtextxy(230,180,"You
Are Intelligent !");break;
case
2:outtextxy(255,180,"
Wonderful !");break;
case
3:outtextxy(255,180,"
Good Job !");break;
case 4:outtextxy(255,180," Can
be better !");break;
case 5:outtextxy(230,180," You
Need Practice !");break;
case
6:outtextxy(230,180,"
Very Poor !");break;
case 7:outtextxy(230,180," Very
Very Poor !");break;
default:outtextxy(255,180," Try
Again !");break;
}
// gotoxy(1,1);printf("%d",f);
getch();
77
setfillstyle(1,7);
bar(ex-15,sy+4,ex-4,sy+15);
setcolor(15);
line(ex-15,sy+4,ex-4,sy+4);
line(ex-15,sy+4,ex-15,sy+15);
setcolor(0);
line(ex-15,sy+15,ex-4,sy+15);
line(ex-4,sy+4,ex-4,sy+15);
setcolor(1);
outtextxy(ex-13,sy+5,"x");
setfillstyle(1,7);
}
void Menu()
{
setcolor(0);
settextstyle(2,0,4);
getimage(161,80,240,180,p);
win(" ",161,80,240,180,0);
outtextxy(170,88,"New Game");
outtextxy(170,105,"Exit");
setwritemode(XOR_PUT);
mybar(170,88,220,100);
getch();
mybar(170,88,220,100);
mybar(170,105,220,117);
getch();
mybar(170,105,220,117);
setwritemode(COPY_PUT);
getch();
putimage(161,80,p,COPY_PUT);
}
void Lcd(int x,int y,int n)
{
int a,b;
if(n<10)
{
LCD(x,y,0);
LCD(x+15,y,n);
}
else if(n<100)
{
a=n/10;b=n%10;
LCD(x,y,a);
LCD(x+15,y,b);
}
}
void LCD(int left,int top,int NUM)
{
int i;
// int right=100, bottom=100;
setcolor(10);
}
void winp(int sx,int sy,int ex,int ey,int
state)
{
if(state==1)
{
setcolor(0);
line(sx,sy,sx,ey);
line(sx,sy,ex,sy);
line(sx,sy,sx,ey);
line(sx,sy,ex,sy);
setcolor(15);
line(ex,sy,ex,ey);
line(ex,sy,ex,ey);
line(sx,ey,ex,ey);
line(sx,ey,ex,ey);
}
else
{
setcolor(15);
line(sx,sy,sx,ey);
line(sx,sy,ex,sy);
line(sx,sy,sx,ey);
line(sx,sy,ex,sy);
setcolor(0);
line(ex,sy,ex,ey);
line(ex,sy,ex,ey);
line(sx,ey,ex,ey);
line(sx,ey,ex,ey);
}
}
void mybar(int sx,int sy,int ex,int ey)
{
int i;
// setcolor(14);
for(i=sy;i<=ey;i++)
line(sx,i,ex,i);
}
switch(NUM)
{
case 1:
line(left+11,top+2,left+11,top+9);
// |
line(left+11,top+11,left+11,top+18);
// |
break;
78
case 2:
line(left+1,top+10,left+9,top+10);
//--
line(left,top,left+10,top);
//--
line(left+11,top+11,left+11,top+18);
// |
line(left+11,top+2,left+11,top+9);
// |
line(left,top+20,left+10,top+20);
//-break;
case 6:
line(left,top,left+10,top);
//-line(left-1,top+2,left-1,top+9);
//|
line(left+1,top+10,left+9,top+10);
//-line(left-1,top+11,left1,top+18); //|
line(left,top+20,left+10,top+20);
//-break;
case 3:
line(left,top,left+10,top);
//--
line(left+1,top+10,left+9,top+10);
//-line(left-1,top+11,left1,top+18); //|
line(left+11,top+2,left+11,top+9);
// |
line(left+11,top+11,left+11,top+18);
// |
line(left+1,top+10,left+9,top+10);
//--
line(left,top+20,left+10,top+20);
//-break;
case 7:
line(left,top,left+10,top);
//-line(left-1,top+2,left-1,top+9);
//|
line(left+11,top+11,left+11,top+18);
// |
line(left,top+20,left+10,top+20);
//-break;
case 4:
line(left-1,top+2,left-1,top+9);
//|
line(left+11,top+2,left+11,top+9);
// |
line(left+11,top+2,left+11,top+9);
// |
line(left+11,top+11,left+11,top+18);
// |
break;
case 8:
line(left,top,left+10,top);
//-line(left-1,top+2,left-1,top+9);
//|
line(left+1,top+10,left+9,top+10);
//-line(left+11,top+11,left+11,top+18);
// |
break;
case 5:
line(left,top,left+10,top);
//-line(left-1,top+2,left-1,top+9);
//|
line(left+11,top+2,left+11,top+9);
// |
line(left+1,top+10,left+9,top+10);
//--
79
line(left-1,top+11,left1,top+18);
}
int load_game()
{
FILE *fp ;
char *name;
gotoxy(20,2);printf("File name:
");
scanf("%s",name);
if ( ( fp = fopen ( name, "rb" ) )
== NULL )
{
setfillstyle(1,3);
bar(20,17,400,40);
gotoxy(20,2);
printf("
Unable to Load
Game");
getch();
setfillstyle(1,3);
bar(20,17,400,40);
return 0;
}
fread(board,sizeof(board),1,fp);
fclose ( fp ) ;
setfillstyle(1,3);
bar(20,17,400,40);
DrawBoard();
return 1;
}
int save_game()
{
char *fname;
FILE *fp ;
gotoxy(20,2);printf("File name:
");
scanf("%s",fname);
if ( ( fp = fopen ( fname, "wb" ) )
== NULL ) return 0;
fwrite(board, sizeof ( board ), 1,
fp);
fclose(fp) ;
setfillstyle(1,3);
bar(20,17,400,40);
return 1;
}
//|
line(left+11,top+11,left+11,top+18);
// |
line(left,top+20,left+10,top+20);
//-break;
case 9:
line(left,top,left+10,top);
//-line(left-1,top+2,left-1,top+9);
//|
line(left+11,top+2,left+11,top+9);
// |
line(left+1,top+10,left+9,top+10);
//-line(left+11,top+11,left+11,top+18);
// |
line(left,top+20,left+10,top+20);
//-break;
case 0:
line(left,top,left+10,top);
//-line(left-1,top+2,left-1,top+9);
//|
line(left+11,top+2,left+11,top+9);
// |
line(left-1,top+11,left1,top+18); //|
line(left+11,top+11,left+11,top+18);
// |
line(left,top+20,left+10,top+20);
//-break;
}
80