Your fault if your eyes bleed after seeing this crap. Before the actual code itself, here are a few screenshots.
Exhibit A
Exhibit B
The Main Menu
The Game Over Screen
"Would You Like To Enter Your Name" in a disgusting font? No, I really would not.
THE POINT OF NO RETURN:
#include "all.h"
int gx, gy;//GETMAXX(), GETMAXY()
int px, py;//PAD_X, PAD_Y
float bx, by;//BALL_X,BALL_Y
float vbx=0,vby=0;//Velocity_ball_x, Velocity_ball_y
int score = 0;
int rel_ball = 0;
float liner = 1;
int sound_chk = 1;
int s = 1;
void key();
void changevelball();
void drawballline();
void choosevel();
void draw_pad();
void drawbricks(int, int);
void ball();
void ball_chk();
void chkbrick();
void esc_key();
void score_disp();
void name_enter();
void get_name();
void put_in_file();
void sound_func(int);
void main_menu();
class bricks
{
public:
int x[20], y[20], bool[20];
bricks()
{
for (int i =0;i<20;i++)
bool[i] = 1;
}
void bricks_chk();
void assign_brick();
}b;
void bricks::bricks_chk()
{
int i = 0;
for(i;i<20;i++)
{
if (bool[i] == 1)
{
setcolor(RED);
drawbricks(x[i],y[i]);
}
if (bool[i] == 0)
{
setcolor(BLACK);
drawbricks(x[i],y[i]);
}
}
}
void bricks::assign_brick()
{
for (int i =0;i<10;i++)
{
x[i] = gx/14 + (40*i);
y[i] = gy/7;
}
for (i;i<20;i++)
{
x[i] = (i-8)*gx/14 + 10;
y[i] = gy/10;
}
}
class data_for_storage
{
public:
char name[30];
int t_score;
}dot;
void main()
{
clrscr();
int gdriver = DETECT,gmode;
initgraph(&gdriver,&gmode,"C:\\TC\\BGI");
gx = getmaxx();
gy = getmaxy();
px = gx/2;
bx = gx/2 ;
by = gy - 34;
b.assign_brick();
void game();
game();
closegraph();
}
//int sound_control_val = 0;
void control_sound()
{
++sound_chk;
if (sound_chk == 8)
{s++;
sound_chk = 0;
}
if (s == 64)
s =0;
sound_func(s);
}
void game()
{
setcolor(WHITE);
rectangle(10,20,gx-10,gy-10);
settextstyle(2,0,5);
setcolor(BROWN);
outtextxy(gx/2 - 50,5,"BRICK BREAKER");
int i;
for(i=0;i==0;)
{
setcolor(WHITE);
rectangle(10,20,gx-10,gy-10);
settextstyle(2,0,5);
setcolor(BROWN);
outtextxy(gx/2 - 50,5,"BRICK BREAKER");
control_sound();
setcolor(RED);
b.bricks_chk();
setcolor(BLACK);
ball();
setcolor(WHITE);
draw_pad();
setfillstyle(1,BLACK);
floodfill(px,py+gy-20,WHITE);
setcolor(BLACK);
score_disp();
draw_pad();
if(kbhit())
key();
ball_chk();
setcolor(WHITE);
ball();
score_disp();
setcolor(LIGHTCYAN);
setfillstyle(5,LIGHTCYAN);
draw_pad();
floodfill(px,py+gy-20,LIGHTCYAN);
delay(25);
//gameover();
}
closegraph();
}
void draw_pad()
{
line(px-25,py+gy-25,px+25,py+gy-25);//top line
line(px-25,py+gy-15,px+25,py+gy-15);//bottom line
arc(px-25,py+gy-20,90,270,5);//left arc
arc(px+25,py+gy-20,270,90,5);//right arc
}
void key()
{
char ch;
ch = getche();
switch (ch)
{
case 'a':
case 'A':
px -= 10;
break;
case 'd':
case 'D':
px += 10;
break;
case 'w':
case 'W':
if (rel_ball == 0)
{
rel_ball = 1;
changevelball();
}
break;
case 27:
esc_key();
}
if (px <= 41)
px = 41;
if (px >= gx-41)
px = gx - 41;
}
void drawbricks(int x, int y)
{
rectangle(x-15,y-5,x+15,y+5);
}
void ball()
{
circle(bx, by, 5);
}
void ball_chk()
{
bx = bx + vbx;
by = by + vby;
if ( ((bx+8)>=(gx-10))||((bx-8)<=(10)) )
{
vbx = (-1)*(vbx);
}
if ((by-8)<=(20))
{
vby = (-1)*vby;
}
if ( (((bx+4) >= (px-25)) && ((bx-4)<= (px+25))) && ((py+gy-33 <= by)&&(py+gy-29>=by)) )
{vby = (-1)*vby;
}
chkbrick();
if ((by+8)>=(gy-10))
{setcolor(RED);
outtextxy(gx/2-50,gy/2,"GAME OVER");
getch();
setfillstyle(1,BLACK);
floodfill(gx/2,gy/2,WHITE);
name_enter();
settextstyle(2,0,5);
esc_key();
}
}
void chkbrick()
{
for (int i =0;i<20;i++)
{
if (b.bool[i] == 1)
{
if ( (((bx+5) >= (b.x[i]-15))&&((bx-5) <= (b.x[i]+15))) && ( ( ((by+5) <= b.y[i]-2)&&((by+5)>=b.y[i]-8)) || ( ((by-5)>=b.y[i]+2)&&((by-5)<=b.y[i]+8) ) ) )
{
b.bool[i] = 0;
vby = (-1)*vby;
score++;
}
if ( ((bx-5)>= (b.x[i]+12))&&((bx-5)<=(b.x[i]+18)) && ((by<=b.y[i]+8)&&(by>=b.y[i]-8)) )
{
b.bool[i] = 0;
vbx = (-1)*vbx;
score++;
}
if ( ((bx+5)>= (b.x[i]+12))&&((bx+5)<=(b.x[i]+18)) && ((by<=b.y[i]+8)&&(by>=b.y[i]-8)) )
{
b.bool[i] = 0;
vbx = (-1)*vbx;
score++;
}
}
}
}
void esc_key()
{
setcolor(GREEN);
rectangle(gx/4,gy/4,3*gx/4,3*gy/4);
setfillstyle(1,BLACK);
floodfill(gx/2,gy/2,GREEN);
setcolor(WHITE);
rectangle(gx/4,gy/4,3*gx/4,3*gy/4);
setcolor(GREEN);
rectangle(gx/4+10,gy/4+10,3*gx/4-10,gy/4+50);
outtextxy(gx/4+50,gy/4+20," START OVER - ENTER S");
rectangle(gx/4+10,gy/4+70,3*gx/4-10,gy/4+110);
outtextxy(gx/4+50,gy/4+80," CONTINUE - ENTER C");
rectangle(gx/4+10,gy/4+130,3*gx/4-10,gy/4+170);
outtextxy(gx/4+50,gy/4+140," MAIN MENU - ENTER M");
rectangle(gx/4+10,gy/4+180,3*gx/4-10,gy/4+220);
outtextxy(gx/4+50,gy/4+190," QUIT - PRESS ESC KEY");
setcolor(WHITE);
score_disp();
int color = 1;
for (int l =0 ;l==0;)
{
setcolor(GREEN);
rectangle(gx/4,gy/4,3*gx/4,3*gy/4);
setfillstyle(1,BLACK);
floodfill(gx/2,gy/2,GREEN);
setcolor(WHITE);
rectangle(gx/4,gy/4,3*gx/4,3*gy/4);
setcolor(GREEN);
rectangle(gx/4+10,gy/4+10,3*gx/4-10,gy/4+50);
outtextxy(gx/4+50,gy/4+20," START OVER - ENTER S");
rectangle(gx/4+10,gy/4+70,3*gx/4-10,gy/4+110);
outtextxy(gx/4+50,gy/4+80," CONTINUE - ENTER C");
rectangle(gx/4+10,gy/4+130,3*gx/4-10,gy/4+170);
outtextxy(gx/4+50,gy/4+140," MAIN MENU - ENTER M");
rectangle(gx/4+10,gy/4+180,3*gx/4-10,gy/4+220);
outtextxy(gx/4+50,gy/4+190," QUIT - PRESS ESC KEY");
setcolor(WHITE);
score_disp();
control_sound();
setcolor( (color/10) %15 + 1);
outtextxy((gx/2)-60,gy/4+225,"R / o / S \\ o \\ N");
if (kbhit())
{
char ch;
ch = getche();
switch (ch)
{
case 'C':
case 'c':
floodfill(gx/2,gy/2,RED);
setcolor(BLACK);
rectangle(gx/2,gy/2,3*gx/4,3*gy/4);
rel_ball = 0;
game();
break;
case 's':
case 'S':
floodfill(gx/2,gy/2,RED);
setcolor(BLACK);
rectangle(gx/2,gy/2,3*gx/4,3*gy/4);
rel_ball = 0;
for (int qt =0;qt<20;qt++)
{
b.bool[qt] = 1;
}
vbx =0;vby=0;
score = 0;
main();
break;
case 'm':
case 'M':
main_menu();
break;
case 27:
nosound();
closegraph();
exit(0);
}
}
++color;
delay(200);
}
}
int theta = 90;
void changevelball()
{
char ch;
for (int i =0;i==0;)
{
control_sound();
setcolor(BLACK);
drawballline();
ball();
setcolor(WHITE);
draw_pad();
setfillstyle(1,BLACK);
floodfill(px,py+gy-20,WHITE);
setcolor(BLACK);
draw_pad();
if (kbhit())
{
ch = getche();
switch(ch)
{
case 'a':
case 'A':
theta += 2;
break;
case 'd':
case 'D':
theta -= 2;
break;
case 'w':
case 'W':
choosevel();
break;
case 27:
esc_key();
}
}
setcolor(WHITE);
drawballline();
ball();
setcolor(LIGHTCYAN);
setfillstyle(5,LIGHTCYAN);
draw_pad();
floodfill(px,gy-20,LIGHTCYAN);
delay(25);
}
closegraph();
}
int lenline;
float radtodeg = (3.141592/180);
void drawballline()
{
lenline = (gy/10);
if (theta>=150)
theta = 150;
if (theta<=30)
theta = 30;
int x,y;
y = (gy-34) - lenline*(sin(theta*radtodeg));
x = gx/2 + lenline*(cos(theta*radtodeg));
line(gx/2,gy-34,x,y);
}
void choosevel()
{
vbx = lenline*(cos(theta*radtodeg))/10;
vby = -lenline*(sin(theta*radtodeg))/10;
game();
}
void score_disp()
{
int keep_score = score;
char ch[4] = {48,48,48};
int divide = 100, assign = 0, temp =0;
for (divide,assign;divide>=1;divide/=10,++assign)
{
temp = keep_score/divide;
ch[assign] = temp +48;
keep_score -= (temp*divide);
}
outtextxy(4*gx/5, 5, "SCORE:");
for(int i =0;i<4;++i)
{
switch(ch[i])
{
case 48:
outtextxy(4*gx/5+50+(i*10),5,"0");
break;
case 49:
outtextxy(4*gx/5+50+(i*10),5,"1");
break;
case 50:
outtextxy(4*gx/5+50+(i*10),5,"2");
break;
case 51:
outtextxy(4*gx/5+50+(i*10),5,"3");
break;
case 52:
outtextxy(4*gx/5+50+(i*10),5,"4");
break;
case 53:
outtextxy(4*gx/5+50+(i*10),5,"5");
break;
case 54:
outtextxy(4*gx/5+50+(i*10),5,"6");
break;
case 55:
outtextxy(4*gx/5+50+(i*10),5,"7");
break;
case 56:
outtextxy(4*gx/5+50+(i*10),5,"8");
break;
case 57:
outtextxy(4*gx/5+50+(i*10),5,"9");
break;
}
}
}
void name_enter()
{
settextstyle(7, 0, 1);
setcolor(10);
outtextxy(20*getmaxx()/100,getmaxy()/4,"Would You Like To Enter Your Name? (Y/N)");
gotoxy(10,10);
char ch;
cin>>ch;
switch(ch)
{
case 'y':
case 'Y':
get_name();
break;
case 'n':
case 'N':
break;
}
}
void get_name()
{
setcolor(BLACK);
outtextxy(20*getmaxx()/100,getmaxy()/4,"Would You Like To Enter Your Name? (Y/N)");
gotoxy(10,10);
cout<<" ";
setcolor(10);
outtextxy(getmaxx()/100,getmaxy()/4,"Please Enter Your Name:");
gets(dot.name);
put_in_file();
}
void put_in_file()
{
dot.t_score = score;
ofstream fobj("BRICKS.TXT",ios::out|ios::app);
fobj.write( (char *) &dot, sizeof(dot) );
fobj.close();
}
void c(int s)
{
sound(s);
}
void sound_func(int s)
{
switch (s)
{
case 1:
c(392);
break;
case 3:
c(466);
break;
case 5:
c(587);
break;
case 7:
c(784);
break;
case 9:
c(392);
break;
case 11:
c(466);
break;
case 13:
c(622);
break;
case 15:
c(784);
break;
case 17:
c(466);
break;
case 19:
c(587);
break;
case 21:
c(698);
break;
case 23:
c(932);
break;
case 25:
c(349);
break;
case 27:
c(440);
break;
case 29:
c(523);
break;
case 31:
c(698);
break;
case 33:
c(261);
break;
case 35:
c(311);
break;
case 37:
c(392);
break;
case 39:
c(523);
break;
case 41:
c(311);
break;
case 43:
c(392);
break;
case 45:
c(466);
break;
case 47:
c(622);
break;
case 49:
c(233);
break;
case 51:
c(293);
break;
case 53:
c(349);
break;
case 55:
c(466);
break;
case 57:
c(349);
break;
case 59:
c(440);
break;
case 61:
c(523);
break;
case 63:
c(698);
break;
default:
nosound();
}
}
void main_menu()
{
setcolor(BLACK);
rectangle(gx/4,gy/4,3*gx/4,3*gy/4);
setcolor(WHITE);
rectangle(10,20,gx-10,gy-10);
settextstyle(2,0,5);
setcolor(BROWN);
outtextxy(gx/2 - 50,5,"BRICK BREAKER");
setfillstyle(1,BLACK);
floodfill(gx/2,gy/2,WHITE);
setcolor(WHITE);
ifstream fobj("BRICKS.TXT",ios::in);
fobj.seekg(0);
int i =0;
gotoxy(1,5);
cout<<"NAME:";
gotoxy(20,5);
cout<<"SCORE:";
while(fobj)
{
fobj.read( (char *) &dot, sizeof(dot) );
gotoxy(1,6+i);
puts(dot.name);
gotoxy(20,6+i);
cout<<dot.t_score;
}
getch();
}