Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
КП Компьютерная Игра по ПЯВУ.docx
Скачиваний:
0
Добавлен:
01.03.2025
Размер:
919.97 Кб
Скачать
  1. Описание интерфейса программы:

Программа встречает пользователя приветствием в виде анимационного ролика:

Главный персонаж игры «съедает» надпись “Pacy-Pacy, Welcome!”.

Далее пользователь попадает в главное меню:

Управление в меню осуществляется вводом чисел от 1 до 3.

  • если пользователь набирает 3, то программа завершается, прощаясь с пользователем анимационным роликом, где главный персонаж игры «съедает» надпись “Goodbye, Pacy-Pacy!”.

  • если пользователь набирает 2, то на экране выводятся правила игры:

нажатие любой клавиши вернет пользователя в главное меню.

  • если пользователь набирает 1, то начинается игра:

когда пользователь нажимает ESC или проигрывает, то на экране выводятся его личный результат за игру:

Далее пользователь автоматически попадает в главное меню.

  1. Вывод:

Мною была написана игра на языке программирования высокого уровня, используя знания, накопленные за год обучения. Игра имеет радужный интерфейс, представленный псевдографикой. Мною в процессе написания данной программы были использованы такие типы данных как структура, перечисления и более простой – двумерные массивы, как символьные, так и числовые.

Данная программа не занимает много места в памяти, всего 23 КБ, красочна и проста в использовании и понимании. Единственным самым ярким недостатком моей программы является отсутствие русского языка, которое обосновано выбором между красивым дизайном моей game и не имеющей нужных мне символов библиотекой русского языка.

ПРИЛОЖЕНИЕ 1:

#include <iostream>

#include <Windows.h>

#include <conio.h>

using namespace std;

char const_map[21][21];

//рисуется карта игры

void made_const_map(void)

{

int i,j;

for(i=0;i<21;i++)

for(j=0;j<21;j++)

const_map[i][j]=32;

for(i=1;i<6;i++)

for(j=2;j<19;j++)

{

const_map[i][j]='.';

const_map[i+12][j]='.';

const_map[i+14][j]='.';

}

for(i=6;i<13;i++)

{

const_map[i][5]='.';

const_map[i][15]='.';

}

const_map[2][2]='+';

const_map[2][18]='+';

const_map[15][2]='+';

const_map[15][18]='+';

for(j=2;j<19;j++)

{

i=0;

const_map[i][j]=205;

i=20;

const_map[i][j]=205;

}

for(i=1;i<6;i++)

{

j=1;

const_map[i][j]=186;

j=19;

const_map[i][j]=186;

}

for(i=13;i<20;i++)

{

j=1;

const_map[i][j]=186;

j=19;

const_map[i][j]=186;

}

for(j=8;j<13;j++)

{

i=4;

const_map[i][j]=205;

i=8;

const_map[i][j]=205;

i=10;

const_map[i][j]=205;

i=12;

const_map[i][j]=205;

i=16;

const_map[i][j]=205;

}

const_map[8][10]=32;

for(j=0;j<4;j++)

{

i=8;

const_map[i][j]=205;

const_map[i][j+17]=205;

i=10;

const_map[i][j]=205;

const_map[i][j+17]=205;

}

for(j=3;j<5;j++)

{

i=2;

const_map[i][j]=205;

const_map[i][j+13]=205;

i=4;

const_map[i][j]=205;

const_map[i][j+13]=205;

i=14;

const_map[i][j]=205;

const_map[i][j+13]=205;

}

for(j=6;j<9;j++)

{

i=2;

const_map[i][j]=205;

const_map[i][j+6]=205;

i=6;

const_map[i][j]=205;

const_map[i][j+6]=205;

i=14;

const_map[i][j]=205;

const_map[i][j+6]=205;

}

for(j=2;j<4;j++)

{

i=6;

const_map[i][j]=205;

const_map[i][j+15]=205;

i=12;

const_map[i][j]=205;

const_map[i][j+15]=205;

}

for(i=10;i<13;i++)

{

const_map[i][4]=186;

const_map[i][6]=186;

const_map[i][14]=186;

const_map[i][16]=186;

const_map[i-4][4]=186;

const_map[i-4][6]=186;

const_map[i-4][14]=186;

const_map[i-4][16]=186;

const_map[i+4][4]=186;

const_map[i+6][6]=186;

const_map[i+6][14]=186;

const_map[i+4][16]=186;

const_map[i-10][10]=186;

const_map[i-6][10]=186;

const_map[i+2][10]=186;

const_map[i+6][10]=186;

const_map[i-2][8]=186;

const_map[i-2][12]=186;

const_map[i-6][6]=186;

const_map[i-6][14]=186;

}

for(j=3;j<9;j++)

{

i=18;

const_map[i][j]=205;

const_map[i][j+9]=205;

}

const_map[16][2]=205;

const_map[16][18]=205;

const_map[0][1]=201;

const_map[0][10]=203;

const_map[0][19]=187;

const_map[4][10]=203;

const_map[6][1]=200;

const_map[6][4]=187;

const_map[6][6]=204;

const_map[6][14]=185;

const_map[6][16]=201;

const_map[6][19]=188;

const_map[8][4]=188;

const_map[8][8]=201;

const_map[8][12]=187;

const_map[8][16]=200;

const_map[10][4]=187;

const_map[10][8]=200;

const_map[10][12]=188;

const_map[10][16]=201;

const_map[12][1]=201;

const_map[12][4]=188;

const_map[12][10]=203;

const_map[12][16]=200;

const_map[12][19]=187;

const_map[14][4]=187;

const_map[14][16]=201;

const_map[16][1]=204;

const_map[16][10]=203;

const_map[16][19]=185;

const_map[18][6]=202;

const_map[18][14]=202;

const_map[20][1]=200;

const_map[20][19]=188;

//установка героев игры

const_map[15][10]=2;//пэкмен

const_map[9][9]='T';//привидения

const_map[9][11]='T';

const_map[9][10]='Y';

const_map[7][10]='Y';

}

enum COLOURS

{

yellow,red,pink,green,grey,cyan,white,dark_green,dark_blue,sky

};

enum MOOD

{

walk,follow,eaten

};

enum DIRS

{

up,down,Right,Left

};

struct PACMAN

{

char appearance;

DIRS direction;//Up, Down, Left, Right

int location[2];

};

struct GHOST

{

MOOD mood;

char appearance;

int radius;

int location[2];

char under;

};

struct GAME

{

char map[21][21];

int dots;

int points;

int health;

int number_level;

PACMAN pacman;

GHOST ghosts[4];

};

GAME game;//основная структура игры

void made_basic_characters_locations(void)

{

game.pacman.location[0]=15;//Pacman

game.pacman.location[1]=10;

game.pacman.appearance=2;

game.pacman.direction=up;

game.ghosts[1].location[0]=9;//T

game.ghosts[1].location[1]=9;

game.ghosts[1].appearance='T';

game.ghosts[1].radius=21;

game.ghosts[2].location[0]=9;//T

game.ghosts[2].location[1]=11;

game.ghosts[2].appearance='T';

game.ghosts[2].radius=21;

game.ghosts[3].location[0]=9;//Y

game.ghosts[3].location[1]=10;

game.ghosts[3].appearance='Y';

if(3+game.number_level>21)

game.ghosts[3].radius=21;

else

game.ghosts[3].radius=3+game.number_level;

game.ghosts[0].location[0]=7;//Y

game.ghosts[0].location[1]=10;

game.ghosts[0].appearance='Y';

if(3+game.number_level>21)

game.ghosts[0].radius=21;

else

game.ghosts[0].radius=3+game.number_level;

for(int i=0;i<4;i++)

{

game.ghosts[i].mood=follow;

game.map[game.ghosts[i].location[0]][game.ghosts[i].location[1]]=game.ghosts[i].appearance;

game.ghosts[i].under=32;

}

game.map[game.pacman.location[0]][game.pacman.location[1]]=2;

}

void made_basic_map(void)

{

for(int i=0;i<21;i++)

for(int j=0;j<21;j++)

game.map[i][j]=const_map[i][j];

}

void ClearScreen()

{

// Вариант 1.

// system("cls");

// Вариант 2.

HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);

if (hStdOut == INVALID_HANDLE_VALUE)

return;

/* Get the number of cells in the current buffer */

CONSOLE_SCREEN_BUFFER_INFO csbi;

if (!GetConsoleScreenBufferInfo(hStdOut, &csbi))

return;

DWORD cellCount = csbi.dwSize.X *csbi.dwSize.Y;

/* Fill the entire buffer with spaces */

DWORD count;

COORD homeCoords = {0, 0};

if (!FillConsoleOutputCharacter(hStdOut, (TCHAR) ' ', cellCount, homeCoords, &count))

return;

/* Fill the entire buffer with the current colors and attributes */

if (!FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, cellCount, homeCoords, &count))

return;

/* Move the cursor home */

SetConsoleCursorPosition(hStdOut, homeCoords);

}

void MoveCursor(int x, int y)

{

// Координаты

COORD pos;

pos.X = x;

pos.Y = y;

SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);

}

void SetCursorVisibility(bool isVisible)

{

CONSOLE_CURSOR_INFO ci;

ci.bVisible = isVisible;

ci.dwSize = 1;

SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &ci);

}

void SetTextColor(COLOURS colour)

{

switch(colour)

{

case yellow:

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);

break;

case red:

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY);

break;

case pink:

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);

break;

case grey:

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);

break;

case green:

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);

break;

case cyan:

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_BLUE | FOREGROUND_GREEN);

break;

case sky:

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);

break;

case white:

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);

break;

case dark_green:

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN);

break;

case dark_blue:

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_BLUE);

break;

}

}

bool if_it_wall(char ch)

{

if(ch+256==185||ch+256==186||ch+256==187||ch+256==188||ch+256==200||ch+256==201||ch+256==202||ch+256==203||ch+256==204||ch+256==205||ch+256==206)

return true;

return false;

}

void made_basic_descriptions(bool inception)

{

if(inception)

{

game.number_level=1;

game.dots=150;

game.points=0;

game.health=3;

made_basic_map();

made_basic_characters_locations();

}

else

{

game.number_level++;

game.dots=150;

made_basic_map();

made_basic_characters_locations();

}

}

void show_health(void)

{

MoveCursor(0,21);

if(game.health<=5)

for(int i=0;i<game.health;i++)

{

SetCursorVisibility(false);

SetTextColor(yellow);

cout<<char(2);

}

else

{

SetCursorVisibility(false);

SetTextColor(yellow);

cout<<char(2)<<" ";

SetTextColor(grey);

cout<<"x "<<game.health;

}

}

void show_map(void)

{

for(int i=0;i<21;i++)

{

for(int j=0;j<21;j++)

{

if(if_it_wall(game.map[i][j]))

SetTextColor(grey);

else

switch(game.map[i][j])

{

case 'T':

SetTextColor(green);

break;

case 'Y':

SetTextColor(pink);

break;

case 'X':

SetTextColor(red);

break;

case 2:

SetTextColor(yellow);

break;

case '.':

SetTextColor(cyan);

break;

case '+':

SetTextColor(red);

break;

case 'u':

SetTextColor(dark_green);

break;

default:

SetTextColor(white);

break;

}

cout<<game.map[i][j];

}

cout<<endl;

}

MoveCursor(13,21);

SetCursorVisibility(false);

SetTextColor(sky);

cout<<game.points;

show_health();

}

bool if_it_ghost(char ch)

{

if(ch=='T'||ch=='Y'||ch=='u')

return true;

return false;

}

int matrix[21][21];

void made_matrix(void)

{

for(int i=0;i<21;i++)

for(int j=0;j<21;j++)

matrix[i][j]=300;

}

void find_way(int end_poz_X,int end_poz_Y,int poz_X,int poz_Y,int const_poz_X,int const_poz_Y,int count)

{

if(matrix[poz_X][poz_Y]<count)

return;

if(poz_X!=const_poz_X||poz_Y!=const_poz_Y)

if(if_it_wall(game.map[poz_X][poz_Y])||if_it_ghost(game.map[poz_X][poz_Y]))

return;

if(poz_X==end_poz_X&&poz_Y==end_poz_Y)

{

matrix[poz_X][poz_Y]=count;

return;

}

matrix[poz_X][poz_Y]=count;

find_way(end_poz_X,end_poz_Y,poz_X+1,poz_Y,const_poz_X,const_poz_Y,count+1);

find_way(end_poz_X,end_poz_Y,poz_X-1,poz_Y,const_poz_X,const_poz_Y,count+1);

find_way(end_poz_X,end_poz_Y,poz_X,poz_Y+1,const_poz_X,const_poz_Y,count+1);

find_way(end_poz_X,end_poz_Y,poz_X,poz_Y-1,const_poz_X,const_poz_Y,count+1);

}

void find_right_move(int*move,int poz_X,int poz_Y)

{

if(matrix[poz_X][poz_Y]==1)

{

move[0]=poz_X;

move[1]=poz_Y;

return;

}

if(matrix[poz_X+1][poz_Y]<matrix[poz_X][poz_Y])

find_right_move(move,poz_X+1,poz_Y);

if(matrix[poz_X-1][poz_Y]<matrix[poz_X][poz_Y])

find_right_move(move,poz_X-1,poz_Y);

if(matrix[poz_X][poz_Y+1]<matrix[poz_X][poz_Y])

find_right_move(move,poz_X,poz_Y+1);

if(matrix[poz_X][poz_Y-1]<matrix[poz_X][poz_Y])

find_right_move(move,poz_X,poz_Y-1);

}

bool if_in_radius(int poz_ghost_X,int poz_ghost_Y,int radius)

{

for(int i=poz_ghost_X-radius;i<=poz_ghost_X+radius;i++)

for(int j=poz_ghost_Y-radius;j<=poz_ghost_Y+radius;j++)

if(game.map[i][j]==2)

return true;

return false;

}

void random_move(int*move,int poz_X,int poz_Y)

{

int t=rand()%4;

switch(t)

{

case 1://Up

poz_X+=1;

break;

case 2://Down

poz_X-=1;

break;

case 3://Right

poz_Y+=1;

break;

case 0://Left

poz_Y-=1;

break;

}

move[0]=poz_X;

move[1]=poz_Y;

}

void basic_ghosts_decriptions(int number)

{

switch(number)

{

case 0:

{

game.ghosts[number].appearance='Y';

game.ghosts[number].location[0]=7;

game.ghosts[number].location[1]=10;

break;

}

case 1:

{

game.ghosts[number].appearance='T';

game.ghosts[number].location[0]=9;

game.ghosts[number].location[1]=9;

break;

}

case 2:

{

game.ghosts[number].appearance='T';

game.ghosts[number].location[0]=9;

game.ghosts[number].location[1]=11;

break;

}

case 3:

{

game.ghosts[number].appearance='Y';

game.ghosts[number].location[0]=9;

game.ghosts[number].location[1]=10;

break;

}

}

game.ghosts[number].mood=follow;

game.ghosts[number].under=32;

game.map[game.ghosts[number].location[0]][game.ghosts[number].location[1]]=game.ghosts[number].appearance;

}

bool can_do_move(char ch)

{

if(if_it_wall(ch)||if_it_ghost(ch))

return false;

return true;

}

bool analys_ghosts_locations(void)

{

int move[2];

Sleep(200);

for(int i=0;i<4;i++)

{

switch(game.ghosts[i].mood)

{

case walk:

{

random_move(move,game.ghosts[i].location[0],game.ghosts[i].location[1]);

if(!can_do_move(game.map[move[0]][move[1]]))

break;

if(game.map[move[0]][move[1]]==2)

{

game.map[game.ghosts[i].location[0]][game.ghosts[i].location[1]]=game.ghosts[i].under;

MoveCursor(game.ghosts[i].location[1],game.ghosts[i].location[0]);

SetCursorVisibility(false);

cout<<" ";

game.map[move[0]][move[1]]='X';

MoveCursor(move[1],move[0]);

SetCursorVisibility(false);

SetTextColor(red);

cout<<"X";

Sleep(500);

game.health--;

show_health();

if(game.health==0)

return true;

game.dots=150;

made_basic_characters_locations();

made_basic_map();

ClearScreen();

show_map();

break;

}

game.map[game.ghosts[i].location[0]][game.ghosts[i].location[1]]=game.ghosts[i].under;

MoveCursor(game.ghosts[i].location[1],game.ghosts[i].location[0]);

SetCursorVisibility(false);

switch(game.ghosts[i].under)

{

case '.':

{

SetTextColor(cyan);

cout<<".";

break;

}

case '+':

{

SetTextColor(red);

cout<<"+";

break;

}

case 32:

cout<<" ";

break;

}

game.ghosts[i].under=game.map[move[0]][move[1]];

game.ghosts[i].location[0]=move[0];

game.ghosts[i].location[1]=move[1];

game.map[move[0]][move[1]]=game.ghosts[i].appearance;

MoveCursor(game.ghosts[i].location[1],game.ghosts[i].location[0]);

SetCursorVisibility(false);

switch(game.ghosts[i].appearance)

{

case 'T':

{

SetTextColor(green);

cout<<"T";

break;

}

case 'Y':

{

SetTextColor(pink);

cout<<"Y";

break;

}

case 'u':

{

SetTextColor(dark_green);

cout<<"u";

break;

}

}

break;

}

case follow:

{

if(if_in_radius(game.ghosts[i].location[0],game.ghosts[i].location[1],game.ghosts[i].radius))

{

made_matrix();

find_way(game.pacman.location[0],game.pacman.location[1],game.ghosts[i].location[0],game.ghosts[i].location[1],game.ghosts[i].location[0],game.ghosts[i].location[1],0);

if(matrix[game.pacman.location[0]][game.pacman.location[1]]==300)

break;

find_right_move(move,game.pacman.location[0],game.pacman.location[1]);

}

else

{

random_move(move,game.ghosts[i].location[0],game.ghosts[i].location[1]);

if(!can_do_move(game.map[move[0]][move[1]]))

break;

}

if(game.map[move[0]][move[1]]==2)

{

game.map[game.ghosts[i].location[0]][game.ghosts[i].location[1]]=game.ghosts[i].under;

MoveCursor(game.ghosts[i].location[1],game.ghosts[i].location[0]);

SetCursorVisibility(false);

cout<<" ";

game.map[move[0]][move[1]]='X';

MoveCursor(move[1],move[0]);

SetCursorVisibility(false);

SetTextColor(red);

cout<<"X";

Sleep(500);

game.health--;

show_health();

if(game.health==0)

return true;

game.dots=150;

made_basic_characters_locations();

made_basic_map();

ClearScreen();

show_map();

break;

}

game.map[game.ghosts[i].location[0]][game.ghosts[i].location[1]]=game.ghosts[i].under;

MoveCursor(game.ghosts[i].location[1],game.ghosts[i].location[0]);

SetCursorVisibility(false);

switch(game.ghosts[i].under)

{

case '.':

{

SetTextColor(cyan);

cout<<".";

break;

}

case '+':

{

SetTextColor(red);

cout<<"+";

break;

}

case 32:

cout<<" ";

break;

}

game.ghosts[i].under=game.map[move[0]][move[1]];

game.ghosts[i].location[0]=move[0];

game.ghosts[i].location[1]=move[1];

game.map[move[0]][move[1]]=game.ghosts[i].appearance;

MoveCursor(game.ghosts[i].location[1],game.ghosts[i].location[0]);

SetCursorVisibility(false);

switch(game.ghosts[i].appearance)

{

case 'T':

{

SetTextColor(green);

cout<<"T";

break;

}

case 'Y':

{

SetTextColor(pink);

cout<<"Y";

break;

}

}

break;

}

case eaten:

basic_ghosts_decriptions(i);

break;

}

}

return false;

}

bool analys_pacman_locations(void)

{

int next_location[2];

next_location[0]=game.pacman.location[0];

next_location[1]=game.pacman.location[1];

switch(game.pacman.direction)

{

case up:

next_location[0]-=1;

break;

case down:

next_location[0]+=1;

break;

case Right:

next_location[1]+=1;

break;

case Left:

next_location[1]-=1;

break;

}

if(game.pacman.location[0]==9&&game.pacman.location[1]==0&&game.pacman.direction==Left)

{

next_location[0]=9;

next_location[1]=20;

}

if(game.pacman.location[0]==9&&game.pacman.location[1]==20&&game.pacman.direction==Right)

{

next_location[0]=9;

next_location[1]=0;

}

if(if_it_wall(game.map[next_location[0]][next_location[1]]))

return false;

if(game.map[next_location[0]][next_location[1]]=='.')

{

game.dots--;

game.points+=10;

MoveCursor(13,21);

SetCursorVisibility(false);

SetTextColor(sky);

cout<<game.points;

if(game.points%1000==0)

{

game.health++;

show_health();

}

if(game.dots==0)

{

made_basic_descriptions(false);

ClearScreen();

show_map();

return false;

}

game.map[game.pacman.location[0]][game.pacman.location[1]]=32;

MoveCursor(game.pacman.location[1],game.pacman.location[0]);

SetCursorVisibility(false);

cout<<" ";

game.pacman.location[0]=next_location[0];

game.pacman.location[1]=next_location[1];

game.map[next_location[0]][next_location[1]]=2;

MoveCursor(game.pacman.location[1],game.pacman.location[0]);

SetCursorVisibility(false);

SetTextColor(yellow);

cout<<char(2);

return false;

}

if(game.map[next_location[0]][next_location[1]]=='+')

{

game.dots--;

game.points+=50;

MoveCursor(13,21);

SetCursorVisibility(false);

SetTextColor(sky);

cout<<game.points;

if(game.points%1000==0)

{

game.health++;

show_health();

}

if(game.dots==0)

{

made_basic_descriptions(false);

ClearScreen();

show_map();

return false;

}

game.map[game.pacman.location[0]][game.pacman.location[1]]=32;

MoveCursor(game.pacman.location[1],game.pacman.location[0]);

SetCursorVisibility(false);

cout<<" ";

game.pacman.location[0]=next_location[0];

game.pacman.location[1]=next_location[1];

game.map[next_location[0]][next_location[1]]=2;

MoveCursor(game.pacman.location[1],game.pacman.location[0]);

SetCursorVisibility(false);

SetTextColor(yellow);

cout<<char(2);

for(int i=0;i<4;i++)

if(game.ghosts[i].mood!=eaten)

{

game.ghosts[i].appearance='u';

game.ghosts[i].mood=walk;

game.map[game.ghosts[i].location[0]][game.ghosts[i].location[1]]='u';

MoveCursor(game.ghosts[i].location[1],game.ghosts[i].location[0]);

SetCursorVisibility(false);

SetTextColor(dark_green);

cout<<"u";

}

return false;

}

if(game.map[next_location[0]][next_location[1]]=='Y'||game.map[next_location[0]][next_location[1]]=='T')

{

game.map[game.pacman.location[0]][game.pacman.location[1]]=32;

MoveCursor(game.pacman.location[1],game.pacman.location[0]);

SetCursorVisibility(false);

cout<<" ";

game.map[next_location[0]][next_location[1]]='X';

MoveCursor(next_location[1],next_location[0]);

SetCursorVisibility(false);

SetTextColor(red);

cout<<"X";

Sleep(500);

game.health--;

show_health();

if(game.health==0)

return true;

game.dots=150;

made_basic_characters_locations();

made_basic_map();

ClearScreen();

show_map();

return false;

}

if(game.map[next_location[0]][next_location[1]]=='u')

{

game.points+=300;

MoveCursor(13,21);

SetCursorVisibility(false);

SetTextColor(sky);

cout<<game.points;

game.health++;

show_health();

if(game.points%1000==0)

{

game.health++;

show_health();

}

game.map[game.pacman.location[0]][game.pacman.location[1]]=32;

MoveCursor(game.pacman.location[1],game.pacman.location[0]);

SetCursorVisibility(false);

cout<<" ";

game.pacman.location[0]=next_location[0];

game.pacman.location[1]=next_location[1];

game.map[next_location[0]][next_location[1]]=2;

MoveCursor(game.pacman.location[1],game.pacman.location[0]);

SetCursorVisibility(false);

SetTextColor(yellow);

cout<<char(2);

for(int i=0;i<4;i++)

if(game.ghosts[i].location[0]==next_location[0]&&game.ghosts[i].location[1]==next_location[1])

{

game.ghosts[i].mood=eaten;

if(game.ghosts[i].under=='.')

{

game.dots--;

game.points+=10;

MoveCursor(13,21);

SetCursorVisibility(false);

SetTextColor(sky);

cout<<game.points;

if(game.points%1000==0)

{

game.health++;

show_health();

}

if(game.dots==0)

{

made_basic_descriptions(false);

ClearScreen();

show_map();

return false;

}

}

if(game.ghosts[i].under=='+')

{

game.dots--;

game.points+=50;

MoveCursor(13,21);

SetCursorVisibility(false);

SetTextColor(sky);

cout<<game.points;

if(game.points%1000==0)

{

game.health++;

show_health();

}

if(game.dots==0)

{

made_basic_descriptions(false);

ClearScreen();

show_map();

return false;

}

}

}

return false;

}

if(game.map[next_location[0]][next_location[1]]==32)

{

game.map[game.pacman.location[0]][game.pacman.location[1]]=32;

MoveCursor(game.pacman.location[1],game.pacman.location[0]);

SetCursorVisibility(false);

cout<<" ";

game.pacman.location[0]=next_location[0];

game.pacman.location[1]=next_location[1];

game.map[next_location[0]][next_location[1]]=2;

MoveCursor(game.pacman.location[1],game.pacman.location[0]);

SetCursorVisibility(false);

SetTextColor(yellow);

cout<<char(2);

return false;

}

}

bool made_move(void)

{

bool playing=true;

show_map();

while (playing)

{

playing=!analys_ghosts_locations();

if(!playing)

return false;

// Какая-нибудь клавиша нажата?

if (_kbhit())

{

// Получить её код

unsigned char code = _getch();

// Если это функциональная клавиша ...

if (code == 0 || code == 0xE0)

{

// то получить расширенный код

code = _getch();

switch (code)

{

case 72://Нажата клавиша ВВЕРХ

game.pacman.direction=up;

break;

case 80://Нажата клавиша ВНИЗ

game.pacman.direction=down;

break;

case 75://Нажата клавиша ВЛЕВО

game.pacman.direction=Left;

break;

case 77://Нажата клавиша ВПРАВО

game.pacman.direction=Right;

break;

}

playing=!analys_pacman_locations();

}

else

if(code==27)//Нажата клавиша ESC

playing=false;

}

}

return false;

}

void show_rules_and_controls(void)

{

MoveCursor(3,1);

SetTextColor(red);

cout<<"R U L E S :"<<endl<<endl;

SetTextColor(yellow);

cout<<" "<<char(2);

SetTextColor(grey);

cout<<" - ";

SetTextColor(white);

cout<<"Pacy-Pacy Man."<<endl<<endl;

SetTextColor(green);

cout<<" T";

SetTextColor(grey);

cout<<" - ";

SetTextColor(white);

cout<<"two twin brothers-ghosts: Tinky & Tanky."<<endl<<" They haunt Pacy-Pacy Man from every place on the map."<<endl<<endl;

SetTextColor(pink);

cout<<" Y";

SetTextColor(grey);

cout<<" - ";

SetTextColor(white);

cout<<"two twin brothers-ghosts: Yanny & Sunny."<<endl<<" They haunt Pacy-Pacy Man, if they can see him. They have their own radiuses of seeing, that are growing up during levels."<<endl<<endl;

SetTextColor(dark_green);

cout<<" u";

SetTextColor(grey);

cout<<" - ";

SetTextColor(white);

cout<<"little ghost, but also dangerous."<<endl<<" It can cautch Pacy-Pacy, but therefore Pacy-Pacy can eat little stupid ghost and get an extra-life."<<endl<<endl;

SetTextColor(cyan);

cout<<" .";

SetTextColor(grey);

cout<<" - ";

SetTextColor(white);

cout<<"kind of dot that gives Pacy-Pacy 10 points"<<endl<<endl;

SetTextColor(red);

cout<<" +";

SetTextColor(grey);

cout<<" - ";

SetTextColor(white);

cout<<"power pellet - another kind of dot that gives Pacy-Pacy 50 points and turns twin brothers ";

SetTextColor(green);

cout<<"T ";

SetTextColor(white);

cout<<"&";

SetTextColor(pink);

cout<<" Y ";

SetTextColor(white);

cout<<"to little stupid ghosts ";

SetTextColor(dark_green);

cout<<"u";

SetTextColor(white);

cout<<"."<<endl<<endl;

SetTextColor(sky);

cout<<" Aim of game ";

SetTextColor(grey);

cout<<"- ";

SetTextColor(white);

cout<<"to eat all dots on the map and go to the next level."<<endl;

cout<<" Tonnel on the map gives Pacy-Pacy a chance to save his life."<<endl;

cout<<" Pacy-Pacy Man gets an extra-life on every number multiple 1000."<<endl<<endl;

SetTextColor(red);

cout<<" C O N T R O L S :"<<endl<<endl;

SetTextColor(cyan);

cout<<" Player controls Pacy-Pacy Man."<<endl<<endl;

SetTextColor(white);

cout<<" "<<char(24)<<" - Up."<<endl<<" "<<char(25)<<" - Down."<<endl<<" "<<char(26)<<" - Right."<<endl<<" "<<char(27)<<" - Left."<<endl<<" ESC - exit level"<<endl;

}

int main()

{

SetCursorVisibility(false);

MoveCursor(3,3);

SetTextColor(sky);

cout<<"Pacy-Pacy, W E L C O M E!";

Sleep(800);

for(int i=1;i<29;i++)

{

SetTextColor(yellow);

MoveCursor(i-1,3);

cout<<" "<<char(2);

Sleep(100);

}

Sleep(200);

ClearScreen();

int choose;

do

{

SetTextColor(white);

cout<<"Menu:"<<endl<<" 1. Play game."<<endl<<" 2. Rules & controls."<<endl<<" 3. Exit."<<endl<<endl;

SetTextColor(grey);

cout<<"You wrote: ";

cin>>choose;

Sleep(200);

ClearScreen();

switch(choose)

{

case 1:

{

made_const_map();

made_basic_map();

made_basic_characters_locations();

made_basic_descriptions(true);

bool test=made_move();

if(!test)

{

ClearScreen();

MoveCursor(3,3);

SetTextColor(red);

cout<<"G A M E O V E R"<<endl;

MoveCursor(3,5);

SetTextColor(dark_green);

cout<<"Total score: ";

SetTextColor(sky);

cout<<game.points<<endl;

MoveCursor(3,6);

SetTextColor(dark_green);

cout<<"Total levels: ";

SetTextColor(sky);

cout<<game.number_level<<endl;

Sleep(3000);

ClearScreen();

break;

}

}

case 2:

{

show_rules_and_controls();

while(true)

if(_kbhit())

{

ClearScreen();

break;

}

}

case 3:

{

ClearScreen();

break;

}

}

}

while(choose!=3);

MoveCursor(3,3);

SetTextColor(green);

cout<<"G O O D B Y E , Pacy-Pacy!";

Sleep(800);

for(int i=32;i>0;i--)

{

SetTextColor(yellow);

MoveCursor(i+1,3);

cout<<char(2)<<" ";

Sleep(100);

}

Sleep(200);

return 0;

}