Программирование компьютерной графики. Создание игры «Опасный лабиринт», страница 7

massB[0].napr = 4;

massB[0].xt = massB[0].xst;        massB[0].yt = massB[0].yst;

massB[1].xst = 60;                       massB[1].yst = 20;

massB[1].xk = 240;                       massB[1].yk = 20;

massB[1].napr = 1;

massB[1].xt = massB[1].xst;        massB[1].yt = massB[1].yst;

massB[2].xst = 300;                      massB[2].yst = 20;

massB[2].xk =  480;                      massB[2].yk =  20;

massB[2].xt = massB[2].xst;        massB[2].yt = massB[2].yst;

massB[2].napr = 1;     

massB[3].xst = 340;                      massB[3].yst = 280;

massB[3].xk =  340;                      massB[3].yk =  420;

massB[3].xt = massB[3].xst;        massB[3].yt = massB[3].yst;

massB[3].napr = 4;

massB[4].xst = 460;                      massB[4].yst = 220;

massB[4].xk =  640;                      massB[4].yk =  220;

massB[4].xt = massB[4].xst;        massB[4].yt = massB[4].yst;

massB[4].napr = 1;

massB[5].xst = 460;                      massB[5].yst = 240;

massB[5].xk =  460;                      massB[5].yk =  420;

massB[5].xt = massB[5].xst;        massB[5].yt = massB[5].yst;

massB[5].napr = 4;

massB[6].xst = 540;                      massB[6].yst = 280;

massB[6].xk =  540;                      massB[6].yk =  420;

massB[6].xt = massB[6].xst;        massB[6].yt = massB[6].yst;

massB[6].napr = 4;

massB[7].xst = 620;                      massB[7].yst = 0;

massB[7].xk =  620;                      massB[7].yk =  220;

massB[7].xt = massB[7].xst;        massB[7].yt = massB[7].yst;

massB[7].napr = 4;

L1: cleardevice ();

for (int k=0; k<16; k++)

{

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

{

if (lab[k][j]==1)

{

ys=k*40;

xs=j*40;

Stenka (xs,ys);

}

}

}

srand(time(NULL));

x = pos_x*40+20;

y = pos_y*40+20;

while(true)

{          

end=clock();

Time ();

Pole();

Exit (xe,ye);

HidePlayer(x,y);

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

{

Life (l);

massB[i].Paint(BLACK);

massB[i].Move();

massB[i].Paint(GREEN);

if (x==massB[i].xt && y==massB[i].yt)

{

GameOver();

return ;

}

}

x = pos_x*40+20;

y = pos_y*40+20;

if(kbhit())

key = getch();

switch (key)

{

case KEY_UP:

pos_y--;

if (pos_y<0)

pos_y++;

else

if(lab[pos_y][pos_x]!= 1)

{

y=(pos_y+1)*40+20;

x=pos_x*40+20;

}

else

pos_y++;   

key=0;

break;

case KEY_DOWN:

pos_y++;

if(pos_y>10)

pos_y--;

else

if(lab[pos_y][pos_x]!= 1)

{

y=(pos_y-1)*40+20;

x=pos_x*40+20;

}

else

pos_y--;

key=0;

break;

case KEY_LEFT:

pos_x--;

if (pos_x<0)

pos_x++;

else

if(lab[pos_y][pos_x]!= 1)

{

y=pos_y*40+20;

x=(pos_x+1)*40+20;

}

else

pos_x++;

key=0;

break;

case KEY_RIGHT:

pos_x++;

if (pos_x>15)

pos_x--;

else

if(lab[pos_y][pos_x]!= 1)

{

y=pos_y*40+20;

x=(pos_x-1)*40+20;

}

else

pos_x--;                                             

key=0;

break;

case KEY_ESCAPE:

end=clock();

f=(end-begin)/CLK_TCK;

L2:   cleardevice ();

User_Menu1 ();

switch(m.UserMenu())

{

case 0:

cleardevice ();

key=0;

begin=clock();

goto L1;

break;

case 1:

cleardevice ();

return;

break;

case 2:

cleardevice ();

this->ReadFileRank ();

goto L2;

break;

}    

break;

}

for(int k=0; k<16; k++)

{

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

{

if (k==pos_y&&j==pos_x)

{

if(lab[k][j]==3)

{

cleardevice();

TheEnd ();

this->AddNewUser(ft);

sleep (20);

st=0;

ft=0;

f=0;

this->ReadFileRank();

return ;

}

}

}

}

ShowPlayer(x,y);

sleep(100);

}

}

};

class Game: public Play //начало игры

{

public:

int yc, xc;

Game ()

{

yc=110; xc=205;

}

void Zapusk () //запуск заставки и переход в главное меню

{

Screen ();

this -> Menu ();

}

void Menu () //описание главного меню

{

M1:   cleardevice();

MenuShow ();

CurShow (xc,yc);

do

{

key=getch();

switch (key)

{

case KEY_UP:

CurHide (xc,yc);

yc-=90; 

if (yc<110)

yc=380;

CurShow(xc,yc);

break;

case KEY_DOWN:

CurHide (xc,yc);

yc+=90; 

if (yc>380)

yc=110;

CurShow (xc, yc);

break;

case 13:

if (yc==110)

{    

cleardevice();

begin=clock();

this -> Labirint ();

}

if (yc==200)

{

this -> Vlvl(); //выбор уровня

goto M1;

}

if (yc==290)

{

this ->ReadFileRank (); //лучшие игроки

goto M1;

}

if (yc==380)

exit (0);

break;

}

}while (1);

}

void Labirint (void) //начало новой игры

{

this -> Level1 ();

this ->Menu ();

}

};

void main ()

{

int driver = DETECT, mode = 0;

initgraph( &driver, &mode, "" );

Game g;

g.Zapusk();

closegraph();

}