问题标题: 蒟蒻的代码

0
0
已解决
王子豪
王子豪
资深守护
资深守护
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize(2)
#include<algorithm>               
#include<bitset>              
#include<cctype>              
#include<cerrno>              
#include<clocale>             
#include<cmath>                   
#include<complex>
#include<conio.h>
#include<cstdio>          
#include<cstdlib>         
#include<cstring>         
#include<ctime>   
#include<ctype.h>         
#include<cwchar>          
#include<cwctype>         
#include<deque> 
#include<exception>
#include<fstream>     
#include<functional>
#include<limits>      
#include<list>
#include<map>
#include<iomanip>     
#include<ios>
#include<iosfwd>
#include<iostream>    
#include<istream>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<stdlib.h>
#include<streambuf>
#include<string>
#include<time.h>
#include<utility>
#include<vector>  
#include<windows.h>   
#define A 17    //地图的高
#define B 17    //地图的宽
#define C 30    //雷的总数  
#define high 20 
#define width 60  
#define snake_maxlength 200         
using namespace std;
int h,w,c;
int xn_x,xn_y,b1,b2,b3;
char asd;
int snake_x[snake_maxlength],snake_y[snake_maxlength];
int snake_length;  
int food_x,food_y;
int score;  
char input; 
char primeinput='.'; 
int op;  
string s;
string ans="1";
bool tuichu;
HWND hwnd=GetForegroundWindow();    
RECT rect;                          
int xLeft,yTop;
DWORD a,b;
char map2[A][B],news,spare;
int BoomTotalNum,floatx,floaty,flag[A][B],flagnum,mode,slect[A][B],game;

//颜色属性
const WORD FORE_BLUE  =  FOREGROUND_BLUE;   //蓝色文本属性
const WORD FORE_GREEN = FOREGROUND_GREEN;   //绿色文本属性
const WORD FORE_RED   =   FOREGROUND_RED;   //红色文本属性
int clrscr(){                       
    HANDLE hndl=GetStdHandle(STD_OUTPUT_HANDLE); 
    CONSOLE_SCREEN_BUFFER_INFO csbi; 
    GetConsoleScreenBufferInfo(hndl,&csbi); 
    DWORD written; 
    DWORD N=csbi.dwSize.X*csbi.dwCursorPosition.Y+csbi.dwCursorPosition.X+1; 
    COORD curhome={0,0}; 
    FillConsoleOutputCharacter(hndl,' ',N,curhome,&written); 
    csbi.srWindow.Bottom-=csbi.srWindow.Top; 
    csbi.srWindow.Top=0; 
    SetConsoleWindowInfo(hndl,TRUE,&csbi.srWindow); 
    SetConsoleCursorPosition(hndl,curhome); 
    return 0;
}
void couts(string s,bool f){
    int cnt=0;
    for(int i=1;i<=(80-s.size())/2;i++){
        cout<<" ";
    }
    for(int i=0;i<s.size();i++,cnt++){
        if(cnt%12==1){
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
        }else if(cnt%12==3){
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
        }else if(cnt%12==5){
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
        }else if(cnt%12==7){
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |FOREGROUND_BLUE);
        }else if(cnt%12==9){
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);
        }else if(cnt%12==11){
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_BLUE);
        }
        cout<<s[i];
        if(f){
            Sleep(50);
        }
    }
    return ;
}
struct node {
    int x;
    int y;
};
queue <node> dui;

//打印位置
void position(int x,int y) {
    COORD pos={x,y};
    HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(Out,pos);
}

//隐藏光标 
void Hide() {
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);  
    CONSOLE_CURSOR_INFO CursorInfo;  
    GetConsoleCursorInfo(handle, &CursorInfo);//获取控制台光标信息  
    CursorInfo.bVisible = false; //隐藏控制台光标  
    SetConsoleCursorInfo(handle, &CursorInfo);//设置控制台光标状态   
}

//初始化
void Beginning() {
    while(!dui.empty()) {
        dui.pop();
    }
    game=1;
    //BoomTotalNum=C;
    floatx=A/2;
    floaty=B/2;
    flagnum=0;
    BoomTotalNum=C;
    mode=0;
    HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);    //获得标准输出设备句柄  
    CONSOLE_SCREEN_BUFFER_INFO csbi;                        //定义窗口缓冲区信息结构体  
    GetConsoleScreenBufferInfo(handle_out, &csbi);          //获得窗口缓冲区信息
    int x,y;
    srand((unsigned)time(0));
    for(int i=0;i<A;i++) for(int j=0;j<B;j++) {
        map2[i][j]=' ';
        flag[i][j]=0;
        slect[i][j]=0;
    }
    while(BoomTotalNum) {
        x=rand()%A;
        y=rand()%B;
        if(map2[x][y]==' ') {
            map2[x][y]='@';
            BoomTotalNum--;
        }
    }
    SetConsoleTextAttribute(handle_out, FORE_GREEN);  
    for(int i=0;i<A;i++) {
        for(int j=0;j<B;j++) printf("█");
        printf("\n");
    }
    position(floaty*2,floatx);
    SetConsoleTextAttribute(handle_out, FORE_RED);  
    printf("");    //光标位置
    position(44,9);
    printf("扫雷模式");
    position(44,5);
    printf("剩余雷数:%d ",C-flagnum);
    SetConsoleTextAttribute(handle_out, FORE_GREEN);  
    position(5,22);
    printf("按“空格”切换模式");
    position(5,23);
    printf("按“Enter”确认");
    position(5,24);
    printf("按“方向键”选择方块"); 

}

//打印地图的一块儿 
void Lump(int xx,int yy) {
    switch(map2[xx][yy]) {
        case '1' : printf("①");break;   //周围雷的数量(下同) 
        case '2' : printf("②");break;
        case '3' : printf("③");break;
        case '4' : printf("④");break;
        case '5' : printf("⑤");break;
        case '6' : printf("⑥");break;
        case '7' : printf("⑦");break;
        case '8' : printf("⑧");break;
        case ' ' :
            if(xx==floatx&&yy==floaty) {
                if(flag[xx][yy]==0) {
                    if(mode%2==0) printf("");
                    else printf("");
                }
                else printf("");
            }
            else {
                if(flag[xx][yy]==0) printf("█");
                else printf("");
            }
            break;
        case '@' :
            if(xx==floatx&&yy==floaty) {
                if(flag[xx][yy]==0) {
                    if(mode%2==0) printf("");
                    else printf("");
                }
                else printf("");
            }
            else {
                if(flag[xx][yy]==0) printf("█");
                else printf("");
            }
            break;
        case 'x' : if(floatx==xx&&floaty==yy) printf(""); else printf("  ");break; //已经挖开的空白
    }
}

//移动光标
void Move() {
    HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);    //获得标准输出设备句柄  
    CONSOLE_SCREEN_BUFFER_INFO csbi;                        //定义窗口缓冲区信息结构体  
    GetConsoleScreenBufferInfo(handle_out, &csbi);          //获得窗口缓冲区信息
    int xxx,yyy;
    xxx=floatx;
    yyy=floaty;
    switch(news) {
        case 72 : floatx--;break;   //上 
        case 80 : floatx++;break;   //下 
        case 75 : floaty--;break;   //左 
        case 77 : floaty++;break;   //右 
    }
    if(floatx==-1) floatx=A-1; floatx%=A;   //两端穿模处理 
    if(floaty==-1) floaty=B-1; floaty%=B;

    position(yyy*2,xxx);
    SetConsoleTextAttribute(handle_out, FORE_GREEN);
    Lump(xxx,yyy);  //删除原位置

    if(map2[floatx][floaty]=='x') {
        position(floaty*2,floatx);
        printf("  ");
    }

    position(floaty*2,floatx);
    SetConsoleTextAttribute(handle_out, FORE_BLUE);  
    Lump(floatx,floaty);    //更新新位置 
} 

//插旗和排雷模式切换 
void Mode() {
    HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);    //获得标准输出设备句柄  
    CONSOLE_SCREEN_BUFFER_INFO csbi;                        //定义窗口缓冲区信息结构体  
    GetConsoleScreenBufferInfo(handle_out, &csbi);          //获得窗口缓冲区信息
    mode++;
    SetConsoleTextAttribute(handle_out, FORE_BLUE);
    position(floaty*2,floatx);
    if(mode%2==0) printf("");
    else printf("");

    position(44,9);
    if(mode%2==0) {
        SetConsoleTextAttribute(handle_out, FORE_BLUE);  
        printf("扫雷模式");
    }
    else {
        SetConsoleTextAttribute(handle_out, FORE_RED);  
        printf("插旗模式");
    }
}

//该点周围地雷数 
int Boomnum(int xx,int yy) {
    int num=0;
    if((xx-1>=0)&&(yy-1>=0)&&(map2[xx-1][yy-1]=='@')) num++;
    if((xx-1>=0)&&(yy+0>=0)&&(map2[xx-1][yy]=='@')) num++;
    if((xx-1>=0)&&(yy+1<B) &&(map2[xx-1][yy+1]=='@')) num++;
    if((xx+0>=0)&&(yy-1>=0)&&(map2[xx][yy-1]=='@')) num++;
    if((xx+0>=0)&&(yy+1<B) &&(map2[xx][yy+1]=='@')) num++;
    if((xx+1<A)&&(yy-1>=0) &&(map2[xx+1][yy-1]=='@')) num++;
    if((xx+1<A)&&(yy+0>=0) &&(map2[xx+1][yy]=='@')) num++;
    if((xx+1<A)&&(yy+1<B)  &&(map2[xx+1][yy+1]=='@')) num++;
    return num;
}

//更新地图 
void Open() {
    node c;
    node d;
    while(!dui.empty()) {
        dui.pop();
    }
    c.x=floatx;
    c.y=floaty;
    dui.push(c);
    slect[c.x][c.y]=1;
    while(!dui.empty()) {
        c=dui.front();
        dui.pop();
        if(Boomnum(c.x,c.y)!=0) {
            map2[c.x][c.y]=(Boomnum(c.x,c.y)+48);
            continue;
        }
        else {
            map2[c.x][c.y]='x';                                                                                                                                                                                                                                                                                                                                                                                                                                     
            if((c.x-1>=0)&&(c.y-1>=0)&&(map2[c.x-1][c.y-1]==' ')&&(slect[c.x-1][c.y-1]==0)) {
                d.x=c.x-1;
                d.y=c.y-1;
                dui.push(d);
                slect[d.x][d.y]=1;
            }
            if((c.x-1>=0)&&(c.y-0>=0)&&(map2[c.x-1][c.y]==' ')&&(slect[c.x-1][c.y]==0)) {
                d.x=c.x-1;
                d.y=c.y-0;
                dui.push(d);
                slect[d.x][d.y]=1;
            }
            if((c.x-1>=0)&&(c.y+1<B)&&(map2[c.x-1][c.y+1]==' ')&&(slect[c.x-1][c.y+1]==0)) {
                d.x=c.x-1;
                d.y=c.y+1;
                dui.push(d);
                slect[d.x][d.y]=1;
            }
            if((c.x-0>=0)&&(c.y-1>=0)&&(map2[c.x][c.y-1]==' ')&&(slect[c.x][c.y-1]==0)) {
                d.x=c.x-0;
                d.y=c.y-1;
                dui.push(d);
                slect[d.x][d.y]=1;
            }
            if((c.x-0>=0)&&(c.y+1<B)&&(map2[c.x][c.y+1]==' ')&&(slect[c.x][c.y+1]==0)) {
                d.x=c.x-0;
                d.y=c.y+1;
                dui.push(d);
                slect[d.x][d.y]=1;
            }
            if((c.x+1<A)&&(c.y-1>=0)&&(map2[c.x+1][c.y-1]==' ')&&(slect[c.x+1][c.y-1]==0)) {
                d.x=c.x+1;
                d.y=c.y-1;
                dui.push(d);
                slect[d.x][d.y]=1;
            }
            if((c.x+1<A)&&(c.y-0>=0)&&(map2[c.x+1][c.y]==' ')&&(slect[c.x+1][c.y]==0)) {
                d.x=c.x+1;
                d.y=c.y-0;
                dui.push(d);
                slect[d.x][d.y]=1;
            }
            if((c.x+1<A)&&(c.y+1<B)&&(map2[c.x+1][c.y+1]==' ')&&(slect[c.x+1][c.y+1]==0)) {
                d.x=c.x+1;
                d.y=c.y+1;
                dui.push(d);
                slect[d.x][d.y]=1;
            }
        }
    }
}
void setdata(int map[20][60]){
    snake_x[0]=high/2;snake_y[0]=width/3; 
    snake_x[1]=high/2;snake_y[1]=width/3+1; 
    snake_length=2;   
    food_x=high/3,food_y=width/3;  
    score=0;
    int i,j;
    map[snake_x[0]][snake_y[0]]=4;  
    map[snake_x[1]][snake_y[1]]=1; 
    map[food_x][food_y]=2;
    for(i=0;i<high;i++)  
      for(j=0;j<width;j++)
        if(i==0||j==0||i==high-1||j==width-1)
           map[i][j]=3;   
} 
void gotoxy(int x,int y){
    HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);
    COORD pos;
    pos.X=x;
    pos.Y=y;
    SetConsoleCursorPosition(handle,pos);
}
void show(int map[20][60]){
    gotoxy(0,0);
    int i,j;
    for(i=0;i<high;i++){
        for(j=0;j<width;j++){
            if(map[i][j]==0)
            cout<<" ";
            else if(map[i][j]==1)
            cout<<"+";
            else if(map[i][j]==2)
            cout<<"@";
            else if(map[i][j]==3)
            cout<<"*";
            else if(map[i][j]==4)
            cout<<"0";
        }
        cout<<endl;
    }
    cout<<"得分"<<score<<"  ";
}
void updatewithoutinput(int map[20][60]){
    int i;
    if(snake_x[0]==food_x&&snake_y[0]==food_y){
        score++;
        srand((unsigned)time(NULL));  
        food_x=rand()%(high-3)+1;    
        food_y=rand()%(width-3)+1;
        map[food_x][food_y]=2; 
        snake_length++;
    }
    if(snake_x[0]==0||snake_x[0]==high-1||snake_y[0]==0||snake_y[0]==width-1){
        cout<<"游戏结束"<<endl;
        getch();
        exit(1);  
    }
    for(i=1;i<snake_length;i++) 
      if(snake_x[0]==snake_x[i]&&snake_y[0]==snake_y[i]){
        cout<<"游戏结束"<<endl;
        exit(1);
    }
} 
void updatewithinput(int map[20][60]){
    int i=1;
    if(kbhit()) 
      input=getch();
    if(input!='\0'){
        if(input=='w'||input=='a'||input=='s'||input=='d'){
            if(primeinput=='w'&&input=='s'||primeinput=='s'&&input=='w'||primeinput=='a'&&input=='d'||primeinput=='d'&&input=='a'){
                cout<<"贪吃蛇教会你的,是世上没有回头路,回头等于自焚"<<endl;   
                 exit(0); 
            }else
                primeinput=input;
        }
        else if(primeinput=='.')
            primeinput='w';
        else if(input=='p'){
            while(1){
                char op;
                op=getch();
                if(op=='p'){
                input='.';   
                break;
                }
            }
        }else if(input=='+'){
            if(op>=50)
                op=op/2;
        }
         else if(input=='-'){
            if(op<=1000) 
                op=op*2;
         }
        map[snake_x[snake_length-1]][snake_y[snake_length-1]]=0;
        for(i=snake_length-1;i>0;i--){
            snake_x[i]=snake_x[i-1];
            snake_y[i]=snake_y[i-1];  
            map[snake_x[i]][snake_y[i]]=1;
        } 

    }
    if(primeinput=='w')
        snake_x[0]--;
    else if(primeinput=='s')
        snake_x[0]++;
    else if(primeinput=='a')
        snake_y[0]--;
    else if(primeinput=='d')
        snake_y[0]++;
        map[snake_x[0]][snake_y[0]]=4;  
}
void tanchi(){
    int map[20][60]={0};
    setdata(map);
    while(1){
        show(map); 
        Sleep(op);
        updatewithoutinput(map);  
        updatewithinput(map);   
     }
     return ;
} 
void HideCursor(){
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_CURSOR_INFO CursorInfo;
    GetConsoleCursorInfo(handle, &CursorInfo);
    CursorInfo.bVisible = false;
    SetConsoleCursorInfo(handle, &CursorInfo);
}
void data(){
    h=15;
    w=25;
    xn_x=0;
    xn_y=w/3;
    b3=w;
    b1=h/4;
    b2=h/2;
}
void page(){
    int i,j;
    char dad ;
    if(c==0){
        system("color 0C");
        cout<<endl<<endl<<endl<<endl;
        s="=======================================";
        couts(s,0);
        cout<<endl;
        s="=          --->飞翔的小鸟<---         =";
        couts(s,0);
        cout<<endl;
        s="=                                     =";
        couts(s,0);
        cout<<endl;
        s="=           空格控制小鸟移动          =";
        couts(s,0);
        cout<<endl;
        s="=             5键暂停继续             =";
        couts(s,0);
        cout<<endl;
        s="=                                     =";
        couts(s,0);
        cout<<endl;
        s="=                                     =";
        couts(s,0);
        cout<<endl;
        s="=======================================";
        couts(s,0);
        cout<<endl;
        c++;
        dad=getch();
    }
    clrscr();
    system("color 02");
    for(i=0;i<h;i++){
        for(j=0;j<=w;j++){
            if(i==xn_x && j==xn_y){
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),14);
                printf("卐");
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),2);
            }
            else 
                if(j==b3&&(i<=b1||i>=b2)){
                    if(i==xn_x && j>xn_y){
                        printf("▓");
                    }
                    else   printf(" ▓");
                }
                else printf(" ");
        }
        printf("\n");
    }
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),9);
}
void saolei(){
    Relife: //重玩处
    HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);    //获得标准输出设备句柄  
    CONSOLE_SCREEN_BUFFER_INFO csbi;                        //定义窗口缓冲区信息结构体  
    GetConsoleScreenBufferInfo(handle_out, &csbi);          //获得窗口缓冲区信息
    Hide();     //隐藏光标
    Beginning();//初始化地图
    a=GetTickCount();
    while(1) {
        if(kbhit()!=0) {
            spare=getch();

            //按其他
            if((spare!=(-32))&&(spare!=13)&&(spare!=' ')) continue;//跳过 

            //按Enter
            if(spare==13) { //确认 
                //排雷
                if(mode%2==0) {
                    if(map2[floatx][floaty]=='@'&&flag[floatx][floaty]==0) {
                        break;  //触雷
                        game=0;
                    }

                    if(flag[floatx][floaty]==1) continue;   //有旗跳过
                    Open();
                    position(0,0);
                    SetConsoleTextAttribute(handle_out, FORE_GREEN);
                    for(int i=0;i<A;i++) {
                        for(int j=0;j<B;j++) Lump(i,j);
                        printf("\n");
                    }
                    position(floaty*2,floatx);
                    SetConsoleTextAttribute(handle_out, FORE_BLUE);
                    Lump(floatx,floaty);
                }

                //插拔旗
                else {

                    //不能插旗的地方
                    if(map2[floatx][floaty]=='x'||(map2[floatx][floaty]>'0'&&map2[floatx][floaty]<'9'))
                        continue;   //跳过

                    //插旗
                    if(flag[floatx][floaty]==0) {
                        flagnum++;
                        flag[floatx][floaty]=1;
                        position(floaty*2,floatx);
                        SetConsoleTextAttribute(handle_out, FORE_BLUE);
                        Lump(floatx,floaty);
                    }

                    //拔旗 
                    else {
                        flagnum--;
                        flag[floatx][floaty]=0;
                        position(floaty*2,floatx);
                        SetConsoleTextAttribute(handle_out, FORE_BLUE);
                        Lump(floatx,floaty);
                    }
                }
            }

            //按空格
            if(spare==' ') Mode();  //切换模式 

            //按方向键 
            if(spare==-32) {
                news=getch();
                Move(); //移动光标
            }
            for(int i=0;i<A;i++) for(int j=0;j<B;j++) if(map2[i][j]=='x'||(map2[i][j]>'0'&&map2[i][j]<'9')) game++;
            if(game==A*B-C+1) break;
            else game=1;
            SetConsoleTextAttribute(handle_out, FORE_RED);
            position(44,5);
            printf("剩余雷数:%d ",C-flagnum);
        }
        else Sleep(10);
        b=GetTickCount();
        SetConsoleTextAttribute(handle_out, FORE_RED);
        position(44,7);
        printf("用时:");  //用时 
        if((b-a)/60000<10) printf("0");
        printf("%d:",(b-a)/60000);
        if(((b-a)/1000)%60<10) printf("0");
        printf("%d:",((b-a)/1000)%60);
        if(((b-a)/10)%100<10) printf("0");
        printf("%d",((b-a)/10)%100);
    }
    SetConsoleTextAttribute(handle_out, FORE_RED);
    position(5,5);
    if(game==1) printf("游戏结束!");
    else printf("恭喜通关!");
    position(5,8);
    printf("任意键重玩");
    scanf("%c%c",&spare,&spare);
    system("cls");
    position(0,0);
    goto Relife;
} 
void pause(){
    s="请按任意键继续...";
    couts(s,0);
    char ch=getch();
    return ;
}
int adf[105],bx[105],d[105];
string Plus(string x,string y){
    memset(adf,0,sizeof(adf));
    memset(bx,0,sizeof(bx));
    memset(d,0,sizeof(d));
    adf[0]=x.size();
    bx[0]=y.size();
    d[0]=max(adf[0],bx[0]);
    int jw=0;
    for(int i=1;i<=adf[0];i++){
        adf[i]=x[adf[0]-i]-'0';
    }
    for(int i=1;i<=bx[0];i++){
        bx[i]=y[bx[0]-i]-'0';
    }
    for(int i=1;i<=d[0];i++){
        d[i]=adf[i]+bx[i];
        d[i]+=jw;
        jw=d[i]/10;
        d[i]%=10;
    }
    if(jw!=0){
        d[0]++;
        d[d[0]]=jw;
    }
    string ans="";
    for(int i=1;i<=d[0];i++){
        ans=char(d[i]+'0')+ans;
    }
    return ans;
}
void Chuangkou(){
    HideCursor();                   
    system("mode con cols=80 lines=25");
    GetWindowRect(hwnd,&rect);  
    xLeft=(GetSystemMetrics(SM_CXFULLSCREEN)-(rect.right-rect.left))/2;
    yTop=(GetSystemMetrics(SM_CYFULLSCREEN)-(rect.bottom-rect.top))/2;
    SetWindowPos(hwnd, HWND_TOPMOST,xLeft,yTop,-1,-1,SWP_NOSIZE|SWP_NOZORDER);
    SetWindowPos(hwnd, HWND_NOTOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
    return ;
}
void no(){
    int randx;
        if(xn_y==b3){
        if(xn_x>b1&&xn_x<b2)
            score++;
        else{
            system("color F0");
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),252);
            printf("                           ------>  the end  <------\n");
            c=3;
            asd=getch();
        }
    }
    xn_x++;
    if(b3==0){
        b3=w;
        b1=rand()%(h-5);
        randx=b1;
        b2=randx+h/4+2;
    }
    else
        b3--;
    Sleep(120);

}
void yes(){
    char input;
    if(kbhit()){
        input=getch();
        if(input==' ')     xn_x-=3;
        if(input=='5')    while(getch()!='5'){};//暂停继续  
    }
}
void xiaoniao(){
    data();//加载数据
    while(1){
        page();//页面
        no();//与用户无关变量
        yes();//与用户有关变量
        if(c==3)break;
    }
    return ;
}
void Jiazai(){
    for(int i=1;i<=100;i++){
        for(int j=1;j<=9;j++){
            cout<<endl;
        }
        s="加载中";
        if(i%6==1||i%6==2){
            s=s+".";
        }else if(i%6==3||i%6==4){
            s=s+"..";
        }else if(i%6==5||i%6==0){
            s=s+"...";
        }
        for(int i=1;i<=37;i++){
            cout<<" ";
        }
        int cnt=0;
        for(int i=0;i<s.size();i++,cnt++){
            if(cnt%12==1){
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
            }else if(cnt%12==3){
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
            }else if(cnt%12==5){
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
            }else if(cnt%12==7){
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |FOREGROUND_BLUE);
            }else if(cnt%12==9){
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);
            }else if(cnt%12==11){
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_BLUE);
            }
            cout<<s[i];
        }
        cout<<endl;
        s="(100/"+ans+")";
        for(int i=1;i<=36;i++){
            cout<<" ";
        }
        for(int i=0;i<s.size();i++,cnt++){
            if(cnt%12==1){
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
            }else if(cnt%12==3){
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
            }else if(cnt%12==5){
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
            }else if(cnt%12==7){
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |FOREGROUND_BLUE);
            }else if(cnt%12==9){
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);
            }else if(cnt%12==11){
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_BLUE);
            }
            cout<<s[i];
        }
        cout<<endl;
        ans=Plus(ans,"1");
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_BLUE);
        if(i%12==1){
            s="∷□■■";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
        }else if(i%12==2){
            s="  ∷□■";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
            cout<<endl;
            s="      ■";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
        }else if(i%12==3){
            s="    ∷□";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
            cout<<endl;
            s="      ■";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
            cout<<endl;
            s="      ■";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
        }else if(i%12==4){
            s="      ∷";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
            cout<<endl;
            s="      □";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
            cout<<endl;
            s="      ■";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
            cout<<endl;
            s="      ■";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
        }else if(i%12==5){
            cout<<endl;
            s="      ∷";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
            cout<<endl;
            s="      □";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
            cout<<endl;
            s="    ■■";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
        }else if(i%12==6){
            cout<<endl<<endl;
            s="      ∷";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
            cout<<endl;
            s="  ■■□";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
        }else if(i%12==7){
        cout<<endl<<endl<<endl;
            s="■■□∷";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
        }else if(i%12==8){
            cout<<endl<<endl;
            s="■";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
            cout<<endl;
            s="■□∷";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
        }else if(i%12==9){
            cout<<endl;
            s="■";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
            cout<<endl;
            s="■";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
            cout<<endl;
            s="□∷";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
        }else if(i%12==10){
            s="■";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
            cout<<endl;
            s="■";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
            cout<<endl;
            s="□";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
            cout<<endl;
            s="∷";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
        }else if(i%12==11){
            s="■■";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
            cout<<endl;
            s="□";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
            cout<<endl;
            s="∷";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
        }else if(i%12==0){
            s="□■■";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
            cout<<endl;
            s="∷";
            for(int i=1;i<=36;i++){
                cout<<" ";
            }
            cout<<s;
        }
        Sleep(50);
        clrscr();
    }
    for(int i=1;i<=10;i++){
        cout<<endl;
    }
    s="加载完毕!";
    couts(s,1);
    Sleep(100);
    clrscr();
    return ;
}
void Zhumian(){
    for(int i=1;i<=8;i++){
        cout<<endl;
    }
    s="|------------------------------|";
    couts(s,0);
    cout<<endl;
    s="|            请选择            |";
    couts(s,0);
    cout<<endl;
    s="|1.贪吃蛇  2.飞翔的小鸟  3.扫雷|";
    couts(s,0);
    cout<<endl;
    s="|          小游戏1.0           |";
    couts(s,0);
    cout<<endl;
    s="|------------------------------|";
    couts(s,0);
    cout<<endl;
    s="你的选择:";
    string an;
    getline(cin,an);
    while(an!="1"&&an!="2"&&an!="3"){
        MessageBox(NULL,"输入错误","提示",MB_OK);
        clrscr();
        for(int i=1;i<=8;i++){
            cout<<endl;
        }
        s="|------------------------------|";
        couts(s,0);
        cout<<endl;
        s="|            请选择            |";
        couts(s,0);
        cout<<endl;
        s="|1.贪吃蛇  2.飞翔的小鸟  3.扫雷|";
        couts(s,0);
        cout<<endl;
        s="|          小游戏1.0           |";
        couts(s,0);
        cout<<endl;
        s="|------------------------------|";
        couts(s,0);
        cout<<endl;
        s="你的选择:";
        getline(cin,an);
    }
    clrscr();
    if(an=="1"){
        tanchi();
    }else if(an=="2"){
        xiaoniao();
    }else if(an=="3"){
        saolei();
    }
    return ;
}
void Into(){
    MessageBox(NULL,"小游戏1.0已发布","通知",MB_OK);
    if(MessageBox(NULL,"点确定开始","提示",MB_OKCANCEL)!=1){
        MessageBox(NULL,"已退出","通知",MB_OK);
        tuichu=true;
        return ; 
    }
    for(int i=1;i<=9;i++){
        cout<<endl;
    }
    s="欢迎进入游戏!";
    couts(s,1);
    cout<<endl;
    s="本游戏由王子豪独家制作,禁止抄袭!";
    couts(s,1); 
    Sleep(100);
    cout<<endl;
    pause();
    Jiazai();
    Zhumian();
    return ;
}
int main(){
    Chuangkou();
    if(tuichu){
        return 0;
    }
    Into();
    if(tuichu){
        return 0;
    }
    return 0;
}

 


0
已采纳
孔小川
孔小川
初级光能
初级光能

还是比较(      )

0
王子豪
王子豪
资深守护
资深守护

我可真能抄我可真能抄我可真能抄我可真能抄我可真能抄我可真能抄我可真能抄我可真能抄我可真能抄我可真能抄我可真能抄我可真能抄

我要回答