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

}

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 0;

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)

{

end=f;

cleardevice();

return 1;

}                                 

}

}

}

ShowPlayer(x,y);

sleep(100);

}    

}

int Labirint2 (void) //прорисовка 2-го лабиринта и игра в нем))

{

begin=f;

Time ();

int l=2;

int k1ey = 0;

int pos_x=0;

int pos_y=0;

xe=20;

ye=380;

int lab[11][16]={0,0,1,0,0,0,1,1,1,1,0,0,0,0,0,0,

1,0,1,0,1,0,1,0,0,0,0,1,0,1,1,1,

0,0,0,0,1,0,1,0,1,0,1,1,0,0,0,0,

1,1,1,0,1,0,0,0,1,0,0,0,0,1,1,0,

0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,

1,1,0,1,1,0,0,0,1,0,0,0,0,0,0,1,

0,0,0,0,0,0,1,1,1,0,1,0,1,1,0,1,

0,1,1,1,1,1,1,0,0,0,1,0,1,0,0,1,

1,1,0,0,0,0,0,0,1,1,1,0,0,0,1,1,

3,1,1,1,0,1,1,1,1,0,0,0,1,0,0,1,

0,0,0,0,0,1,0,0,0,0,1,1,1,1,0,1};

BadObject massB[4];

massB[0].xst = 140;                      massB[0].yst = 0;

massB[0].xk = 140;                       massB[0].yk = 180;

massB[0].napr = 4;                

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

massB[1].xst = 500;                      massB[1].yst = 0;

massB[1].xk = 500;                       massB[1].yk = 140;

massB[1].napr = 4;                

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

massB[2].xst = 380;                      massB[2].yst = 220;

massB[2].xk =  600;                      massB[2].yk =  220;

massB[2].napr = 1;

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

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

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

massB[3].napr = 1;

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

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<4;i++)

{

Life (l);

massB[i].Paint(BLACK);

massB[i].Move();

massB[i].Paint(GREEN);

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

{

l--;

if(Life (l)==0)

{

return 0;

}

}

}

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 0;

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)

{

end=f;

cleardevice();

return 1;

}

}

}

}

ShowPlayer(x,y);

sleep(100);

}

}

void Labirint3 (void) // прорисовка 3-го лабиринта и игра в нем))

{

begin=f;

int l=1;

int key = 0;

int pos_x=0;

int pos_y=0;

xe=260;

ye=180;

int lab[11][16]={0,0,0,0,0,0,1,0,0,0,0,0,1,1,1,0,

1,1,1,0,1,0,0,0,1,0,1,0,0,0,0,0,

0,0,0,0,1,1,1,1,1,0,1,1,1,1,1,0,

0,1,1,0,0,3,1,0,0,0,0,0,0,1,0,0,

0,0,1,1,1,1,3,1,1,0,1,1,1,1,1,0,

1,0,1,0,0,1,0,1,0,0,1,0,0,0,0,0,

1,0,1,1,0,1,0,1,1,1,1,0,1,1,0,1,

0,0,0,1,0,1,0,1,0,1,0,0,1,0,0,1,

1,1,0,0,0,1,0,0,0,1,1,0,0,0,1,1,

0,1,0,1,0,0,1,0,0,0,0,0,1,0,0,0,

0,0,0,1,1,1,1,1,0,1,1,0,1,0,1,1};

BadObject massB[8];

massB[0].xst = 100;                      massB[0].yst = 280;

massB[0].xk = 100;                       massB[0].yk = 420;