我的世界C++。 二小时终于写完了=(^.^)=

#include<windows.h>
#include<stdio.h>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<conio.h>
#include<stdlib.h>
using namespace std;
enum ConsoleColor {
    BLACK = 0,
    BLUE = 1,
    GREEN = 2,
    CYAN = 3,
    RED = 4,
    MAGENTA = 5,
    BROWN = 6,
    LIGHT_GRAY = 7,
    DARK_GRAY = 8,
    LIGHT_BLUE = 9,
    LIGHT_GREEN = 10,
    LIGHT_CYAN = 11,
    LIGHT_RED = 12,
    LIGHT_MAGENTA = 13,
    YELLOW = 14,
    WHITE = 15
};
void COLOR_PRINT(const char* s, int color)
{
 HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
 SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | color);
 printf(s);
 SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | 7);
}
void rgb_init() {
HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD dwInMode, dwOutMode;
GetConsoleMode(hIn, &dwInMode);
GetConsoleMode(hOut, &dwOutMode);
dwInMode |=0x0200; 
dwOutMode |=0x0004;
SetConsoleMode(hIn, dwInMode);
SetConsoleMode(hOut,dwOutMode);
}
void rgb_set(int wr,int wg,int wb,int br,int bg,int bb){
printf("\033[38;2;%d;%d;%dm\033[48;2;%d;%d;%dm",wr,wg,wb,br,bg,bb);}
int main(){
    int hp=10;
    int a[61][100]={0};//主世界方块数组
    for(int i=0;i<=60;i++){
        for(int j=0;j<=99;j++){
            if(i<=10){
                if(i==10&&j==20){//玩家初始坐标,10,20 
                    a[i][j]=2;//玩家 
                }else if(i>=8&&j==5){
                    a[i][j]=9;//木块 
                }else if(i==6&&j==5||i==7&&j==4||i==7&&j==5||i==7&&j==6){
                    a[i][j]=10;//树叶 
                }else{
                    a[i][j]=0;//空气
                }
            }else if(i>11){
                if(i==15&&j==18||j==60&&i==14||j==6&&i==17||j==45&&i==16||i==15&&j==19||i==16&&j==18||i==16&&j==19||i==20&&j==34||i==21&&j==78||i==22&&j==78||i==14&&j==90||i==14&&j==66||i==15&&j==66||i==24&&j==67||i==25&&j==68||i==15&&j==2||i==15&&j==3){
                    a[i][j]=3;//煤矿 
                }else if(i==31&&j==19||i==35&&j==78||i==45&&j==67||i==42&&j==67||i==42&&j==68||i==43&&j==67||i==43&&j==68||i==34&&j==34||i==56&&j==33||i==56&&j==32||i==56&&j==31||i==36&&j==3||i==35&&j==4||i==30&&j==10||i==32&&j==15||i==30&&j==9||i==33&&j==17){                                                                                                                                           
                    a[i][j]=4;//铁矿 
                }else if(i==56&&j==17||i==54&&j==78||i==48&&j==56){
                    a[i][j]=5;//钻石 
                }else if(i==11&&j>=25&&j<=40){
                    a[i][j]=7;//水 
                }else if(i==12&&j>=25&&j<=40){
                    a[i][j]=7;//水
                }else if(i==13&&j>=27&&j<=40){
                    a[i][j]=7;//水
                }else if(i==13&&j>=30&&j<=38){
                    a[i][j]=7;//水
                }else if(i==37&&j>=35&&j<=45){
                    a[i][j]=8;//岩浆 
                }else{
                    a[i][j]=1;//石块 
                }
            }else if(i==11){
                if(j<25||j>40){
                    a[i][j]=6;//草 
                }
            }
        }
    } 
    int sj;
    int zybl=1;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<"                                                                                                  "<<"按任意键开始游戏";
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    
    
    char zy;
    if(_kbhit()){
            zybl=0;
            system("cls");
    }
    
    
    
        
    
    
    
    
    
    int u=0;
    int sum=0;//草 
    int sum1=0;//石 
    int sum2=0;//木 
    int sum3=0;//木板 
    int sum4=0;//铁 
    int sum5=0;//煤 
    int sum6=0;//钻 
    int sjbl=8;//时间变量
    int zb=10,zb2=20;//玩家初始坐标,10,20 
    int xht=1;//循环体变量
    bool ms=0; 
    int fk;
    while(xht=1){    
    char xz1;//玩家行动变量
    if(_kbhit()){
        xz1 = _getch();
        if(ms==0){
            if(xz1=='a'){//向左 
            if(a[zb][zb2-1]==0&&zb2-1>-1){
            swap(a[zb][zb2],a[zb][zb2-1]);
            zb2--;
            sjbl++;
            int fxxh=1;
            int jsq=0;
            while(fxxh=1){
                if(a[zb+1][zb2]==0){
                    swap(a[zb][zb2],a[zb+1][zb2]);
                    zb++;
                    jsq++;
                }else{
                     if(jsq>=5){
                        if(a[zb+1][zb2]!=7){
                            hp-=(jsq-5);
                        }
                    }
                    break;
                }
            }
            }    
        }else if(xz1=='d'){//向右 
            if(a[zb][zb2+1]==0&&zb2+1<=100){
            swap(a[zb][zb2],a[zb][zb2+1]);
            zb2++;
            sjbl++;
            int fxxh1=1;
            int jsq2=0;
            while(fxxh1=1){
                if(a[zb+1][zb2]==0){
                    swap(a[zb][zb2],a[zb+1][zb2]);
                    zb++;
                    jsq2++;
                }else{
                    if(jsq2>=5){
                        if(a[zb+1][zb2]!=7){
                            hp-=(jsq2-5);
                        }
                    }
                    break;
                }
            }
            }
        }else if(xz1=='q'){//向左上 
            if(a[zb-1][zb2-1]==0&&a[zb][zb2-1]!=0&&zb-1>-1&&zb2-1>-1){
                swap(a[zb][zb2],a[zb-1][zb2-1]);
                zb--;
                zb2--;
                sjbl++;
            }
        }else if(xz1=='e'){//向右上 
            if(a[zb-1][zb2+1]==0&&a[zb][zb2+1]!=0&&zb-1>-1&&zb2+1<=100){
                swap(a[zb][zb2],a[zb-1][zb2+1]);
                 zb--;
                zb2++;
                sjbl++;
            } 
         }else if(xz1=='4'){//向左挖 
            if(a[zb][zb2-1]!=0){
                if(a[zb][zb2-1]==6){
                    sum++;
                }else if(a[zb][zb2-1]==1){
                    sum1++;
                }else if(a[zb][zb2-1]==9){
                    sum2++;
                }else if(a[zb][zb2-1]==4){
                    sum4++;
                }else if(a[zb][zb2-1]==3){
                    sum5++;
                }else if(a[zb][zb2-1]==5){
                    sum6++;
                }
                a[zb][zb2-1]=0;
                sjbl++;
            }
        }else if(xz1=='6'){//向右挖 
            if(a[zb][zb2+1]!=0){
                if(a[zb][zb2+1]==6){
                    sum++;
                }else if(a[zb][zb2+1]==1){
                    sum1++;
                }else if(a[zb][zb2+1]==9){
                    sum2++;
                }else if(a[zb][zb2+1]==4){
                    sum4++;
                }else if(a[zb][zb2+1]==3){
                    sum5++;
                }else if(a[zb][zb2+1]==5){
                    sum6++;
                }
                a[zb][zb2+1]=0;
                sjbl++;
            }
        }else if(xz1=='8'){
            if(a[zb-1][zb2]!=0){
                if(a[zb-1][zb2]==6){
                    sum++;
                }else if(a[zb-1][zb2]==1){
                    sum1++;
                }else if(a[zb-1][zb2]==9){
                    sum2++;
                }else if(a[zb-1][zb2]==4){
                    sum4++;
                }else if(a[zb-1][zb2]==3){
                    sum5++;
                }else if(a[zb-1][zb2]==5){
                    sum6++;
                }
                a[zb-1][zb2]=0;
                sjbl++;
            }
        }else if(xz1=='2'){
            if(a[zb+1][zb2]!=0){
                if(a[zb+1][zb2]==6){
                    sum++;
                }else if(a[zb+1][zb2]==1){
                    sum1++;
                }else if(a[zb+1][zb2]==9){
                    sum2++;
                }else if(a[zb+1][zb2]==4){
                    sum4++;
                }else if(a[zb+1][zb2]==3){
                    sum5++;
                }else if(a[zb+1][zb2]==5){
                    sum6++;
                }
                 a[zb+1][zb2]=0;
                sjbl++;
                int fxxh2=1;
                int jsq3=0;
                while(fxxh2=1){
                    if(a[zb+1][zb2]==0){
                        swap(a[zb][zb2],a[zb+1][zb2]);
                        zb++;
                        jsq3++;
                    }else{
                        if(jsq3>=5){
                            if(a[zb+1][zb2]!=7){
                                hp-=(jsq3-5);
                            }
                        }
                        break;
                    }  
                }
            }
        }else if(xz1=='7'){
            if(a[zb-1][zb2-1]!=0){
                if(a[zb-1][zb2-1]==6){
                    sum++;
                }else if(a[zb-1][zb2-1]==1){
                    sum1++;
                }else if(a[zb-1][zb2-1]==9){
                    sum2++;
                }else if(a[zb-1][zb2-1]==4){
                    sum4++;
                }else if(a[zb-1][zb2-1]==3){
                    sum5++;
                }else if(a[zb-1][zb2-1]==5){
                    sum6++;
                }
                 a[zb-1][zb2-1]=0;
                sjbl++;
            }
        }else if(xz1=='9'){
            
        }else if(xz1=='1'){
            
        }else if(xz1=='3'){
            
        }else if(xz1=='o'){
            system("cls");
            cout<<endl;
            cout<<endl;
            cout<<"                "<<"操作说明";
            cout<<endl;
            cout<<"           "<<"A向左";
            cout<<endl;
            cout<<"           "<<"D向右";
            cout<<endl;
            cout<<"           "<<"Q向左上";
            cout<<endl;
            cout<<"           "<<"E向右上";
            cout<<endl;
            cout<<"           "<<"4向左挖(挖掘模式)";
            cout<<endl;
            cout<<"           "<<"6向右挖(挖掘模式)";
            cout<<endl;
            cout<<"           "<<"8向上挖(挖掘模式)";
            cout<<endl;
            cout<<"           "<<"2向下挖(挖掘模式)";
            cout<<endl;
            cout<<"           "<<"4向左放(建造模式)";
            cout<<endl;
            cout<<"           "<<"6向右放(建造模式)";
            cout<<endl;
            cout<<"           "<<"8向上放(建造模式)";
            cout<<endl;
            cout<<"           "<<"2向下放(建造模式)";
            cout<<endl;
            cout<<"           "<<"u切换方块";
            cout<<endl;
            cout<<"                                "<<"17秒后返回游戏";
            Sleep(20000);
        }else if(xz1=='i'){
            if(ms==0){
                ms=1;
            }else{
                ms=0;
            }
        }
        }else if(ms==1){
            if(xz1=='a'){//向左 
            if(a[zb][zb2-1]==0&&zb2-1>-1){
            swap(a[zb][zb2],a[zb][zb2-1]);
            zb2--;
            sjbl++;
            int fxxh=1;
            int jsq4=0;
            while(fxxh=1){
                if(a[zb+1][zb2]==0){
                    swap(a[zb][zb2],a[zb+1][zb2]);
                    zb++;
                     jsq4++;
                }else{
                     if(jsq4>=5){
                        if(a[zb+1][zb2]!=7){
                            hp-=(jsq4-5);
                        }
                    }
                    break;
                }
            }
            }    
        }else if(xz1=='d'){//向右 
            if(a[zb][zb2+1]==0&&zb2+1<=100){
            swap(a[zb][zb2],a[zb][zb2+1]);
            zb2++;
            sjbl++;
            int fxxh1=1;
            int jsq5=0;
            while(fxxh1=1){
                if(a[zb+1][zb2]==0){
                    swap(a[zb][zb2],a[zb+1][zb2]);
                    zb++;
                    jsq5++;    
                }else{
                    if(jsq5>=5){
                        if(a[zb+1][zb2]!=7){
                            hp-=(jsq5-5);
                        }
                    }
                    break;
                }
            }
            }
        }else if(xz1=='q'){//向左上 
            if(a[zb-1][zb2-1]==0&&a[zb][zb2-1]!=0&&zb-1>-1&&zb2-1>-1){
                swap(a[zb][zb2],a[zb-1][zb2-1]);
                zb--;
                zb2--;
                sjbl++;
            }
        }else if(xz1=='e'){//向右上 
            if(a[zb-1][zb2+1]==0&&a[zb][zb2+1]!=0&&zb-1>-1&&zb2+1<=100){
                swap(a[zb][zb2],a[zb-1][zb2+1]);
                 zb--;
                zb2++;
                sjbl++;
            } 
         }else if(xz1=='4'){//左 
             if(a[zb][zb2-1]==0){
                 if(u==1){
                     if(sum!=0){
                         sum--;
                          a[zb][zb2-1]=6;
                    }
                }else if(u==2){
                    if(sum1!=0){
                        sum1--;
                        a[zb][zb2-1]=1;
                    }
                    
                }else if(u==3){
                    if(sum2!=0){
                        sum2--;
                        a[zb][zb2-1]=9;
                    }
                    
                }else if(u==4){
                    if(sum3!=0){
                        sum3--;
                    }
                    
                }else if(u==5){
                    if(sum4!=0){
                        sum4--;
                        a[zb][zb2-1]=4;
                    }
                
                }else if(u==6){
                    if(sum5!=0){
                        sum5--;
                        a[zb][zb2-1]=3;
                    }
                    
                }else if(u==7){
                    if(sum6!=0){
                        sum6--;
                        a[zb][zb2-1]=5;
                    }
                    
                }
            }
        }else if(xz1=='6'){//右 
            if(a[zb][zb2+1]==0){
                 if(u==1){
                     if(sum!=0){
                         sum--;
                          a[zb][zb2+1]=6;
                    }
                }else if(u==2){
                    if(sum1!=0){
                        sum1--;
                        a[zb][zb2+1]=1;
                    }
                    
                }else if(u==3){
                    if(sum2!=0){
                        sum2--;
                        a[zb][zb2+1]=9;
                    }
                    
                }else if(u==4){
                    if(sum3!=0){
                        sum3--;
                    }
                    
                }else if(u==5){
                    if(sum4!=0){
                        sum4--;
                        a[zb][zb2+1]=4;
                    }
                
                }else if(u==6){
                    if(sum5!=0){
                        sum5--;
                        a[zb][zb2+1]=3;
                    }
                    
                }else if(u==7){
                    if(sum6!=0){
                        sum6--;
                        a[zb][zb2+1]=5;
                    }
                    
                }
            }
        }else if(xz1=='2'){//下 
            if(a[zb-1][zb2]==0){
                 if(u==1){
                     if(sum!=0){
                         sum--;
                         swap(a[zb][zb2],a[zb-1][zb2]);
                         zb--;
                          a[zb+1][zb2]=6;
                    }
                }else if(u==2){
                    if(sum1!=0){
                        sum1--;
                        swap(a[zb][zb2],a[zb-1][zb2]);
                        zb--;
                        a[zb+1][zb2]=1;
                    }
                    
                }else if(u==3){
                    if(sum2!=0){
                        sum2--;
                        swap(a[zb][zb2],a[zb-1][zb2]);
                        zb--;
                        a[zb+1][zb2]=9;
                    }
                    
                }else if(u==4){
                    if(sum3!=0){
                        sum3--;
                    }
                    
                }else if(u==5){
                    if(sum4!=0){
                        sum4--;
                        swap(a[zb][zb2],a[zb-1][zb2]);
                        zb--;
                        a[zb+1][zb2]=4;
                    }
                
                }else if(u==6){
                    if(sum5!=0){
                        sum5--;
                        swap(a[zb][zb2],a[zb-1][zb2]);
                        zb--;
                        a[zb+1][zb2]=3;
                    }
                    
                }else if(u==7){
                    if(sum6!=0){
                        sum6--;
                        swap(a[zb][zb2],a[zb-1][zb2]);
                        zb--;
                        a[zb+1][zb2]=5;
                    }
                    
                }
            }
        }else if(xz1=='8'){//上 
            if(a[zb-1][zb2]==0){
                 if(u==1){
                     if(sum!=0){
                         sum--;
                          a[zb-1][zb2]=6;
                    }
                }else if(u==2){
                    if(sum1!=0){
                        sum1--;
                        a[zb-1][zb2]=1;
                    }
                    
                }else if(u==3){
                    if(sum2!=0){
                        sum2--;
                        a[zb-1][zb2]=9;
                    }
                    
                }else if(u==4){
                    if(sum3!=0){
                        sum3--;
                    }
                    
                }else if(u==5){
                    if(sum4!=0){
                        sum4--;
                        a[zb-1][zb2]=4;
                    }
                
                }else if(u==6){
                    if(sum5!=0){
                        sum5--;
                        a[zb-1][zb2]=3;
                    }
                    
                }else if(u==7){
                    if(sum6!=0){
                        sum6--;
                        a[zb-1][zb2]=5;
                    }
                    
                }
            }
        }else if(xz1=='7'){//左上 
            if(a[zb-1][zb2-1]==0){
                 if(u==1){
                     if(sum!=0){
                         sum--;
                          a[zb-1][zb2-1]=6;
                    }
                }else if(u==2){
                    if(sum1!=0){
                        sum1--;
                        a[zb-1][zb2-1]=1;
                    }
                    
                }else if(u==3){
                    if(sum2!=0){
                        sum2--;
                        a[zb-1][zb2-1]=9;
                    }
                    
                }else if(u==4){
                    if(sum3!=0){
                        sum3--;
                    }
                    
                }else if(u==5){
                    if(sum4!=0){
                        sum4--;
                        a[zb-1][zb2-1]=4;
                    }
                
                }else if(u==6){
                    if(sum5!=0){
                        sum5--;
                        a[zb-1][zb2-1]=3;
                    }
                    
                }else if(u==7){
                    if(sum6!=0){
                        sum6--;
                        a[zb-1][zb2-1]=5;
                    }
                    
                }
            }
        }else if(xz1=='9'){//右上 
            if(a[zb-1][zb2+1]==0){
                 if(u==1){
                     if(sum!=0){
                         sum--;
                          a[zb-1][zb2+1]=6;
                    }
                }else if(u==2){
                    if(sum1!=0){
                        sum1--;
                        a[zb-1][zb2+1]=1;
                    }
                    
                }else if(u==3){
                    if(sum2!=0){
                        sum2--;
                        a[zb-1][zb2+1]=9;
                    }
                    
                }else if(u==4){
                    if(sum3!=0){
                        sum3--;
                    }
                    
                }else if(u==5){
                    if(sum4!=0){
                        sum4--;
                        a[zb-1][zb2+1]=4;
                    }
                
                }else if(u==6){
                    if(sum5!=0){
                        sum5--;
                        a[zb-1][zb2+1]=3;
                    }
                    
                }else if(u==7){
                    if(sum6!=0){
                        sum6--;
                        a[zb-1][zb2+1]=5;
                    }
                    
                }
            }
        }else if(xz1=='1'){//左下 
            if(a[zb+1][zb2-1]==0){
                 if(u==1){
                     if(sum!=0){
                         sum--;
                          a[zb+1][zb2-1]=6;
                    }
                }else if(u==2){
                    if(sum1!=0){
                        sum1--;
                        a[zb+1][zb2-1]=1;
                    }
                    
                }else if(u==3){
                    if(sum2!=0){
                        sum2--;
                        a[zb+1][zb2-1]=9;
                    }
                    
                }else if(u==4){
                    if(sum3!=0){
                        sum3--;
                    }
                    
                }else if(u==5){
                    if(sum4!=0){
                        sum4--;
                        a[zb+1][zb2-1]=4;
                    }
                
                }else if(u==6){
                    if(sum5!=0){
                        sum5--;
                        a[zb+1][zb2-1]=3;
                    }
                    
                }else if(u==7){
                    if(sum6!=0){
                        sum6--;
                        a[zb+1][zb2-1]=5;
                    }
                    
                }
            }
        }else if(xz1=='3'){//右下 
            if(a[zb+1][zb2+1]==0){
                 if(u==1){
                     if(sum!=0){
                         sum--;
                          a[zb+1][zb2+1]=6;
                    }
                }else if(u==2){
                    if(sum1!=0){
                        sum1--;
                        a[zb+1][zb2+1]=1;
                    }
                    
                }else if(u==3){
                    if(sum2!=0){
                        sum2--;
                        a[zb+1][zb2+1]=9;
                    }
                    
                }else if(u==4){
                    if(sum3!=0){
                        sum3--;
                    }
                    
                }else if(u==5){
                    if(sum4!=0){
                        sum4--;
                        a[zb+1][zb2+1]=4;
                    }
                
                }else if(u==6){
                    if(sum5!=0){
                        sum5--;
                        a[zb+1][zb2+1]=3;
                    }
                    
                }else if(u==7){
                    if(sum6!=0){
                        sum6--;
                        a[zb+1][zb2+1]=5;
                    }
                    
                }
            }
        }else if(xz1=='i'){
            if(ms==0){
                ms=1;
            }else{
                ms=0;
            }
        }else if(xz1=='u'){
            if(u+1!=8){
                u++;
            }else{
                u=1;
            }
        }
        }
        
    if(sj==1){
        if(sjbl<=20&&sjbl>10){
        system("color e8");
    }else if(sjbl>20&&sjbl<=40){
        system("color 98");
    }else if(sjbl>40&&sjbl<=50){
        system("color 68");
    }else if(sjbl<=10||sjbl>50){
        system("color 08");
        if(sjbl==60){
            sjbl=0;
        }
    }
    }
    Sleep(0.000000000000001);
    system("cls");
    for(int i=0;i<=60;i++){
        for(int j=0;j<=99;j++){
            if(a[i][j]==0){
                printf("  ");
            }else if(a[i][j]==1){
                COLOR_PRINT("█",8);
            }else if(a[i][j]==2){
                printf("★");
            }else if(a[i][j]==3){
                printf("▓");
            }else if(a[i][j]==4){
                printf("□");
            }else if(a[i][j]==5){
                COLOR_PRINT("△",1);
            }else if(a[i][j]==6){
                COLOR_PRINT("█",2);
            }else if(a[i][j]==7){
                COLOR_PRINT("▓",9);
            }else if(a[i][j]==8){
                COLOR_PRINT("▓",12);
            }else if(a[i][j]==9){
                COLOR_PRINT("█",6);
            }else if(a[i][j]==10){
                COLOR_PRINT("▓",10);
            }
        }
        
        if(i==11){
            cout<<"    "<<"草块"<<sum;
            if(u==1){
                cout<<"●"<<"当前使用方块";
            }
        }else if(i==12){
            cout<<"    "<<"石块"<<sum1;
            if(u==2){
                cout<<"●"<<"当前使用方块";
            }
        }else if(i==13){
            cout<<"    "<<"木块"<<sum2;
            if(u==3){
                cout<<"●"<<"当前使用方块";
            }
        }else if(i==14){
            cout<<"    "<<"木板"<<sum3;
            if(u==4){
                cout<<"●"<<"当前使用方块";
            }
        }else if(i==15){
            cout<<"    "<<"铁矿"<<sum4;
            if(u==5){
                cout<<"●"<<"当前使用方块";
            }
        }else if(i==16){
            cout<<"    "<<"煤矿"<<sum5;
            if(u==6){
                cout<<"●"<<"当前使用方块";
            }
        }else if(i==17){
            cout<<"    "<<"钻矿"<<sum6;
            if(u==7){
                cout<<"●"<<"当前使用方块";
            }
        }else if(i==18){
            if(ms==0){
                cout<<"   "<<"挖掘模式i";
            }else{
                cout<<"   "<<"建造模式i";
            }
        }else if(i==19){
            cout<<"    "<<"";
        }else if(i==20){
            cout<<"    "<<"";
        }else if(i==21){
            cout<<"    "<<"";
        }else if(i==22){
            cout<<"    "<<"";
        }else if(i==23){
            cout<<"    "<<"";
        }else if(i==24){
            cout<<"    "<<"";
        }else if(i==25){
            cout<<"    "<<"";
        }else if(i==3){
            cout<<"    "<<"O查看操作";
        }else if(i==1){
            if(hp<=0){
                cout<<"血量:";
                for(int sw=1;sw<=10;sw++){
                    COLOR_PRINT("█",15);
                }
                Sleep(6000);
                system("cls");
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<"                                                                                                                "<<"你失败了";
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                cout<<endl;
                Sleep(8000);
                return 0;
            }
            cout<<"血量:";
            for(int hpx=1;hpx<=hp;hpx++){
                COLOR_PRINT("█",4);
            }
            for(int hpx2=1;hpx2<=10-hp;hpx2++){
                COLOR_PRINT("█",15);
            }
        }
        cout<<endl;
    }
    cout<<endl;
    
    }
 
    
}
    return 0;

 

 

### 回答1: 好的,我可以用中文来回答你关于世界名画陈列的问题,并用 C 语言来给出解决方案。 首先,我们需要确定所有可供选择的画作的信息,包括每幅画的价值和体积。我们可以使用结构体来存储这些信息,如下所示: ``` struct Painting { int value; // 画的价值 int volume; // 画的体积 }; ``` 然后,我们可以使用贪心算法来解决这个问题。贪心算法的基本思路是,每次都选择价值/体积比最大的画作。 在 C 语言中,我们可以先对画作进行排序,然后依次选择价值/体积比最大的画作。为了方便,我们可以写一个比较函数,用于在排序时比较两幅画的价值/体积比。 ``` int compare(const void *a, const void *b) { const Painting *pa = (const Painting*)a; const Painting *pb = (const Painting*)b; return (pb->value * pa->volume) - (pa->value * pb->volume); } ``` 最后,我们可以使用类似如下的代码来解决这个问题: ``` #include <stdio.h> #include <stdlib.h> #define MAX_NUM_PAINTINGS 100 struct Painting { int value; // 画的价值 int volume; // 画的体积 }; int compare(const void *a, const void *b) { const Painting *pa = (const Painting*)a; const Painting *pb = (const Painting*)b; return (pb->value * pa->volume) - (pa-> ### 回答2: 题目要求用贪心算法解决世界名画陈列问题,我理解为如何通过贪心策略选择一些世界名画进行陈列,使得总陈列面积最大化。 首先,我们需要准备一个数组c[],表示每幅名画所占的面积。另外,我们还需要一个变量total_area,表示当前已选择的名画总面积。 然后,我们按照贪心策略进行操作: 1. 初始化total_area为0。 2. 对c[]进行非递增排序。 3. 从头开始遍历c[],对于每幅名画,判断如果将其加入陈列,是否会使得总面积增加。即,如果total_area + c[i] <= C(陈列空间限制),则将其加入陈列,同时更新total_area为total_area + c[i]。 4. 继续遍历下一幅名画,直到遍历完所有名画或无法再添加新的名画为止。 最终的total_area即为能够选择的世界名画在给定陈列空间C下的最大陈列面积。 下面是用C语言实现的代码: ```c #include <stdio.h> #include <stdlib.h> // 比较两个整数的大小 int compare(const void *a, const void *b) { return (*(int*)b - *(int*)a); } int main() { int n; // 名画数量 int C; // 陈列空间限制 int *c; // 各名画占面积 int total_area = 0; // 当前已选择的名画总面积 printf("请输入名画数量n:"); scanf("%d", &n); printf("请输入陈列空间限制C:"); scanf("%d", &C); c = (int *)malloc(n * sizeof(int)); printf("请输入每幅名画的面积:"); for (int i = 0; i < n; i++) { scanf("%d", &c[i]); } // 按照面积非递增排序 qsort(c, n, sizeof(int), compare); // 贪心策略选择名画 for (int i = 0; i < n; i++) { if (total_area + c[i] <= C) { total_area += c[i]; } } printf("总陈列面积:%d\n", total_area); free(c); return 0; } ``` 通过以上代码,我们可根据输入的名画占面积和陈列空间限制,得到最大陈列面积的结果。注意,在实际应用时,可能还需要对输入进行错误处理和合理性判断,以便得到更可靠的陈列结果。 ### 回答3: 题目要求使用贪心算法解决世界名画陈列问题,下面给出基本实现方法。 首先,我们将世界名画按照重要性进行排序,重要性值越大则越重要。假设存在一个维数组`paintings[N][2]`,其中`paintings[i][0]`表示第i幅画的重要性,`paintings[i][1]`表示第i幅画的占用空间。 定义一个`totalSpace`变量表示展厅的总空间大小,初始化为C(代码中使用一个常量C表示);定义一个`displayedPaintings`数组,初始化为空。 然后,按照重要性从大到小的顺序遍历所有画作。对于每一幅画作,先判断其占用空间是否小于等于展厅剩余空间`totalSpace`,如果是,则将该画作加入`displayedPaintings`数组,并更新展厅剩余空间`totalSpace`。 最后,如果展厅剩余空间`totalSpace`小于某一幅画的占用空间,说明无法继续陈列更多的画作,算法结束。 下面是使用C语言编写的贪心算法实现: ```c #include <stdio.h> #define C 300 // 展厅总空间 void displayPaintings(int paintings[][2], int n) { int totalSpace = C; int displayedPaintings[n]; int count = 0; // 按重要性从大到小排序 for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - 1 - i; j++) { if (paintings[j][0] < paintings[j + 1][0]) { int temp1 = paintings[j][0]; int temp2 = paintings[j][1]; paintings[j][0] = paintings[j + 1][0]; paintings[j][1] = paintings[j + 1][1]; paintings[j + 1][0] = temp1; paintings[j + 1][1] = temp2; } } } // 选择陈列画作 for (int i = 0; i < n; i++) { if (paintings[i][1] <= totalSpace) { displayedPaintings[count++] = i; totalSpace -= paintings[i][1]; } else { break; } } // 输出陈列的画作索引 printf("陈列的画作:"); for (int i = 0; i < count; i++) { printf("%d ", displayedPaintings[i]); } printf("\n"); } int main() { int paintings[][2] = {{5, 50}, {10, 150}, {7, 80}, {12, 200}, {9, 100}}; int n = sizeof(paintings) / sizeof(paintings[0]); displayPaintings(paintings, n); return 0; } ``` 以上代码会输出陈列的画作的索引(从0开始),例如输出`0 1 2 4`表示陈列的画作为第0、1、2、4幅画。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值