florr小游戏

· · 个人记录

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

#define ll long long

#define GREEN 0
#define YELLOW 1
#define BLUE 2
#define PURPLE 3
#define RED 4
#define CYAN 5

#define COMMON 0
#define UNUSUAL 1
#define RARE 2
#define EPIC 3
#define LEGENDARY 4
#define MYTHIC 5

const string petal_names[30] = {
    "Light", "Wings", "Rice",   "Stinger", "Egg (1x)", "Egg (4x)", "Orange",    "Rose",
    "Claw",  "Sand",  "Cutter", "Peas",    "Missle",   "Heavy",    "Lightning", "j2k183",
};

const string lvl_names[6] = { "绿", "黄", "蓝", "紫", "红", "青" };

const int attack[30][6] = { { 5, 25, 80, 270, 1080, 2480 },      { 10, 60, 150, 360, 800, 1800 },
                            { 2, 12, 42, 252, 842, 1682 },       { 183, 283, 383, 683, 883, 1883 },

                            { 10, 50, 100, 600, 1000, 2000 },    { 20, 100, 200, 1200, 2000, 4000 },
                            { 30, 90, 270, 810, 1620, 2480 },    { -5, -45, -125, -725, -1725, -3025 },

                            { 183, 283, 383, 683, 883, 1883 },   { 15, 40, 100, 160, 480, 1280 },
                            { 20, 220, 420, 620, 820, 1020 },    { 20, 40, 100, 200, 800, 1600 },

                            { 183, 283, 383, 683, 883, 1883 },   { 1, 5, 25, 125, 375, 1875 },
                            { 100, 300, 600, 1000, 1500, 2100 }, { 1, 11, 114, 1145, 11451, 114514 } };

const int naijiu[30] = { 10, 5, 10, 3, 1, 1, 5, 5, 3, 3, 10, 10, 3, 30, 1, 114514 };

void p(string s, int v = 20) {
    for (char ch : s) {
        cout << ch;
        Sleep(v);
    }
    cout << endl;
}

void pp(string s, int v = 20) {
    for (char ch : s) {
        cout << ch;
        Sleep(v);
    }
}

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

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

struct Enemy {
    string name;
    int atk, range;
    int bisha_type;
    int gongji() { return atk + (rand() % (2 * range + 1)) - range; }
    int bisha() {
        if (bisha_type == 1) {
            return atk + (rand() % (2 * range + 1)) - range;
        } else if (bisha_type == 2) {
            return (atk + (rand() % (2 * range + 1) - range)) * 3;
        } else if (bisha_type == 3) {
            return atk * (rand() % 3 + 1);
        } else if (bisha_type == 4) {
            return 0;
        } else if (bisha_type == 5) {
            return 114514;
        }
    }
    string bisha_name() {  // 怪物名称[return value],你受到了[bisha() return value]的攻击
        if (bisha_type == 1) {
            return "攻击了你";
        } else if (bisha_type == 2) {
            return "精准打只因";
        } else if (bisha_type == 3) {
            return "即兴发挥";
        } else if (bisha_type == 4) {
            return "神经发癫";
        } else if (bisha_type == 5) {
            return "是一拳超人";
        }
    }
};

struct Menu {
    int v = 20;
    vector<string> options;
    void add(string s) { options.push_back(s); }
    int show() {
        cls();
        for (string s : options) {
            cout << "* ";
            p(s, v);
        }
        int cur = 0;
        while (true) {
            cls();
            for (int i = 0; i < options.size(); i++) {
                if (cur == i) {
                    cout << "> ";
                } else {
                    cout << "* ";
                }
                cout << options[i] << endl;
            }
            char ch = getch();
            if (ch == 'w') {
                cur = max(0, cur - 1);
            } else if (ch == 's') {
                cur = min((int)options.size() - 1, cur + 1);
            } else if (ch == ' ') {
                return cur;
            }
        }
    }
};

struct Petal {
    int lvl, id;
    int atk, nj;
    Petal(int idx = 0, int l = COMMON) {
        id = idx;
        lvl = l;
        atk = attack[id][lvl];
        nj = naijiu[idx];
    }
    string name() { return lvl_names[lvl] + " " + petal_names[id]; }
};

int money = 100;
int xp = 100;
int hp = 0;

vector<Petal> backpack;

int power(int a, int x) {
    int ans = 1;
    for (int i = 0; i < x; i++) {
        ans *= a;
    }
    return ans;
}

void daguai() {
    cls();
    int type = rand() % 30;
    int lvl = rand() % 6;
    Enemy enemy;
    int prob;
    int ehp;
    if (type <= 6) {
        enemy.name = "Ladybug";
        enemy.atk = 5 * power(3, lvl);
        enemy.range = 2 * power(3, lvl);
        enemy.bisha_type = 1, prob = 100;
        ehp = 100 * power(3, lvl);
    } else if (type <= 11) {
        enemy.name = "Bee";
        enemy.atk = 10 * power(3, lvl);
        enemy.range = 4 * power(3, lvl);
        enemy.bisha_type = 4, prob = 10;
        ehp = 30 * power(3, lvl);
    } else if (type <= 13) {
        enemy.name = "Baby Ant";
        enemy.atk = 0;
        enemy.range = 0;
        enemy.bisha_type = 5, prob = 1;
        ehp = 50 * power(3, lvl);
    } else if (type <= 23) {
        enemy.name = "Hornet";
        enemy.atk = 20 * power(3, lvl);
        enemy.range = 10 * power(2, lvl);
        enemy.bisha_type = 2, prob = 30;
        ehp = 150 * power(3, lvl);
    } else if (type <= 29) {
        enemy.name = "Beetle";
        enemy.atk = 10 * power(3, lvl);
        enemy.range = 0;
        enemy.bisha_type = 3, prob = 30;
        ehp = 200 * power(3, lvl);
    }
    p("你遇到了 " + lvl_names[lvl] + " " + enemy.name + "!");
    p("战斗?(Y/N)");
    char ch = getch();
    if (ch == 'n' || ch == 'N') {
        return;
    }
    hp = xp;
    while (true) {
        // 我方攻击
        cls();
        if (backpack.size() == 0) {
            p("你没有花瓣了");
            hp = 0;
            Sleep(1000);
            break;
        }
        Menu menu;
        menu.v = 1;
        for (Petal x : backpack) {
            if (x.id == 7) {
                menu.add(x.name() + " HEAL " + to_string(-x.atk) + " HP " + to_string(x.nj));
            } else {
                menu.add(x.name() + " ATK " + to_string(x.atk) + " HP " + to_string(x.nj));
            }
        }
        int petal_idx = menu.show();
        if (backpack[petal_idx].id != 7) {
            ehp = max(0, ehp - backpack[petal_idx].atk);
            backpack[petal_idx].nj--;
            p("你使用 " + backpack[petal_idx].name());
            p("对方掉了 " + to_string(backpack[petal_idx].atk) + " 点血");
            p("对方剩余 " + to_string(ehp) + " 点血");
            if (!backpack[petal_idx].nj) {
                backpack.erase(backpack.begin() + petal_idx);
            }
            Sleep(1000);
            if (!ehp) {
                break;
            }
        } else {
            hp = min(xp, hp - backpack[petal_idx].atk);
            backpack[petal_idx].nj--;
            p("你使用 " + backpack[petal_idx].name());
            p("你回复了 " + to_string(-backpack[petal_idx].atk) + " 点血");
            p("你现在有 " + to_string(hp) + " 点血");
            if (!backpack[petal_idx].nj) {
                backpack.erase(backpack.begin() + petal_idx);
            }
            Sleep(1000);
        }
        // 敌方攻击
        cls();
        if (rand() % 100 < prob) {
            int x = enemy.bisha();
            hp = max(0, hp - x);
            p("对方" + enemy.bisha_name() + ",你受到了 " + to_string(x) + " 的攻击");
            p("还剩 " + to_string(hp) + " 点血");
        } else {
            int x = enemy.gongji();
            hp = max(0, hp - x);
            p("对方攻击了你,你受到了 " + to_string(x) + " 的攻击");
            p("还剩 " + to_string(hp) + " 点血");
        }
        Sleep(1000);
        if (!hp) {
            break;
        }
    }
    cls();
    if (!ehp) {
        p("对方被击败了");
        int huode = 0, jinbi = 0;
        if (type <= 6) {
            huode = 4 * power(3, lvl);
            jinbi = 20 * power(3, lvl);
        } else if (type <= 11) {
            huode = 5 * power(3, lvl);
            jinbi = 30 * power(3, lvl);
        } else if (type <= 13) {
            huode = 1 * power(3, lvl);
            jinbi = 10 * power(3, lvl);
        } else if (type <= 23) {
            huode = 10 * power(3, lvl);
            jinbi = 50 * power(3, lvl);
        } else if (type <= 29) {
            huode = 10 * power(3, lvl);
            jinbi = 40 * power(3, lvl);
        }
        p("获得 " + to_string(huode) + " XP," + to_string(jinbi) + " FDL");
        xp += huode, money += jinbi;
        if (type <= 6) {
            Petal a(0, lvl);
            Petal b(7, lvl);
            backpack.push_back(a);
            backpack.push_back(b);
        } else if (type <= 11) {
            Petal a(0, lvl);
            Petal b(3, lvl);
            backpack.push_back(a);
            backpack.push_back(b);
        } else if (type <= 13) {
            Petal a(2, lvl);
            Petal b(5, lvl);
            backpack.push_back(a);
            backpack.push_back(b);
        } else if (type <= 23) {
            Petal a(6, lvl);
            Petal b(12, lvl);
            backpack.push_back(a);
            backpack.push_back(b);
        } else if (type <= 29) {
            Petal a(4, lvl);
            Petal b(9, lvl);
            backpack.push_back(a);
            backpack.push_back(b);
        }
        p("获得了两张卡片 [请于背包查看] ");
    } else {
        p("你被击败了");
    }
    Sleep(2000);
    return;
}

void buyhuaban() {
    Petal a(0, RARE), b(3, RARE), c(6, RARE), d(7, RARE);
    Petal e(3, RED), f(6, RED), g(7, RED);
    Menu menu;
    menu.v = 1;
    menu.add("蓝 Light        500 FDL");
    menu.add("蓝 Stingers     400 FDL");
    menu.add("蓝 Orange       700 FDL");
    menu.add("蓝 Rose         800 FDL");
    menu.add("红 Stingers     2500 FDL");
    menu.add("红 Orange       3000 FDL");
    menu.add("红 Rose         3000 FDL");
    menu.add("查看自己的钱包");
    menu.add("退出");
    int chs = menu.show();
    cls();
    switch (chs) {
        case 0:
            if (money >= 500) {
                money -= 500;
                p("购买成功");
                backpack.push_back(a);
            } else {
                p("你没钱了");
            }
            break;
        case 1:
            if (money >= 400) {
                money -= 400;
                p("购买成功");
                backpack.push_back(b);
            } else {
                p("你没钱了");
            }
            break;
        case 2:
            if (money >= 700) {
                money -= 700;
                p("购买成功");
                backpack.push_back(c);
            } else {
                p("你没钱了");
            }
            break;
        case 3:
            if (money >= 800) {
                money -= 800;
                p("购买成功");
                backpack.push_back(d);
            } else {
                p("你没钱了");
            }
            break;
        case 4:
            if (money >= 2500) {
                money -= 2500;
                p("购买成功");
                backpack.push_back(e);
            } else {
                p("你没钱了");
            }
            break;
        case 5:
            if (money >= 3000) {
                money -= 3000;
                p("购买成功");
                backpack.push_back(f);
            } else {
                p("你没钱了");
            }
            break;
        case 6:
            if (money >= 3000) {
                money -= 3000;
                p("购买成功");
                backpack.push_back(g);
            } else {
                p("你没钱了");
            }
            break;
        case 7:
            p("你有 " + to_string(money) + " FDL (Florr Dollars)");
            break;
        default:
            return;
    }
    pause();
}

void salehuaban() {
    Menu menu;
    menu.v = 1;
    for (Petal x : backpack) {
        if (x.id == 7) {
            menu.add(x.name() + " HEAL " + to_string(-x.atk) + " HP " + to_string(x.nj));
        } else {
            menu.add(x.name() + " ATK " + to_string(x.atk) + " HP " + to_string(x.nj));
        }
    }
    menu.add("退出");
    int idx = menu.show();
    if (idx == backpack.size()) {
        return;
    }
    int gain;
    if (backpack[idx].lvl == COMMON) {
        gain = 1 * backpack[idx].nj;
    } else if (backpack[idx].lvl == UNUSUAL) {
        gain = 5 * backpack[idx].nj;
    } else if (backpack[idx].lvl == RARE) {
        gain = 20 * backpack[idx].nj;
    } else if (backpack[idx].lvl == EPIC) {
        gain = 80 * backpack[idx].nj;
    } else if (backpack[idx].lvl == LEGENDARY) {
        gain = 250 * backpack[idx].nj;
    } else if (backpack[idx].lvl == MYTHIC) {
        gain = 700 * backpack[idx].nj;
    }
    backpack.erase(backpack.begin() + idx);
    p("出售成功,获得 " + to_string(gain) + " XP 和 " + to_string(gain) + " FDL");
    xp += gain, money += gain;
    Sleep(1000);
}

void shuxing() {
    pp("经验值(血量上限):");
    cout << xp << endl;
    pp("钱包:");
    cout << money << " FDL" << endl;
    p(" ");
    p("背包:");
    for (Petal x : backpack) {
        if (x.id == 7) {
            p(x.name() + " HEAL " + to_string(-x.atk) + " HP " + to_string(x.nj), 1);
        } else {
            p(x.name() + " ATK " + to_string(x.atk) + " HP " + to_string(x.nj), 1);
        }
    }
    pause();
}

bool comes = 0;
void xunlianying() {
    cls();
    if (!comes) {
        p("在灾难面前,一群花组成了一个训练营");
        p("它们的目标,是通过训练得到提升");
        p("然后去击败那只Hornet……");
        pause();
    }
    comes = 1;
    cls();
    p("最近,训练营流行一种训练:反应速度!");
    p("做得好的,还可以获得花瓣!");
    Sleep(1000);
    Menu menu;
    menu.add("挑战");
    menu.add("退出");
    int x = menu.show();
    if (x == 1) {
        return;
    }
    cls();
    puts("Waiting ...");
    Sleep(rand() % 2001 + 3000);
    puts("Press Any Key!");
    double st = clock() * 1.0 / CLOCKS_PER_SEC * 1000;
    system("pause>nul");
    double ed = clock() * 1.0 / CLOCKS_PER_SEC * 1000;
    cls();
    p("你的成绩为:" + to_string((int)(ed - st)) + " ms");
    Petal got;
    if (ed - st <= 20) {
        Petal x(rand() % 15, MYTHIC);
        got = x;
    } else if (ed - st <= 50) {
        Petal x(rand() % 15, LEGENDARY);
        got = x;
    } else if (ed - st <= 100) {
        Petal x(rand() % 15, EPIC);
        got = x;
    } else if (ed - st <= 200) {
        Petal x(rand() % 15, RARE);
        got = x;
    } else if (ed - st <= 350) {
        Petal x(rand() % 15, UNUSUAL);
        got = x;
    } else if (ed - st <= 500) {
        Petal x(rand() % 15, COMMON);
        got = x;
    } else {
        p("你什么也没获得……");
        pause();
        return;
    }
    p("你获得了 " + got.name() + " !");
    backpack.push_back(got);
    pause();
}

void jvqing() {
    cls();
    p("在1919-8-10 11:45:14");
    p("安居乐业的florr国遇到了大灾难");
    p("(其实就一只粉Hornet,有什么灾难的)");
    p("而你,是全florr国最弱的花");
    p("眼看着自己的前辈们一个个失败");
    p("你只好上阵,虽然你能不能找到boss都是个问题……");
    pause();
}

void kaigua() {
    cls();
    string password;
    pp("输入密码:");
    char ch;
    while ((ch = getch()) != '\r') {
        if (ch == '\b') {
            if (password.size()) {
                putchar('\b');
                putchar(' ');
                putchar('\b');
                password.pop_back();
            }
        } else {
            putchar('*');
            password.push_back(ch);
        }
    }
    p("");
    if (password == "j2k183_and_harvey_yyds") {
        p("密码正确,已添加花瓣 j2k183");
        Petal a(15, MYTHIC);
        backpack.push_back(a);
    } else {
        p("密码错误");
    }
    Sleep(1000);
}

void game() {
    cls();
    Menu menu;
    menu.add("打怪");
    menu.add("买花瓣");
    menu.add("卖花瓣");
    menu.add("查看属性");
    menu.add("挑战boss");
    menu.add("花朵训练营");
    menu.add("查看剧情");
    menu.add("开挂");
    while (true) {
        int chs = menu.show();
        switch (chs) {
            case 0:
                daguai();
                break;
            case 1:
                buyhuaban();
                break;
            case 2:
                salehuaban();
                break;
            case 3:
                shuxing();
                break;
            case 4:
                break;
            case 5:
                xunlianying();
                break;
            case 6:
                jvqing();
                break;
            case 7:
                kaigua();
                break;
        }
    }
}

int main() {
    for (int i = 0; i < 3; i++) {
        Petal a(0, UNUSUAL);
        backpack.push_back(a);
    }
    for (int i = 0; i < 1; i++) {
        Petal a(3, UNUSUAL);
        backpack.push_back(a);
    }
    for (int i = 0; i < 1; i++) {
        Petal a(6, UNUSUAL);
        backpack.push_back(a);
    }
    for (int i = 0; i < 2; i++) {
        Petal a(7, UNUSUAL);
        backpack.push_back(a);
    }
    for (int i = 0; i < 3; i++) {
        Petal a(11, UNUSUAL);
        backpack.push_back(a);
    }
    srand(time(0));
    p("       florr 历险记");
    p("By harvey(蒟蒻) and j2(大佬)");
    p("          j2yyds");
    pause();
    game();
}