#include <graphics.h>
#include <process.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
/*
included function libraries
*/
#define BORDER 1
/*
difference between screen border and game area
*/
#define DELAY 20
/*
game minimal delay
*/
struct unit
{
int x, y, rad, dir, spd, col;
/*
<x> - x position
<y> - y position
<rad> - radius
<dir> - direction
<spd> - speed
<col> - color
*/
};
struct coord
{
int x, y;
/*
<x> - x position
<y> - y position
*/
};
unit ball[128], usr, enm;
/*
all infotmation about balls
*/
int end, key, ballhave, ballnum, score, bombtimer, bombnum, keybuffer, deathtimer = 0;
/*
<end> - 0 if the game is active
<key> - last pressed key
<ballhave> - number of balls collected
<ballnum> - total number of balls
*/
coord bomb;
/*
bomb position
*/
void help();
void init();
void greetings();
void level();
/*
declaration of functions
*/
void help()
{
clearviewport();
gotoxy(1, 1);
printf("Objective: Own and don\'t get owned.\n\nUse arrow keys to move your white bubble.\nCollect green bubbles to get bigger.\nCollect all bubbles to advance to next level.\nAvoid red bubble.\n\nIdea: Gyolchanyan Gor\nProgrammer: Gyolchanyan Gor\nDesign: Gyolchanyan gor\nFeedback: rambling_ghost@mail.ru\n\nSpecial thanks to Chigirinsky Aleksander for the \"Bubble Strike\" name.");
getch();
clearviewport();
if (usr.dir == 0) key = 'H';
if (usr.dir == 1) key = 'M';
if (usr.dir == 2) key = 'P';
if (usr.dir == 3) key = 'K';
}
void init()
{
int i;
randomize();
usr.x = getmaxx() / 2;
usr.y = getmaxy() / 2;
usr.rad = 5;
usr.dir = 2;
usr.spd = 5;
usr.col = 15;
enm.x = 0;
enm.y = 0;
enm.rad ++;
enm.spd = 3;
enm.col = 12;
ballhave = 0;
deathtimer = 0;
bomb.x = getmaxx();
bomb.y = getmaxy();
bombnum ++;
ballnum ++;
for (i = 0; i < ballnum; i++)
{
ball.x = random(getmaxx());
ball.y = random(getmaxy());
ball.dir = random(4);
ball.spd = 1 + random(3);
ball.col = 8 + ball.spd;
ball.rad = 2 * ball.spd;
}
if (key != 27) level();
}
void greetings()
{
gotoxy(33, 15);
printf("Welcome to");
gotoxy(25, 16);
printf(" GAME LOBYIIIKA CHAR9IDA !");
gotoxy(25, 17);
printf("Enter - start game; ESC - exit");
key = getch();
clearviewport();
}
void level()
{
clearviewport();
gotoxy(33, 15);
printf("Level %i", ballnum);
gotoxy(30, 17);
printf("Press any key");
getch();
clearviewport();
}
int main()
{
int gd, gm, i;
detectgraph(&gd, &gm);
initgraph(&gd, &gm, "c:\\progra~1\\bc\\bgi");
bombnum = 0;
enm.rad = 3;
greetings();
init();
clearviewport();
while (end == 0)
{
delay(DELAY);
if ((deathtimer <= 0)&&(deathtimer > -1))
{
deathtimer = -2;
enm.spd = 3;
}
else deathtimer --;
if ((bombtimer <= 0) && (bombtimer > -1))
{
bombtimer = -2;
setcolor(8);
setfillstyle(1, 8);
fillellipse(bomb.x, bomb.y, (usr.rad * 10), (usr.rad * 10));
if ((abs(enm.x - bomb.x) <= (usr.rad * 10 + enm.rad))&&
(abs(enm.y - bomb.y) <= (usr.rad * 10 + enm.rad)))
{
enm.spd = 0;
deathtimer = 200;
}
for(i = 0; i < ballnum; i++)
{
if ((abs(bomb.x - ball.x) <= ((100) + ball.rad))&&
(abs(bomb.y - ball.y) <= ((100) + ball.rad))&&
(ball.col != 0))
{
ball.col = 0;
ball.spd = 0;
ball.x = getmaxx();
ball.y = getmaxy();
ballhave ++;
score += 1;
clearviewport();
if (ballhave >= ballnum) init();
}
}
delay(DELAY);
setcolor(0);
setfillstyle(1, 0);
fillellipse(bomb.x, bomb.y, (usr.rad * 10), (usr.rad * 10));
}
else bombtimer --;
gotoxy(1, 1);
printf("Total bubbles collected: %i \nLevel: %i\nBombs: %i", score, ballnum, bombnum);
setcolor(0);
setfillstyle(1, 0);
fillellipse(usr.x, usr.y, usr.rad, usr.rad);
fillellipse(enm.x, enm.y, enm.rad, enm.rad);
fillellipse(bomb.x, bomb.y, usr.rad, usr.rad);
if (kbhit())
{
keybuffer = key;
key = getch();
}
switch (key)
{
case 27:
{
return 0;
}
case 59:
{
help();
break;
}
case ' ':
{
key = keybuffer;
if ((bombtimer <= 0)&&(bombnum > 0))
{
setcolor(14);
setfillstyle(1, 14);
bombtimer = 50;
bombnum --;
bomb.x = usr.x;
bomb.y = usr.y;
}
}
case 'H':
{
usr.dir = 0;
break;
}
case 'M':
{
usr.dir = 1;
break;
}
case 'P':
{
usr.dir = 2;
break;
}
case 'K':
{
usr.dir = 3;
break;
}
}
if (usr.x <= 0 + BORDER) usr.x = getmaxx() - usr.rad;
if (usr.x >= getmaxx() - BORDER) usr.x = 0 + usr.rad;
if (usr.y <= 0 + BORDER) usr.y = getmaxy() - usr.rad;
if (usr.y >= getmaxy() - BORDER) usr.y = 0 + usr.rad;
switch (usr.dir)
{
case 0:
{
usr.y -= usr.spd;
break;
}
case 1:
{
usr.x += usr.spd;
break;
}
case 2:
{
usr.y += usr.spd;
break;
}
case 3:
{
usr.x -= usr.spd;
break;
}
}
if(enm.x < usr.x) enm.x += enm.spd;
if(enm.x > usr.x) enm.x -= enm.spd;
if(enm.y < usr.y) enm.y += enm.spd;
if(enm.y > usr.y) enm.y -= enm.spd;
if(bomb.x < enm.x) bomb.x += 1;
if(bomb.x > enm.x) bomb.x -= 1;
if(bomb.y < enm.y) bomb.y += 1;
if(bomb.y > enm.y) bomb.y -= 1;
setcolor(usr.col);
setfillstyle(1, usr.col);
fillellipse(usr.x, usr.y, usr.rad, usr.rad);
for(i = 0; i < ballnum; i++)
{
if ((abs(usr.x - ball.x) <= (usr.rad + ball.rad))&&
(abs(usr.y - ball.y) <= (usr.rad + ball.rad))&&
(ball.col != 0))
{
ball.col = 0;
ball.spd = 0;
ball.x = getmaxx();
ball.y = getmaxy();
usr.rad ++;
ballhave ++;
score += 1;
clearviewport();
if (ballhave >= ballnum) init();
}
if ((abs(usr.x - enm.x) <= (usr.rad + enm.rad))&&
(abs(usr.y - enm.y) <= (usr.rad + enm.rad)))
{
clearviewport();
gotoxy(5, 12);
printf("Y O U H A V E B E E N O W N E D I N A L L H O L E S !");
getch();
getch();
if (ballnum > 1) ballnum -= 2;
else ballnum = 0;
bombnum = 0;
score = 0;
enm.rad = 3;
init();
}
setcolor(0);
setfillstyle(1, 0);
fillellipse(ball.x, ball.y, ball.rad, ball.rad);
switch (ball.dir)
{
case 0:
{
ball.x -= ball.spd;
ball.y -= ball.spd;
if (ball.x <= 0)
{
ball.x = 0 + BORDER;
ball.dir = 1;
}
if (ball.y <= 0)
{
ball.y = 0 + BORDER;
ball.dir = 3;
}
break;
}
case 1:
{
ball.x += ball.spd;
ball.y -= ball.spd;
if (ball.x >= getmaxx())
{
ball.x = getmaxx() - BORDER;
ball.dir = 0;
}
if (ball.y <= 0)
{
ball.y = 0 + BORDER;
ball.dir = 2;
}
break;
}
case 2:
{
ball.x += ball.spd;
ball.y += ball.spd;
if (ball.x >= getmaxx())
{
ball.x = getmaxx() - BORDER;
ball.dir = 3;
}
if (ball.y >= getmaxy())
{
ball.y = getmaxy() - BORDER;
ball.dir = 1;
}
break;
}
case 3:
{
ball.x -= ball.spd;
ball.y += ball.spd;
if (ball.x <= 0)
{
ball.x = 0 + BORDER;
ball.dir = 2;
}
if (ball.y >= getmaxy())
{
ball.y = getmaxy() - BORDER;
ball.dir = 0;
}
break;
}
}
if (bombtimer > 0)
{
setcolor(14);
setfillstyle(1, 14);
fillellipse(bomb.x, bomb.y, usr.rad, usr.rad);
}
setcolor(ball.col);
setfillstyle(1, ball.col);
fillellipse(ball.x, ball.y, ball.rad, ball.rad);
setcolor(usr.col);
setfillstyle(1, usr.col);
fillellipse(usr.x, usr.y, usr.rad, usr.rad);
setcolor(enm.col);
setfillstyle(1, enm.col);
fillellipse(enm.x, enm.y, enm.rad, enm.rad);
}
}
closegraph();
return 0;
}
Нужна блок-схема для программы
Если у кого есть возможность, то помогите пожалуйста написать блок-схему (алгоритм) для данной программы. Вот программа: