地下城大战

· · 个人记录

#include <bits/stdc++.h>
#include <cstdlib>
#include <windows.h>
#include <conio.h>
#include <string>
using namespace std;

char  a[14][100] = {"| S小怪 M大怪 O入口 0你的位置 R小资源 H大资源 @传送门 -道路 |道路 X回血|",
                    "|                                                                      |",
                    "|      |S-R-X|-H--M-S-R-S-S-H-M-X---|      |-X|-S--H-|                 |",
                    "|      M     |       |              |-S|R--|  |      |                 |",
                    "|      |     |-M--X--|H-R-|     |-S-|  |      |-M--H--|                |",
                    "|      S--R--|       |    |--M-R|      |-S|-X-|       |--@             |",
                    "| O0-|-----|R-M-S--|R-M-|--X--|S-S-M-|X-|-R-|-H-M-M---|                |",
                    "|      M--S|-|-X-R---|    |-|S-H|    |    |   |       |                |",
                    "|      S   |      |  |      |        |-X-|-M-|-H-|-MH-|                |",
                    "|      H   |-S--R-|-S--X-R--|-S-M--H-|       |        |                |",
                    "|      X   |                         |    |H-|X-H-H-M-|                |",
                    "|      R--M|S---H---M--M-X-|-S-M-R--S|-M-H|                            |",
                    "|                                                                      |"
                   };

char  b[14][100] = {"| S小怪 M大怪 O入口 0你的位置 R小资源 H大资源 @传送门 -道路 |道路 X回血|",
                    "|                                                                      |",
                    "|      |S-R-X|-H--M-S-R-S-S-H-M-X---|      |-X|-S--H-|                 |",
                    "|      M     |       |              |-S|R--|  |      |                 |",
                    "|      |     |-M--X--|H-R-|     |-S-|  |      |-M--H--|                |",
                    "|      S--R--|       |    |--M-R|      |-S|-X-|       M--@             |",
                    "| O0-|-----|R-M-S--|R-M-|--X--|S-S-M-|X-|-R-|-H-M-M-M-|                |",
                    "|      M--S|-|-X-R---|    |-|S-H|    |    |   |       |                |",
                    "|      S   |      |  |      |        |-X-|-M-|-H-|-MH-|                |",
                    "|      H   |-S--R-|-S--X-R--|-S-M--H-|       |        |                |",
                    "|      X   |                         |    |H-|X-H-H-M-|                |",
                    "|      R--M|S---H---M--M-X-|-S-M-R--S|-M-H|                            |",
                    "|                                                                      |"
                   };
int c;
int shang_hai = 5;
int sheng_ming = 5;
int sheng_ming_zhi = 5;
int jb = 0;
string xing_ming;
int l, j;
void game_2();
void player_zi_liao();
void player();
void shop();
void zi_mu_1();
void q();
void game_1();
void s_1();
void shi_bai();
void da_guai();
void xiao_guai();
void xiao_ziyuan();
void da_ziyuan();
void hui_xue();
void sheng_li();
//S小怪 M大怪 O入口 0你的位置 R小资源 H大资源 @传送门 -道路 |道路 X回血

void sheng_li() {
    q();
    cout << "恭喜你,通关了!\n";
    cout << "下次更新 英雄 技能 道具 更多战斗系统 更多武器和防具 任务系统 经验与等级 材料(合成神器)....提前预告:下个版本 小镇2.0新的危机\n";
    system("pause");
}

void hui_xue() {
    q();
    if (sheng_ming < sheng_ming_zhi) {
        sheng_ming++;
        cout << "生命值加1";
    } else {
        cout << "生命值已满,回不了血";
    }
    Sleep(1000);
    q();
}

void xiao_ziyuan() {
    q();
    cout << "恭喜你获得 金币+2";
    jb += 2;
    Sleep(1000);
    q();
}

void da_ziyuan() {
    q();
    cout << "恭喜你获得 金币+5";
    jb += 5;
    Sleep(1000);
    q();
}

void da_guai() {
    q();
    int bguai_xue;
    cout << "即将跟大怪物战斗\n";
    bguai_xue = 12;
    while (1) {
        if (sheng_ming <= 0) {
            cout << "你被大怪打死了";
            Sleep(1000);
            q();
            break;
        }
        if (bguai_xue <= 0) {
            cout << "你打败了大怪";
            Sleep(1000);
            q();
            break;
        }
        cout << "\n1.攻击 2.防御(暂时获得1血)\n";
        cout << "请输入:";
        cin >> c;
        if (c == 1) {
            bguai_xue -= shang_hai;
            cout << "\n成功造成攻击\n";
            Sleep(500);
            cout << "你受到伤害*5";
            sheng_ming -= 5;
        }
        if (c == 2) {
            sheng_ming++;
            sheng_ming -= 5;
        }
        cout << "\n你的生命:" << sheng_ming;
        cout << "\n怪物的生命:" << bguai_xue;
    }
}

void xiao_guai() {
    q();
    int sguai_xue;
    cout << "即将跟小怪物战斗\n";
    sguai_xue = 6;
    while (1) {
        if (sheng_ming <= 0) {
            cout << "你被小怪打死了";
            Sleep(1000);
            q();
            break;
        }
        if (sguai_xue <= 0) {
            cout << "你打败了小怪";
            Sleep(1000);
            q();
            break;
        }
        cout << "\n1.攻击 2.防御(暂时获得1血)\n";
        cout << "请输入:";
        cin >> c;
        if (c == 1) {
            sguai_xue -= shang_hai;
            cout << "\n成功造成攻击\n";
            Sleep(500);
            cout << "你受到伤害*5";
            sheng_ming -= 3;
        }
        if (c == 2) {
            sheng_ming++;
            sheng_ming -= 3;
        }
        cout << "\n你的生命:" << sheng_ming;
        cout << "\n怪物的生命:" << sguai_xue;
    }
}

void s_1() {
    cout << "\t";
    cout << "小镇";
    Sleep(500);
    cout << "1.0";
    Sleep(500);
    cout << "地下城";
    Sleep(1000);
    q();
    zi_mu_1();
}

void player_zi_liao() {
    q();
    cout << "\n    名字:" << xing_ming << endl;
    cout << "    金币:" << jb << endl;
    cout << "    伤害:" << shang_hai << endl;
    cout << "    生命:" << sheng_ming << endl;
    Sleep(2000);
    game_1();
}

void player() {
    q();
    cout << "勇士,请输入你的姓名:";
    cin >> xing_ming;
    game_1();
}

void q() {
    system("cls");
}

void zi_mu_1() {
    cout << "卡罗特小镇的资源一天天流逝,直到今天,资源严重缺乏,你身为勇士,不愿看到大家一个一个被饿死,决定去地下城闯一闯\n";
    system("pause");
    q();
    player();
}

void game_1() {
    q();
    cout << "\n";
    cout << "\t\t小镇\n\n";
    cout << "\t1.去地下城  2.铁匠铺  3.个人资料 4.查看下个版本更新内容 \n";
    cout << "你选择:";
    cin >> l;
    if (l == 2) {
        shop();
    }
    if (l == 3) {
        player_zi_liao();
    }
    if (l == 1) {
        game_2();
    }
    if (l == 4) {
        cout << "下次更新 英雄 技能 道具 更多战斗系统 更多武器和防具 任务系统 经验与等级 材料(合成神器)....提前预告:下个版本 小镇2.0新的危机\n";
        system("pause");
        game_1();
    }
}

void shi_bai() {
    q();
    cout << "你死亡了(装备不掉落)";
    Sleep(1000);
    q();
    game_1();
}



void game_2() {
    q();
    int i, k;
    for (i = 0; i < 14; i++)
        for (k = 0; k < 100; k++) {
            a[i][k] = b[i][k];
        }
    int x = 6, y = 5;
    for (i = 0; i <= 12; i++)
        cout << a[i] << endl;
    char ch;
    while (1) {
        if (sheng_ming <= 0) {
            shi_bai();
        }
        ch = getch();
        if (ch == 'w') { //S小怪 M大怪 O入口 0你的位置 R小资源 H大资源 @传送门 -道路 |道路 X回血
            if (a[x - 1][y] == '-' || a[x - 1][y] == '|' || a[x - 1][y] == 'R' || a[x - 1][y] == 'S' || a[x - 1][y] == 'M'
                    || a[x - 1][y] == 'H' || a[x - 1][y] == 'X') {
                if (a[x - 1][y] == 'H') {
                    q();
                    da_ziyuan();
                    q();
                }
                if (a[x - 1][y] == 'R') {
                    q();
                    xiao_ziyuan();
                    q();
                }
                if (a[x - 1][y] == 'S') {
                    q();
                    xiao_guai();
                    q();
                }
                if (a[x - 1][y] == 'M') {
                    q();
                    da_guai();
                    q();
                }
                if (a[x - 1][y] == 'X') {
                    q();
                    hui_xue();
                    q();
                }
                if (a[x + 1][y] != ' ' || a[x - 1][y] != ' ') {
                    a[x][y] = '|';
                } else {
                    a[x][y] = '-';
                }
                x--;
                a[x][y] = '0';
                q();
                for (i = 0; i <= 12; i++)
                    cout << a[i] << endl;
            }
        }
        if (ch == 's') { //S小怪 M大怪 O入口 0你的位置 R小资源 H大资源 @传送门 -道路 |道路 X回血
            if (a[x + 1][y] == '-' || a[x + 1][y] == '|' || a[x + 1][y] == 'R' || a[x + 1][y] == 'S' || a[x + 1][y] == 'M'
                    || a[x + 1][y] == 'H' || a[x + 1][y] == 'X') {
                if (a[x + 1][y] == 'H') {
                    q();
                    da_ziyuan();
                    q();
                }
                if (a[x + 1][y] == 'R') {
                    q();
                    xiao_ziyuan();
                    q();
                }
                if (a[x + 1][y] == 'S') {
                    q();
                    xiao_guai();
                    q();
                }
                if (a[x + 1][y] == 'M') {
                    q();
                    da_guai();
                    q();
                }
                if (a[x + 1][y] == 'X') {
                    q();
                    hui_xue();
                    q();
                }
                if (a[x + 1][y] != ' ' || a[x - 1][y] != ' ') {
                    a[x][y] = '|';
                } else {
                    a[x][y] = '-';
                }
                x++;
                a[x][y] = '0';
                q();
                for (i = 0; i <= 12; i++)
                    cout << a[i] << endl;


            }
        }
        if (ch == 'a') { //S小怪 M大怪 O入口 0你的位置 R小资源 H大资源 @传送门 -道路 |道路 X回血
            if (a[x][y - 1] == '-' || a[x][y - 1] == '|' || a[x][y - 1] == 'R' || a[x][y - 1] == 'S' || a[x][y - 1] == 'M'
                    || a[x][y - 1] == 'H' || a[x][y - 1] == 'X') {
                if (a[x][y - 1] == 'H') {
                    q();
                    da_ziyuan();
                    q();
                }
                if (a[x][y - 1] == 'R') {
                    q();
                    xiao_ziyuan();
                    q();
                }
                if (a[x][y - 1] == 'S') {
                    q();
                    xiao_guai();
                    q();
                }
                if (a[x][y - 1] == 'M') {
                    q();
                    da_guai();
                    q();
                }
                if (a[x][y - 1] == 'X') {
                    q();
                    hui_xue();
                    q();
                }
                if (a[x][y + 1] != ' ' || a[x][y - 1] != ' ') {
                    a[x][y] = '-';
                } else {
                    a[x][y] = '|';
                }
                y--;
                a[x][y] = '0';
                q();
                for (i = 0; i <= 12; i++)
                    cout << a[i] << endl;


            }
        }
        if (ch == 'd') { //S小怪 M大怪 O入口 0你的位置 R小资源 H大资源 @传送门 -道路 |道路 X回血
            if (a[x][y + 1] == '-' || a[x][y + 1] == '|' || a[x][y + 1] == 'R' || a[x][y + 1] == 'S' || a[x][y + 1] == 'M'
                    || a[x][y + 1] == 'H' || a[x][y + 1] == 'X' || a[x][y + 1] == '@') {
                if (a[x][y + 1] == 'H') {
                    q();
                    da_ziyuan();
                    q();
                }
                if (a[x][y + 1] == '@') {
                    q();
                    sheng_li();
                    break;
                }
                if (a[x][y + 1] == 'R') {
                    q();
                    xiao_ziyuan();
                    q();
                }
                if (a[x][y + 1] == 'S') {
                    q();
                    xiao_guai();
                    q();
                }
                if (a[x][y + 1] == 'M') {
                    q();
                    da_guai();
                    q();
                }
                if (a[x][y + 1] == 'X') {
                    q();
                    hui_xue();
                    q();
                }
                if (a[x][y + 1] != ' ' || a[x][y + 1] != ' ') {
                    a[x][y] = '-';
                } else {
                    a[x][y] = '|';
                }
                y++;
                a[x][y] = '0';
                q();
                for (i = 0; i <= 12; i++)
                    cout << a[i] << endl;


            }
        }
    }
}


void shop() {
    q();
    cout << "欢迎光临!\n";
    cout << "请问你需要什么帮助? (注意:伤害和生命值是=关系,不是+的关系,比如你现在伤害是5,买了桃木剑是把伤害变为10,而不是加10)\n";
    cout << "1.桃木剑    10伤害 20金币\n";
    cout << "2.铁剑      15伤害 30金币\n";
    cout << "3.黄金剑    30伤害 40金币\n";
    cout << "4.钻石剑    40伤害 50金币\n";
    cout << "5.x光剑     50伤害 100金币\n";
    cout << "6.皮革甲    10生命 20金币\n";
    cout << "7.铁甲      15生命 30金币\n";
    cout << "8.黄金甲    30生命 40金币\n";
    cout << "9.钻石甲    40生命 50金币\n";
    cout << "10.激光披风 50生命 100金币\n";
    cout << "11.返回\n";
    cout << "请输入:";
    cin >> j;
    if (j == 1 || j == 6) {
        if (jb >= 20) {
            jb -= 20;
            if (j == 1)
                shang_hai = 10;
            else {
                sheng_ming = 10;
                sheng_ming_zhi = 10;
            }
            game_1();
        } else
            cout << "金币不够";
        game_1();
    }
    if (j == 2 || j == 7) {
        if (jb >= 30) {
            jb -= 20;
            if (j == 2)
                shang_hai = 15;
            else {
                sheng_ming = 15;
                sheng_ming_zhi = 15;
            }
            game_1();
        } else
            cout << "金币不够";
        game_1();
    }
    if (j == 3 || j == 8) {
        if (jb >= 40) {
            jb -= 40;
            if (j == 3)
                shang_hai = 30;
            else {
                sheng_ming = 30;
                sheng_ming_zhi = 30;
            }
            game_1();
        } else
            cout << "金币不够";
        game_1();
    }
    if (j == 4 || j == 9) {
        if (jb >= 50) {
            jb -= 50;
            if (j == 4)
                shang_hai = 40;
            else {
                sheng_ming = 40;
                sheng_ming_zhi = 40;
            }
            game_1();
        } else
            cout << "金币不够";
        game_1();
    }
    if (j == 5 || j == 10) {
        if (jb >= 100) {
            jb -= 100;
            if (j == 5)
                shang_hai = 50;
            else {
                sheng_ming = 50;
                sheng_ming_zhi = 50;
            }
            game_1();
        } else
            cout << "金币不够";
        game_1();
    }
    if (j == 11) {
        game_1();
    }
}

int main() {
    system("title 小镇1.0地下城");
    s_1();
    return 0;
}