0% found this document useful (0 votes)
77 views4 pages

Program: Bricks Game in C/C .: Language

This document contains the code for a bricks game written in C/C++. It uses graphics libraries to display blocks, balls, and scores on the screen. The player controls a ball that bounces around and breaks blocks for points. When all blocks are cleared or the ball goes off screen, the game ends and displays the final score.

Uploaded by

ravi21041989
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views4 pages

Program: Bricks Game in C/C .: Language

This document contains the code for a bricks game written in C/C++. It uses graphics libraries to display blocks, balls, and scores on the screen. The player controls a ball that bounces around and breaks blocks for points. When all blocks are cleared or the ball goes off screen, the game ends and displays the final score.

Uploaded by

ravi21041989
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Program : Bricks Game in C/C .

/*
<a id="KonaLink0" target="undefined" class="kLink"
style="text-decoration: underline ! important; position: static;"
href="#"><font style="color: blue ! important; font-family:
monospace;
font-weight: 400; font-size: 11px; position: static;"
color="blue"><span
class="kLink" style="color: blue ! important; font-family: monospace;
font-weight: 400; font-size: 11px; position:
relative;">Language</span></font></a>:

C\C++ (To convert to C,


just change cout to printf and cin to scanf and
change the library files)
Category: Miscellaneous
Description: bricks game
*/

#include"graphics.h"
#include&lt;iostream.h&gt;
#include&lt;stdio.h&gt;
#include&lt;conio.h&gt;
#include&lt;dos.h&gt;
#include&lt;stdlib.h&gt;

int getkey();

void main()
{
registerbgidriver(EGAVGA_driver);
int gd,gm;
gd=DETECT;
initgraph(&amp;gd,&amp;gm," ");
cleardevice();

int ar,xc,yc,xr=0,yr=195,a=1,b=1,c=0,are;
void *bu,*buf;
int X=0,Y=0,s,area1;
void *buff1;

rectangle(0,0,50,25);
setfillstyle(6,6);
floodfill(2,2,15);
ar=imagesize(0,0,50,25);
bu=malloc(ar);
getimage(0,0,50,25,bu);
putimage(0,0,bu,XOR_PUT);
rectangle(0,0,50,25);
setfillstyle(6,8);
floodfill(2,2,15);
are=imagesize(0,0,50,25);
buf=malloc(are);
getimage(0,0,50,25,buf);
putimage(0,0,buf,XOR_PUT);
for(int j=0;j&lt;180;j+=27)
for(int i=0;i&lt;600;i+=52)
putimage(0+i,27+j,bu,XOR_PUT);
putimage(0,27,bu,XOR_PUT);
putimage(572,27,bu,XOR_PUT);
putimage(0,27,buf,XOR_PUT);
putimage(572,27,buf,XOR_PUT);

setcolor(3);
rectangle(80,445,159,452);
setfillstyle(1,1);
floodfill(82,447,3);
area1=imagesize(80,445,159,452);
buff1=malloc(area1);
getimage(80,445,159,452,buff1);

setcolor(4);
line(0,479,640,479);

int area,x=325,y=325,ch,xdirn=-1,ydirn=-1,step;
int maxx,maxy;
void *buff;

setcolor(WHITE);
setfillstyle(SOLID_FILL,RED);
circle(350,350,5);
floodfill(350,350,WHITE);

area=imagesize(345,345,355,355);
buff=malloc(area);
getimage(345,345,355,355,buff);
putimage(345,345,buff,XOR_PUT);

while (1)
{
putimage(x, y, buff, XOR_PUT);
delay(15);
putimage(x, y, buff, XOR_PUT);

x=x+(xdirn*2);
y=y+(ydirn*3);

if ( x + 10 - 1 &gt; 640 )
{
xdirn*=-1;
x = 640 - 10 + 1;
}
if (x &lt; 0)
{
xdirn*=-1;
x = 0;
}
if ( y + 10 - 1 &gt; 470 )
{
// ydirn*=-1;
// y = 470 - 10 + 1;
cleardevice();
outtextxy(200,200,"Sorry! You loose the game.");
outtextxy(250,240,"Try Again!!!");
gotoxy(30,8);
cout&lt;&lt;"Total Score : "&lt;&lt;c;
delay(5000);
getch();
goto tt;
}
if(c==1020)
{
outtextxy(180,200,"Congrats! You have finished the
game.");
gotoxy(30,8);
cout&lt;&lt;"Total Score : "&lt;&lt;c;
delay(5000);
getch();
goto tt;
}

if ( getpixel(x,y)==1 )
{
sound(500);
delay(15);
nosound();
ydirn*=-1;
}
if (getpixel(x,y)==6)
{
sound(100);
delay(50);
nosound();
ydirn*=-1;
xc=x;
yc=y;
a=xc/52;
b=(yc/27);
xr=a*52;
yr=b*27;
putimage(xr,yr,bu,XOR_PUT);
c+=10;
}
if (getpixel(x,y)==8)
{
sound(800);
delay(200);
nosound();
ydirn*=-1;
xc=x;
yc=y;
a=xc/52;
b=(yc/27);
xr=a*52;
yr=b*27;
putimage(xr,yr,buf,XOR_PUT);
c+=100;
}
if( y &lt; 0 )
{
ydirn*=-1;
y=0;
}
gotoxy(65,1);
cout&lt;&lt;"SCORE : "&lt;&lt;c;

if( kbhit() )
{
s=getkey();
if(s!=1)
{
if(X&gt;480)
{
X=480;
putimage(160+X,445+Y,buff1,XOR_PUT);
}
if(X&lt;-80)
{
X=-80;
putimage(80+X,445+Y,buff1,XOR_PUT);
}
putimage(80+X,445+Y,buff1,XOR_PUT);
//if(s==72)
// Y+=-40;
if(s==75)
X+=-40;
//if(s==80)
// Y+=40;
if(s==77)
X+=40;
putimage(80+X,445+Y,buff1,XOR_PUT);
//cout&lt;&lt;X;
}
if(s==1)
{
tt: free(bu);
free(buff);
free(buff1);
closegraph();
exit(0);
}
}
}
free(bu);
free(buff);
free(buff1);
closegraph();
}

int getkey()
{
union REGS j,o;
j.h.ah=0;
int86(22,&amp;j,&amp;o);
return(o.h.ah);
}

You might also like