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

rectangle (220,85, 420,135);

rectangle (220,175, 420,225);

rectangle (220,265, 420,315);

rectangle (220,355, 420,405);

int key2=0;

CurShow (xc,yc);

do

{

key2=getch();

switch (key2)

{

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)

{    

ft=0;st=0;f=0;

begin=clock();

cleardevice();

this->Level1();

}

if (yc==200)

{

ft=0;st=0;f=0;

begin=clock();

cleardevice();

this->Level2();

}

if (yc==290)

{

ft=0;st=0;f=0;

begin=clock();

cleardevice();

this->Level3();

return;

}

if (yc==380)

{

cleardevice();

return ;

}

}

}while(true);

}

void Level3(void) //запуск третьего уровня

{

for (int x2=200; x2<=440; x2++)

{    

setcolor (12);

settextstyle( DEFAULT_FONT, HORIZ_DIR, 32 );

outtextxy( 320, 140, "Level 3" );

setcolor (1);

settextstyle( DEFAULT_FONT, HORIZ_DIR, 20 );

outtextxy( 320, 240, "Загрузка..." );

setcolor (14);

line (x2,220,x2,260);

sleep (5);

}

Pole ();

cleardevice();   

Labirint3();

}

void Level2(void) //запуск второго уровня

{    

for (int x2=200; x2<=440; x2++)

{    

setcolor (12);

settextstyle( DEFAULT_FONT, HORIZ_DIR, 32 );

outtextxy( 320, 140, "Level 2" );

setcolor (1);

settextstyle( DEFAULT_FONT, HORIZ_DIR, 20 );

outtextxy( 320, 240, "Загрузка..." );

setcolor (14);

line (x2,220,x2,260);

sleep (5);

}

Pole ();

cleardevice();   

if(Labirint2())

this->Level3();

else return;

}

void Level1(void) //запуск первого уровня

{

for (int x2=200; x2<=440; x2++)

{    

setcolor (12);

settextstyle( DEFAULT_FONT, HORIZ_DIR, 32 );

outtextxy( 320, 140, "Level 1" );

setcolor (1);

settextstyle( DEFAULT_FONT, HORIZ_DIR, 20 );

outtextxy( 320, 240, "Загрузка..." );

setcolor (14);

line (x2,220,x2,260);

sleep (5);

}

Pole();

cleardevice();   

if(Labirint1())

this->Level2();

else return;

}

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

{

begin=clock();

int l=3;

int key = 0;

int pos_x=0;

int pos_y=0;

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

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

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

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

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

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

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

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

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

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

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

BadObject massB[3];

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

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

massB[0].napr = 1;

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

massB[1].xst = 180;                      massB[1].yst = 220;

massB[1].xk = 400;                       massB[1].yk = 220;

massB[1].napr = 1;

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

massB[2].xst = 420;                      massB[2].yst = 100;

massB[2].xk =  640;                      massB[2].yk =  100;

massB[2].napr = 1;

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

xe=620;

ye=20;

Exit (xe,ye);

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