问题标题: 矿工模拟器1.0

0
0
丛梓嫣
丛梓嫣
修练者
修练者


```

#include<iostream>
#include<cstdlib>
#include<ctime>
#include<string>
using namespace std;

//矿工信息
struct Miner{
    int hp;     //体力
    int money;  //金币
    int pickLv; //镐子等级
};

//矿石
struct Ore{
    string name;
    int price;
};

//背包结构体:存放4种矿石数量
struct Bag{
    int coal;   //煤矿
    int iron;   //铁矿
    int silver; //银矿
    int gold;   //金矿
};

int main(){
    srand((unsigned)time(NULL));
    Miner me;
    Bag bag;
    //初始化
    me.hp = 100;
    me.money = 50;
    me.pickLv = 1;
    bag.coal = 0;
    bag.iron = 0;
    bag.silver = 0;
    bag.gold = 0;

    Ore ore[4] = {
        {"煤矿", 5},
        {"铁矿", 15},
        {"银矿", 30},
        {"金矿", 80}
    };

    int op;
    while(true){
        cout << "===== ??矿工模拟器3.1 =====" << endl;
        cout << "体力:" << me.hp << "  金币:" << me.money << "  镐等级:" << me.pickLv << endl;
        cout << "【背包】煤:"<<bag.coal<<" 铁:"<<bag.iron<<" 银:"<<bag.silver<<" 金:"<<bag.gold << endl;
        cout << "【1】挖矿  【2】商店  【3】休息  【0】退出游戏" << endl;
        cout << "请输入选择:";
        cin >> op;

        if(op == 1){
            if(me.hp <= 0){
                cout << "体力不足!快去休息!" << endl;
                continue;
            }
            me.hp -= 10;
            int r = rand()%10;
            cout << "你用力挥动镐子..." ;
            if(r < 4){
                bag.coal++;
                cout << "挖到【煤矿】!放进背包。" << endl;
            }
            else if(r <7){
                bag.iron++;
                cout << "挖到【铁矿】!放进背包。" << endl;
            }
            else if(r<9){
                bag.silver++;
                cout << "挖到【银矿】!放进背包。" << endl;
            }
            else{
                bag.gold++;
                cout << "挖到【金矿】!放进背包。" << endl;
            }
        }
        else if(op == 2){
            cout << "\n====??商店====" << endl;
            cout << "1.出售背包全部矿石"<<endl;
            cout << "2.购买食物(+30体力) 售价20金币"<<endl;
            cout << "3.升级镐子 售价100金币"<<endl;
            cout << "0.离开商店"<<endl;
            int shopOp;
            cin >> shopOp;
            if(shopOp == 1){
                int total = (bag.coal*ore[0].price + bag.iron*ore[1].price
                            + bag.silver*ore[2].price + bag.gold*ore[3].price)*me.pickLv;
                me.money += total;
                cout << "卖出所有矿石,获得 "<<total<<" 金币!"<<endl;
                //清空背包
                bag.coal=0;
                bag.iron=0;
                bag.silver=0;
                bag.gold=0;
            }
            else if(shopOp == 2){
                if(me.money >=20){
                    me.money -=20;
                    me.hp +=30;
                    cout << "购买成功!体力+30"<<endl;
                }else{
                    cout << "金币不够!"<<endl;
                }
            }
            else if(shopOp ==3){
                if(me.money >=100){
                    me.money -=100;
                    me.pickLv +=1;
                    cout << "镐子升级成功!卖矿石收益提升!"<<endl;
                }else{
                    cout << "金币不够!"<<endl;
                }
            }
        }
        else if(op ==3){
            me.hp +=25;
            cout << "休息完毕,体力+25"<<endl;
        }
        else if(op ==0){
            cout << "游戏结束!"<<endl;
            break;
        }
        cout << "-------------------------"<<endl;
    }
    return 0;
}
//放在Dev-c++里运行

可以玩


0
程梓睿
程梓睿
中级守护
中级守护

你别用代码框,这样我们复制不了啊。

我要回答