/*----------------------Down------------------------*/
for (i=1; i <= pao.len; ++i)
{
end = 0;
switch (map[pao.y+i][pao.x])
{
case '#':
end = 1;
break;
case ' ':
DrawBlast1(pao.x, pao.y+i);
map[pao.y+i][pao.x] = 'b';
break;
case '@':
end = 1;
DrawBlast1(pao.x, pao.y+i);
map[pao.y+i][pao.x] = 'a';
break;
case 'o':
if (FindElemDelete(Q, &e, pao.x, pao.y+i) == 1)
{
e.original_time = clock();
EnQueue(B, e);
PaoBlast(e, p1, p2, Q, B);
}
break;
default:
break;
}
if (p1->x == pao.x && p1->y == pao.y+i)
{
DrawPaoMan(*p1);
p1->can_move = CANNOT;
p1->old_time = clock();
}
else if (p2->x == pao.x && p2->y == pao.y+i)
{
DrawPaoMan(*p2);
p2->can_move = CANNOT;
p2->old_time = clock();
}
if (end == 1)
{
break;
}
}
/*---------------------Left-------------------------*/
for (i=1; i <= pao.len; ++i)
{
end = 0;
switch (map[pao.y][pao.x-i])
{
case '#':
end = 1;
break;
case ' ':
DrawBlast1(pao.x-i, pao.y);
map[pao.y][pao.x-i] = 'b';
break;
case '@':
end = 1;
DrawBlast1(pao.x-i, pao.y);
map[pao.y][pao.x-i] = 'a';
break;
case 'o':
if (FindElemDelete(Q, &e, pao.x-i, pao.y) == 1)
{
e.original_time = clock();
EnQueue(B, e);
PaoBlast(e, p1, p2, Q, B);
}
break;
default:
break;
}
if (p1->x == pao.x-i && p1->y == pao.y)
{
DrawPaoMan(*p1);
p1->can_move = CANNOT;
p1->old_time = clock();
}
else if (p2->x == pao.x-i && p2->y == pao.y)
{
DrawPaoMan(*p2);
p2->can_move = CANNOT;
p2->old_time = clock();
}
if (end == 1)
{
break;
}
}
/*----------------------Right-----------------------*/
for (i=1; i <= pao.len; ++i)
{
end = 0;
switch (map[pao.y][pao.x+i])
{
case '#':
end = 1;
break;
case ' ':
DrawBlast1(pao.x+i, pao.y);
map[pao.y][pao.x+i] = 'b';
break;
case '@':
end = 1;
DrawBlast1(pao.x+i, pao.y);
map[pao.y][pao.x+i] = 'a';
break;
case 'o':
if (FindElemDelete(Q, &e, pao.x+i, pao.y) == 1)
{
e.original_time = clock();
EnQueue(B, e);
PaoBlast(e, p1, p2, Q, B);
}
break;
default:
break;
}
if (p1->x == pao.x+i && p1->y == pao.y)
{
DrawPaoMan(*p1);
p1->can_move = CANNOT;
p1->old_time = clock();
}
else if (p2->x == pao.x+i && p2->y == pao.y)
{
DrawPaoMan(*p2);
p2->can_move = CANNOT;
p2->old_time = clock();
}
if (end == 1)
{
break;
}
}
}
/*擦除爆炸痕迹的函数*/
void EraseBlast(PAO pao, man *p1, man *p2)
{
int i = 1, end = 0;
gotoxy(pao.x+15, pao.y+6);
putch(' ');
map[pao.y][pao.x] = ' ';
if (p1->x == pao.x && p1->y == pao.y)
{
DrawPaoMan(*p1);
}
else if (p2->x == pao.x && p2->y == pao.y)
{
DrawPaoMan(*p2);
}
/*----------------------UP-------------------*/
for (; i <= pao.len; ++i)
{
end = 0;
switch (map[pao.y-i][pao.x])
{
case 'b':
map[pao.y-i][pao.x] = ' ';
gotoxy(pao.x+15, pao.y-i+6);
putch(' ');
break;
case 'a':
Treasure(pao.x, pao.y-i);
case '#':
end = 1;
break;
default:
break;
}
if (p1->x == pao.x && p1->y == pao.y-i && p1->can_move == CANNOT)
{
DrawPaoMan(*p1);
}
else if (p2->x == pao.x && p2->y == pao.y-i && p2->can_move == CANNOT)
{
DrawPaoMan(*p2);
}
if (end == 1)
{
break;
}
}
/*---------------DOWN-----------------*/
for (i=1; i <= pao.len; ++i)
{
end = 0;
switch (map[pao.y+i][pao.x])
{
case 'b':
map[pao.y+i][pao.x] = ' ';
gotoxy(pao.x+15, pao.y+i+6);
putch(' ');
break;
case 'a':
Treasure(pao.x, pao.y+i);
case '#':
end = 1;
break;
default:
break;
}
if (p1->x == pao.x && p1->y == pao.y+i && p1->can_move == CANNOT)
{
DrawPaoMan(*p1);
}
else if (p2->x == pao.x && p2->y == pao.y+i && p2->can_move == CANNOT)
{
DrawPaoMan(*p2);
}
if (end == 1)
{
break;
}
}
/*---------------LEFT-----------------*/
for (i=1; i <= pao.len; ++i)
{
end = 0;
switch (map[pao.y][pao.x-i])
{
case 'b':
map[pao.y][pao.x-i] = ' ';
gotoxy(pao.x+15-i, pao.y+6);
putch(' ');
break;
case 'a':
Treasure(pao.x-i, pao.y);
case '#':
end = 1;
break;
default:
break;
}
if (p1->x == pao.x-i && p1->y == pao.y && p1->can_move == CANNOT)
{
DrawPaoMan(*p1);
p1->can_move = CANNOT;
}
else if (p2->x == pao.x-i && p2->y == pao.y && p2->can_move == CANNOT)
{
DrawPaoMan(*p2);
p2->can_move = CANNOT;
}
if (end == 1)
{
break;
}
}
/*-------------RIGHT------------------*/
for (i=1; i <= pao.len; ++i)
{
end = 0;
switch (map[pao.y][pao.x+i])
{
case 'b':
map[pao.y][pao.x+i] = ' ';
gotoxy(pao.x+15+i, pao.y+6);
putch(' ');
break;
case 'a':
Treasure(pao.x+i, pao.y);
case '#':
end = 1;
break;
default:
break;
}
if (p1->x == pao.x+i && p1->y == pao.y && p1->can_move == CANNOT)
{
DrawPaoMan(*p1);
p1->can_move = CANNOT;
}
else if (p2->x == pao.x+i && p2->y == pao.y && p2->can_move == CANNOT)
{
DrawPaoMan(*p2);
p2->can_move = CANNOT;
}
if (end == 1)
{
break;
}
}
}
/*主函数*/
int main()
{
int END = 0;
int x, y;
man play1 = {1, 1, PLAY1, CAN, 1, 1}, play2 = {14, 1, PLAY2, CAN, 1, 1};
LinkQueue PaoQueue, BlastQueue;
int iCurrentTime, iOldTime;
PAO PaoHead, BlastHead;
for (y=0; y<Map_Y; ++y)
{
for (x=0; x<Map_X; ++x)
{
map[y][x] = map1[y][x];
}
}
clrscr();
randomize();
/*显示游戏开始画面*/
DrawBegin();
getch();
clrscr();
/*开始游戏,先画地图*/
DrawMap();
/*画出两个人来*/
DrawMan(play1);
DrawMan(play2);
/*初始化泡泡队列和爆炸队列*/
InitalQueue(&PaoQueue);
InitalQueue(&BlastQueue);
InstallKeyboard();
iOldTime = clock();
/*游戏主循环——接受按键并执行相关操作*/
while (END != 1)
{
if (GetKey(KEY_ESC))
{
END=1;
}
/*---------Play1--------------*/
if (GetKey(PLAY1UP))
{
if (!MoveUp(&play1, &play2))
{
while (clock() - iOldTime <= WIN_DELAY);
END = 1;
}
}
if (GetKey(PLAY1DOWN))
{
if (!MoveDown(&play1, &play2))
{
while (clock() - iOldTime <= WIN_DELAY);
END = 1;
}
}
if (GetKey(PLAY1LEFT))
{
if (!MoveLeft(&play1, &play2))
{
while (clock() - iOldTime <= WIN_DELAY);
END = 1;
}
}
if (GetKey(PLAY1RIGHT))
{
if (!MoveRight(&play1, &play2))
{
while (clock() - iOldTime <= WIN_DELAY);
END = 1;
}
}
if (GetKey(PLAY1FIRE))
{
Paopao(&play1, &PaoQueue);
}
/*---------Play2--------------*/
if (GetKey(PLAY2UP))
{
if (!MoveUp(&play2, &play1))
{
while (clock() - iOldTime <= WIN_DELAY);
END = 1;
}
}
if (GetKey(PLAY2DOWN))
{
if (!MoveDown(&play2, &play1))
{
while (clock() - iOldTime <= WIN_DELAY);
END = 1;
}
}
if (GetKey(PLAY2LEFT))
{
if (!MoveLeft(&play2, &play1))
{
while (clock() - iOldTime <= WIN_DELAY);
END = 1;
}
}
if (GetKey(PLAY2RIGHT))
{
if (!MoveRight(&play2, &play1))
{
while (clock() - iOldTime <= WIN_DELAY);
END = 1;
}
}
if (GetKey(PLAY2FIRE))
{
Paopao(&play2, &PaoQueue);
}
/*---------Ok! we check if the pao is blast!----------------*/
/*循环一次就检查泡泡的爆炸时间到了没有*/
iCurrentTime = clock();
if (QueueHead(&PaoQueue, &PaoHead))
{
if ((iCurrentTime - PaoHead.original_time) >= PAO_TIME)
{
DeQueue(&PaoQueue);
map[PaoHead.y][PaoHead.x] = ' ';
gotoxy(PaoHead.x+15, PaoHead.y+6);
putch(' ');
/* blast */
PaoBlast(PaoHead, &play1, &play2, &PaoQueue, &BlastQueue);
PaoHead.original_time = iCurrentTime;
EnQueue(&BlastQueue, PaoHead);
}
}
/*检查是不是应该擦除爆炸痕迹了*/
if (QueueHead(&BlastQueue, &BlastHead))
{
if ((iCurrentTime - BlastHead.original_time) >= BLAST_TIME)
{
DeQueue(&BlastQueue);
/*-- Erase the blast --*/
EraseBlast(BlastHead, &play1, &play2);
}
}
/*检查人物被炸后,有没有到恢复时间*/
if (play1.can_move == CANNOT)
{
if (iCurrentTime - play1.old_time >= PAOMAN_DELAY)
{
play1.can_move = CAN;
DrawMan(play1);
}
}
if (play2.can_move == CANNOT)
{
if (iCurrentTime - play2.old_time >= PAOMAN_DELAY)
{
play2.can_move = CAN;
DrawMan(play2);
}
}
/*拖延一段时间*/
while (clock() - iOldTime < TIME_DELAY);
iOldTime = clock();
/*假如按了ESC键或游戏结素,询问要不要重新开始*/
if (END == 1)
{
gotoxy(34, 3);
textcolor(WHITE);
printf("Play again?(y/n)");
while (1)
{
if (GetKey(KEY_Y))
{
DestroyQueue(&PaoQueue);
DestroyQueue(&BlastQueue);
InitalQueue(&PaoQueue);
InitalQueue(&BlastQueue);
for (y=0; y<Map_Y; ++y)
{
for (x=0; x<Map_X; ++x)
{
map[y][x] = map1[y][x];
}
}
play1.x = 1;
play1.y = 1;
play1.which = PLAY1;
play1.can_move = CAN;
play1.len = 1;
play1.pao_num = 1;
play2.x = 14;
play2.y = 1;
play2.which = PLAY2;
play2.can_move = CAN;
play2.len = 1;
play2.pao_num = 1;
textcolor(LIGHTBLUE);
clrscr();
DrawMap();
DrawMan(play1);
DrawMan(play2);
END = 0;
break;
}
else if (GetKey(KEY_N))
{
break;
}
}
}
}
ShutDownKeyboard();
DestroyQueue(&PaoQueue);
DestroyQueue(&BlastQueue);
return 0;
}
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |