zoukankan      html  css  js  c++  java
  • 【CQgame】[下一百层] [Down]

    简单的下一百层的c++实现,代码一晚上就码完了

    注意:游戏前请在 默认值 或 属性 中调整缓冲区大小,否则会输出爆屏,方法写在代码里了

    觉得速度 快/慢 的可以在第 23 行手动改一下,相信大神们能看懂~

    /*************************************************************/

    /*
        < D O W N >
        **作者:CQzhangyu
        **使用说明:
        游戏时请在 窗口 上按 右键 打开菜单
        点击 默认值 ->
             布局 ->
          将 屏幕缓冲区 中的 高度 改为 9999
    */
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<iostream>
    #include<queue>
    #include<time.h>
    #include<conio.h>
    #include<windows.h>
    #define gowhite SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
    #define goyellow SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN|FOREGROUND_INTENSITY)
    #define gogreen SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN|FOREGROUND_INTENSITY)
    #define gored SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_INTENSITY)
    using namespace std;
    const int n=20,m=24,unit=20,len=5,sfall=2,smove=1,sdown=5,hei=7;
    int tot,depth,score,dead,px,py;
    char input;
    queue<int> qx,qy;
    void GOTO(int x,int y)
    {
        COORD pos = {x,y};
        HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
        SetConsoleCursorPosition(hOut, pos);
    }
    void pmenu()
    {
        GOTO(0,0);
        int i;
        printf("
    
    
    
    
    ");
        puts("          ╔═══════════════════════════╗");
        puts("          ║    ████      ███    █      █  █      █    ║");
        puts("          ║    █      █  █      █  █  █  █  ██    █    ║");
        puts("          ║    █      █  █      █  █  █  █  █  █  █    ║");
        puts("          ║    █      █  █      █  █  █  █  █  █  █    ║");
        puts("          ║    █      █  █      █  █  █  █  █  █  █    ║");
        puts("          ║    █      █  █      █    █  █    █    ██    ║");
        puts("          ║    ████      ███      █  █    █      █    ║");
        puts("          ╚═══════════════════════════╝");
        printf("
    
    
    ");
        puts("                           Press any key to start.");
        getch();
        system("cls");
        for(i=1;i<=n+1;i++)    printf("▼");
        printf("
    ");
        for(i=1;i<=m;i++)
        puts("║                                        ║");
        GOTO(50,3);
        printf("分 数:");
        GOTO(0,24);
    }
    int main()
    {
        srand(time(NULL));
        pmenu();
        qx.push((n-len)/2+1);
        qy.push(23);
        GOTO(n-len+3,23);
        int i,tx,ty;
        for(i=0;i<len;i++)
        printf("█");
        px=n/2;
        py=22;
        GOTO(n+2,22);
        goyellow;
        printf("●");
        gowhite;
        while(!dead)
        {
            tot++;
            if(tot%smove==0)
            {
                while(kbhit())
                {
                    input=_getch();
                    if(input=-32)
                    {
                        input=_getch();
                        if(input==75&&px>0&&(py!=qy.front()||px>qx.front()+len))
                        {
                            GOTO(px*2+2,py);
                            printf("  ");
                            px--;
                            GOTO(px*2+2,py);
                            goyellow;
                            printf("●");
                            gowhite;
                        }
                        if(input==77&&px<n-1&&(py!=qy.front()||px<qx.front()-1))
                        {
                            GOTO(px*2+2,py);
                            printf("  ");
                            px++;
                            goyellow;
                            printf("●");
                            gowhite; 
                        }
                    }
                }
            }
            if(tot%sdown==0)
            {
                depth++;
                if(py==depth)
                {
                    dead=1;
                    break;
                }
                GOTO(0,depth);
                for(i=1;i<=n+2;i++)    printf("▼");
                GOTO(50,depth+2);
                printf("           ");
                GOTO(50,depth+3);
                printf("分 数:");
                gogreen;
                printf("%04d",score);
                gowhite;
                GOTO(0,depth+23);
                puts("║                                        ║");
                if(depth%hei==0)
                {
                    score++;
                    tx=rand()%(n-len+1);
                    ty=depth+23;
                    qx.push(tx);
                    qy.push(depth+23);
                    GOTO(tx*2+2,ty);
                    for(i=1;i<=len;i++)
                        printf("█");
                }
            }
            if(tot%sfall==0)
            {
                while(!qy.empty()&&qy.front()<py)
                {
                    qx.pop();
                    qy.pop();
                }
                if(qy.empty()||py+1!=qy.front()||px<qx.front()||px>=qx.front()+len)
                {
                    GOTO(px*2+2,py);
                    printf("  ");
                    py++;
                    GOTO(px*2+2,py);
                    goyellow;
                    printf("●");
                    gowhite;
                }
            }
            if(py>=depth+24)
            {
                dead=1;
                break;
            }
            GOTO(0,depth+24);
            Sleep(unit);
        }
        GOTO(50,depth+15);
        gored;
        printf("---Game Over---");
        gowhite;
        GOTO(0,depth+24);
        getch();
        return 0;
    }

    | 欢迎来原网站坐坐! >原文链接<

  • 相关阅读:
    Reactive(1) 从响应式编程到"好莱坞"
    [动图演示]Redis 持久化 RDB/AOF 详解与实践
    补习系列(22)-全面解读 Spring Profile 的用法
    Android手机打造你的Python&Java开发工具!
    人工神经网络模型种类
    最小二乘拟合
    LDA主体模型
    Logistic Regression求解classification问题
    batch gradient descent(批量梯度下降) 和 stochastic gradient descent(随机梯度下降)
    SVM实验
  • 原文地址:https://www.cnblogs.com/CQzhangyu/p/6149482.html
Copyright © 2011-2022 走看看