论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > C语言程序设计教程
Tag:新手,函数,指针,数据类型,对象,Turbo,入门,运算符,数组,结构,二级,,tc,游戏,试题,问答,编译,视频教程

TC写的“泡泡堂”(2)

文章类别:C语言程序设计 | 发表日期:2008-9-24 14:46:39

    /*----------------------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;
}



点这里下载
上一篇:{应用}TC写的“泡泡堂”(1) 人气:6817
下一篇:{应用}文曲星小游戏 人气:7377
视频教程列表
文章教程搜索
 
C语言程序设计推荐教程
C语言程序设计热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058