#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <dos.h>
#include <stdlib.h>
#define c15 textcolor(15);
#define col 30
#define row 4
int i,j,x=5, y=5, vx=1, vy=1, paddle=1,
points=0, level=0, timet=0, blocks[row][col];
char a;
float s=1;
clock_t t1=0, t2=0; // timers
void arc(void)
{
gotoxy(1,25);
for(i=0; i<79; i++)
printf(".");
gotoxy(paddle,25);
printf("!@@@!");
}
int ball(void)
{
t2=clock();
if((t2-t1)*(s/2) < timet) return 0;
t1=clock();
gotoxy(x,y); // koordinati sharika
printf(" "); // zatiraet shleyf sharika
if(x<=2 || x > 79) vx=-vx;
if(y>23) // granica. SHAR DOHODIT DO NIZA
{
if(x==paddle) // otlet c bolshey skorostiyu s kraya ottolk. udaryatcya ob !xxxx
{
vy=-vy;
vx=-vx;
s++;
}
if(x==(paddle+1)) // x@xxx
{
vy=-vx;
vx=-vx;
}
if(x==(paddle+2)) // xx@xx
{
if(vy==-vy) vy=vy;
if(vy==vy) vy=-vy;
vx=0;
}
if(x==(paddle+3)) // xxx@x
{
vy=-vy;
vx=vx;
}
if(x==(paddle+4))// xxxx!
{
vy=-vy;
vx=vx;
s++;
}
if(x>(paddle+4) || x < paddle) return 1; // SHAR KRANTI
}
if(y<=2) vy=-vy; // OTTALKIVANIE OT POTOLKA
x+=vx;
y+=vy;
gotoxy(x,y);
printf("*");
for(i=3; i < row+3; i++)
{
for(j=0; j < col; j++)
{
if(blocks[i-3][j]==1)
{
if(x==(10+j) && y==i)
{
points++;
vy=-vy;
blocks[i-3][j]=0;
}
}
}
}
gotoxy(1,1); // INDIKATOR SBITIH KVADRATIKOV
printf("Points: %d",points);
return 0;
}
void putsq(void)
{
textcolor(random(4*2)+1); cprintf("\376");
}
void squares(void)
{
for(i=3; i < row+3; i++)
{
for(j=0; j < col; j++)
{
gotoxy(10+j*2,i);
putsq();
}
}
}
void main()
{
clrscr();
for(i=0; i < row; i++)
{
for(j=0; j < col; j++)
{
blocks[i][j]=1;
}
}
do
{
c15; cprintf("\nEnter difficulty 1<=diff<=4: ");
scanf("%d",&level);
}
while(level < 1 || level > 4);
clrscr();
timet=level+1;
squares();
do
{
a=0;
if(kbhit())
{
a=getch();
if(a==77)
{
paddle++;
}
if(a==75)
{
paddle--;
}
if(paddle < 1) paddle=1; // GRANICI DVIJENIYA ARKANOIDA
if(paddle > 74) paddle=74;
if(a == 32) break; // BREAK NA PROBEL
arc();
}
if(ball()) break;
}
while(1);
if(points>100)
{
clrscr();
c15; cprintf("\n\nYou are winner! :)");
getch();
return;
}
clrscr();
c15; cprintf("Vi proigrali");
getch();
}