修仙小游戏(未完成)

· · 休闲·娱乐

#include<bits/stdc++.h>
#include<windows.h>
#include<stdio.h>
#include<conio.h> 
#define key_down(key_name) GetAsyncKeyState(key_name)
using namespace std;
int ling_shi=10,jin_bi=100;
double xie_liang = 10,gong_ji = 2,gong_su = 1,fang_yu = 0;
double ji_chu_xie_liang = 10,ji_chu_gong_ji = 2,ji_chu_gong_su = 1,ji_chu_fang_yu = 0,e_wai_sheng_ming=0; 
int fang_xiang = 1;
int xuan_zhong_x;
int xuan_zhong_y; 
//n = getch();
//system("cls");
//Sleep(100); 

char ditu[10][10] = {{'*','*','*','*','*','*','*','*','*','*'},
                   {'*','r',' ','d',' ',' ',' ',' ',' ','*'},
                   {'*','A',' ',' ',' ',' ',' ',' ',' ','*'},
                   {'*',' ',' ',' ',' ',' ',' ',' ',' ','*'},
                   {'*',' ',' ',' ',' ',' ',' ',' ',' ','*'},
                   {'*',' ',' ',' ',' ',' ',' ',' ',' ','*'},
                   {'*',' ',' ',' ',' ',' ',' ',' ',' ','*'},
                   {'*',' ',' ',' ',' ',' ',' ',' ',' ','*'},
                   {'*',' ',' ',' ',' ',' ',' ',' ',' ','*'},
                   {'*','*','*','*','*','*','*','*','*','*'}};
char mao_xian_dt[10][10];
int x=1,y=1;
void SetColorAndBackground(int ForgC, int BackC) {
    WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
}
struct guai_wu_jgt{
    int xie_ling,gong_ji;
    int x,y;
}guai_wu[10];
string be_bao[3][10]={{"空","空","空","空","空","空","空","空","空","空"},
                      {"空","空","空","空","空","空","空","空","空","空"},
                      {"空","空","空","空","空","空","空","空","空","空"}};
int be_bao_bian_hao[3][10] = {{0,0,0,0,0,0,0,0,0,0},
                              {0,0,0,0,0,0,0,0,0,0},
                              {0,0,0,0,0,0,0,0,0,0}};

int be_bao_x=0,be_bao_y=0;
string da_jing_jie[12] = {"凡人","练气","筑基","结丹","元婴","化神","练虚","合体","大乘","真仙","金仙","道祖"}; 
string xiao_jing_jie[6] = {"凡体","初阶","中阶","高价","圆满","无双"};
int ti_sheng_ling_qi[12] = {50,100,200,400,600,1000,3000,6000,10000,40000,80000,100000};
int da_jing_jie_shu=0,xiao_jing_jie_shu=0;
int ling_qi_zhi = 0;
string gou_mai_wu_pin[] = {" ","(1)钢剑 攻击+5 攻速+2 金币100\n",
                           "(2)金苹果 血量回复5 +4点额外生命值 金币20\n",
                           "(3)生命料理 血量回满 +20点额外生命 金币100\n",
                           "(4)海拉鲁大剑 攻击+20 攻速-0.4 金币300\n",
                           "(5)皮制盔甲 防御+3 金币50\n",
                           "(6)一阶灵晶 灵气+10 金币20\n"};
int gou_mai_jia_ge[] = {0,100,20,100,300,50,20};
string gou_mai_ming_zi[] = {" ","钢剑","金苹果","生命料理","海拉鲁大剑","皮制盔甲","一阶灵晶"};
string wu_pin_shu_zhi[] = {"无",
                            "钢剑:伤害+5 攻速+2\nQ键装备",
                           "金苹果:血量回复5 +4点额外生命值\nR键食用",
                           "生命料理:血量回满 +20点额外生命\nR键食用",
                           "海拉鲁大剑:伤害+20 攻速-0.4\nQ键装备",
                           "皮质盔甲:防御+3\nQ键装备",
                           "一阶灵晶:灵气+10\nR键食用"};
string wu_qi = "无";
string fang_ju = "无";
void zhuang_tai(){
    cout<<"血量:"<<xie_liang<<" 攻击:"<<gong_ji<<" "<<"攻速"<<gong_su<<"\n";
    cout<<"方向:";
    if(fang_xiang==1) cout<<"左";
    if(fang_xiang==2) cout<<"上";
    if(fang_xiang==3) cout<<"右";
    if(fang_xiang==4) cout<<"下";
    cout<<"\n"; 
    cout<<"灵石:"<<ling_shi<<" 金币"<<jin_bi<<"\n";
    cout<<"境界:"<<da_jing_jie[da_jing_jie_shu]<<" "<<xiao_jing_jie[xiao_jing_jie_shu]<<"\n";
    cout<<"灵气:  "<<ling_qi_zhi<<" / "<<ti_sheng_ling_qi[da_jing_jie_shu] + (xiao_jing_jie_shu-1)*20<<"\n";
    cout<<"武器:"<<wu_qi<<"   防具"<<fang_ju<<"\n"; 
    return;
}
void shang_ren(){
    cout<<"商人:\n";
    cout<<"Q键购买\n";
    cout<<"R键卖货\n";
    cout<<"E键退出\n"; 
    return;
}
void shang_ren_gou_mai(){
    while(1){
        int xx = 0,yy = 0;
        for(int i=1;i<=6;i++){
            cout<<gou_mai_wu_pin[i];
        }
        cout<<"金币:"<<jin_bi<<"\n";
        char gou_mai;
        gou_mai = getch();
        if(gou_mai=='e') return;
        int gou_mai_de = int(gou_mai-'0');
        if(jin_bi<gou_mai_jia_ge[gou_mai_de]){
            cout<<"钱不够";
            Sleep(500);
            system("cls");
            continue;
        }
        else{
            bool f = true;
            jin_bi -= gou_mai_jia_ge[gou_mai_de];
            while(be_bao[yy][xx]!="空"){
                xx++;
                if(xx>=10){
                    xx=0; yy++;
                }
                if(yy>=3){
                    cout<<"空间不够\n"; 
                    Sleep(500);
                    f = false;
                    break;
                } 
            }
            if(!f){
                system("cls");
                jin_bi += gou_mai_jia_ge[gou_mai_de];
                return;
            }
            be_bao[yy][xx] = gou_mai_ming_zi[gou_mai_de];
            be_bao_bian_hao[yy][xx] = gou_mai_de;
            system("cls");
        }
    }
    return;
}
void tu_po(){
    ling_qi_zhi = 0;
    xiao_jing_jie_shu++;
    ji_chu_xie_liang += 2;
    ji_chu_gong_ji += 2;
    if(xiao_jing_jie_shu>4 || da_jing_jie_shu==0){
        da_jing_jie_shu++;
        xiao_jing_jie_shu = 1;
        ji_chu_xie_liang += 10;
        ji_chu_gong_ji += 10;
        gong_ji = ji_chu_gong_ji;
        xie_liang = ji_chu_xie_liang;
    }
    return;
}
void da_kai_be_bao(){

    be_bao_x=0; be_bao_y=0;
    while(1){
        zhuang_tai();
        cout<<"\n";
        for(int i=0;i<=2;i++){
            for(int j=0;j<=9;j++){
                if(be_bao_x==i && be_bao_y==j){
                    SetColorAndBackground(4,0);
                    cout<<be_bao[be_bao_x][be_bao_y]<<" ";
                    SetColorAndBackground(15,0);
                } 
                else cout<<be_bao[i][j]<<" ";
            }
            cout<<endl;
        }
        cout<<"\n\n";
        cout<<wu_pin_shu_zhi[be_bao_bian_hao[be_bao_x][be_bao_y]];
        char be_bao_yi_dong;
        be_bao_yi_dong = getch();
        if(be_bao_yi_dong=='e') return;
        if(be_bao_yi_dong=='w'){
            if(be_bao_x-1>=0){
                be_bao_x--;
            }
        }
        else if(be_bao_yi_dong=='s'){
            if(be_bao_x+1<3){
                be_bao_x++;
            }
        }
        else if(be_bao_yi_dong=='a'){
            if(be_bao_y-1>=0){
                be_bao_y--;
            }
        }
        else if(be_bao_yi_dong=='d'){
            if(be_bao_y+1<10){
                be_bao_y++;
            }
        }
        if(be_bao_yi_dong=='q'){
            if(be_bao_bian_hao[be_bao_x][be_bao_y]==1){
                if(wu_qi=="无"){
                    wu_qi = be_bao[be_bao_x][be_bao_y];
                    be_bao[be_bao_x][be_bao_y] = "空";

                } 
                else{
                    swap(be_bao[be_bao_x][be_bao_y],wu_qi);
                }
                be_bao_bian_hao[be_bao_x][be_bao_y] = 0;
                gong_su = ji_chu_gong_su;
                gong_ji = ji_chu_gong_ji;
                gong_su += 2; gong_ji += 5;
            }
            if(be_bao_bian_hao[be_bao_x][be_bao_y]==4){
                if(wu_qi=="无"){
                    wu_qi = be_bao[be_bao_x][be_bao_y];
                    be_bao[be_bao_x][be_bao_y] = "空";

                } 
                else{
                    swap(be_bao[be_bao_x][be_bao_y],wu_qi);
                }
                be_bao_bian_hao[be_bao_x][be_bao_y] = 0;
                gong_su = ji_chu_gong_su;
                gong_ji = ji_chu_gong_ji;
                gong_su -= 0.4; gong_ji += 20;
            }
            if(be_bao_bian_hao[be_bao_x][be_bao_y]==5){
                if(wu_qi=="无"){
                    fang_ju = be_bao[be_bao_x][be_bao_y];
                    be_bao[be_bao_x][be_bao_y] = "空";
                } 
                else{
                    swap(be_bao[be_bao_x][be_bao_y],fang_ju);
                }
                be_bao_bian_hao[be_bao_x][be_bao_y] = 0;
                fang_yu = ji_chu_fang_yu;
                fang_yu += 3;
            }
        }
        if(be_bao_yi_dong=='r'){
            if(be_bao_bian_hao[be_bao_x][be_bao_y]==2){
                be_bao[be_bao_x][be_bao_y] = "空";
                be_bao_bian_hao[be_bao_x][be_bao_y] = 0;
                xie_liang+=5;
                if(xie_liang>ji_chu_xie_liang) xie_liang = ji_chu_xie_liang;
                e_wai_sheng_ming += 4;
            }
            if(be_bao_bian_hao[be_bao_x][be_bao_y]==3){
                be_bao[be_bao_x][be_bao_y] = "空";
                be_bao_bian_hao[be_bao_x][be_bao_y] = 0;
                xie_liang = ji_chu_xie_liang;
                e_wai_sheng_ming += 20;
            }
            if(be_bao_bian_hao[be_bao_x][be_bao_y]==6){
                be_bao[be_bao_x][be_bao_y] = "空";
                be_bao_bian_hao[be_bao_x][be_bao_y] = 0;
                ling_qi_zhi += 10;
            }   
        }
        if(ling_qi_zhi>=ti_sheng_ling_qi[da_jing_jie_shu]) tu_po();
        system("cls");
    }
    return;
} 
void mao_xian(){
    system("cls");
    int mx=1,my=1;
    int mxuan_zhong_x=2,mxuan_zhong_y=1,xx;
    fang_xiang = 4;
    int guai_wu_shu=0;
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            if(i==1 && j==1) continue;
            if(i==0 || j==0 || i==9 || j==9){
                mao_xian_dt[i][j] = '*';
                continue;
            } 
            int sheng_cheng = rand()%3;
            if(sheng_cheng==0){
                mao_xian_dt[i][j] = ' ';
            }
            else if(sheng_cheng==1 && xx<4){
                mao_xian_dt[i][j] = '&';
                xx++;
            }
            else if(guai_wu_shu<4){
                mao_xian_dt[i][j] = 'B';
                guai_wu_shu++;
                guai_wu[guai_wu_shu].gong_ji = rand()%6+1;
                guai_wu[guai_wu_shu].xie_ling = rand()%20+3;
                guai_wu[guai_wu_shu].x = i;
                guai_wu[guai_wu_shu].y = j;
            }
            else{
                mao_xian_dt[i][j] = ' ';
            }
        }
    }
    mao_xian_dt[1][1]='r';
    while(1){
        zhuang_tai();
        cout<<"\n\n";
        if(fang_xiang==1) mxuan_zhong_x=mx,mxuan_zhong_y=my-1;
        if(fang_xiang==2) mxuan_zhong_y=my,mxuan_zhong_x=mx-1;
        if(fang_xiang==3) mxuan_zhong_x=mx,mxuan_zhong_y=my+1;
        if(fang_xiang==4) mxuan_zhong_y=my,mxuan_zhong_x=mx+1;
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                if(mxuan_zhong_x==i && mxuan_zhong_y==j) SetColorAndBackground(15,4);
                cout<<mao_xian_dt[i][j]<<" ";
                SetColorAndBackground(15,0);
            }
            cout<<"\n";
        }
        char yi_dong;
        if(_kbhit() != 0){
            yi_dong = getch();
            int nx = mx,ny = my;
            if(yi_dong=='i') return;
            if(yi_dong==72) fang_xiang=2;
            else if(yi_dong==75) fang_xiang=1;
            else if(yi_dong==77) fang_xiang=3;
            else if(yi_dong==80) fang_xiang=4; 
            else if(yi_dong=='w'){
                if(mx-1>=0 && mao_xian_dt[mx-1][my]==' '){
                    nx--;
                }
            }
            else if(yi_dong=='s'){
                if(mx+1<10 && mao_xian_dt[mx+1][my]==' '){
                    nx++;
                }
            }
            else if(yi_dong=='a'){
                if(my-1>=0 && mao_xian_dt[mx][my-1]==' '){
                    ny--;
                }
            }
            else if(yi_dong=='d'){
                if(my+1<10 && mao_xian_dt[mx][my+1]==' '){
                    ny++;

                }
            }
            if(yi_dong=='e')  da_kai_be_bao();
            mao_xian_dt[mx][my] = ' ';
            mao_xian_dt[nx][ny] = 'r';
            mx=nx; my=ny;
        }
        system("cls");
    }
}
void jp(){
    char yi_dong;
    if(_kbhit() != 0){
        yi_dong = getch();
        int nx = x,ny = y;
        if(yi_dong==72) fang_xiang=2;
        else if(yi_dong==75) fang_xiang=1;
        else if(yi_dong==77) fang_xiang=3;
        else if(yi_dong==80) fang_xiang=4; 
        else if(yi_dong=='w'){
            if(x-1>=0 && ditu[x-1][y]==' '){
                nx--;
            }
        }
        else if(yi_dong=='s'){
            if(x+1<10 && ditu[x+1][y]==' '){
                nx++;
            }
        }
        else if(yi_dong=='a'){
            if(y-1>=0 && ditu[x][y-1]==' '){
                ny--;
            }
        }
        else if(yi_dong=='d'){
            if(y+1<10 && ditu[x][y+1]==' '){
                ny++;

            }
        }
        else if(yi_dong=='q'){
            if(ditu[xuan_zhong_x][xuan_zhong_y]=='A')shang_ren_gou_mai();

        } 
        else if(yi_dong=='1'){
            if(ditu[xuan_zhong_x][xuan_zhong_y]=='d') mao_xian();
        } 
        else if(yi_dong=='e')  da_kai_be_bao();
        ditu[x][y] = ' ';
        ditu[nx][ny] = 'r';
        x=nx; y=ny;
    }
} 
void SetPos(int x,int y){
    COORD pos;
    pos.X=y,pos.Y=x;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}

int main(){
    cout<<"这里是一个修仙的世界,大家都过着幸福的生活,可是有一天,灾厄天降,一个巨大的阴谋席卷了这片大陆......."<<endl;
    Sleep(200);
    cout<<"你需要收集资源,调查这片大陆的秘密,兴许可以拯救它..."<<endl;
    Sleep(200);
    cout<<"请输入您的名字:";
    string xm;
    cin>>xm;
    if(xm=="杨越江666"){
        jin_bi+=1000;
    }
    system("cls");
    cout<<"您要进入新手教程吗\n0.要  1.不要\n";
    int xsjc;
    cin>>xsjc;
    if(xsjc==0){
        cout<<"操作规则:\n";
        Sleep(200);
        cout<<"w,a,s,d,移动\n";
        Sleep(200);
        cout<<"空格键像面向方向攻击\n";
        Sleep(200);
        cout<<"变白为攻击到的地方\n";
        Sleep(200);
        cout<<"e键打开背包,红色的为选择的物品,按A键使用\n";
        Sleep(200);
        cout<<"e键退出背包\n";
        Sleep(200);
        cout<<"按A键与NPC互动\n"; 
        Sleep(200);
        cout<<"地图规则:\n";
        Sleep(200);
        cout<<"空格无作用\n";
        Sleep(200);
        cout<<"A为商人\n";
        Sleep(200);
        cout<<"B为敌人\n"; 
        Sleep(200);
        cout<<"r为我\n";
        Sleep(200);
        cout<<"*为墙壁\n";
        Sleep(200);
        cout<<"&为宝箱\n";
        cout<<"如果读完请按1";
        int xsjcA;
        xsjcA = getch();
    }
    system("cls");
    while(true){
        zhuang_tai();
        cout<<"\n\n";
        if(fang_xiang==1) xuan_zhong_x=x,xuan_zhong_y=y-1;
        if(fang_xiang==2) xuan_zhong_y=y,xuan_zhong_x=x-1;
        if(fang_xiang==3) xuan_zhong_x=x,xuan_zhong_y=y+1;
        if(fang_xiang==4) xuan_zhong_y=y,xuan_zhong_x=x+1;

        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                if(xuan_zhong_x==i && xuan_zhong_y==j) SetColorAndBackground(15,4);
                cout<<ditu[i][j]<<" ";
                SetColorAndBackground(15,0);
            }
            cout<<"\n";
        }
        if(ditu[xuan_zhong_x][xuan_zhong_y]=='A') shang_ren();
        if(ditu[xuan_zhong_x][xuan_zhong_y]=='d'){
            cout<<"冒险:\n";
            cout<<"1:随机(i:离开)";

        }
        jp();
        if(ling_qi_zhi>=ti_sheng_ling_qi[da_jing_jie_shu]) tu_po();
//      if(yi_dong==' ') zhan_dou();
        Sleep(50);
        system("cls");
    }
    return 0;
}