游戏
Shitou123456 · · 个人记录
#include<bits/stdc++.h>
#include<cmath>
#include<ctime>
using namespace std;
int main()
{
long long qs = 0; // 金钱
srand((unsigned)time(NULL));
int flag = 0; // 装备耐久,>0代表有工具
int sum = 0; // 小动物总数
while(1)
{
cout << "\n===== 宠物救助系统 =====" << endl;
cout << "1.寻找小动物" << endl;
cout << "2.寻找领养人" << endl;
cout << "3.购买网子、鱼竿" << endl;
cout << "4.查看当前资产" << endl;
cout << "输入Goodbye退出游戏" << endl;
string n;
cin >> n;
// 全局退出
if(n == "Goodbye")
{
cout << "最终持有金钱:" << qs << endl;
return 0;
}
// 新增:查看资产功能
if(n == "4")
{
cout << "\n===== 资产详情 =====" << endl;
cout << "现有金钱:" << qs << " 元" << endl;
cout << "当前小动物数量:" << sum << " 只" << endl;
cout << "工具剩余耐久:" << flag << endl;
continue;
}
if(n == "1")
{
cout << "\n请选择地点:" << endl;
cout << "4.森林" << endl;
cout << "5.池塘(需要工具)" << endl;
cout << "6.楼道" << endl;
string t;
cin >> t;
if(t == "4") // 森林
{
int l = rand() % 7;
if(l == 0) { cout << "1只独角仙" << endl; sum++; }
else if(l == 1) { cout << "1只小猫" << endl; sum++; }
else if(l == 2) { cout << "1只蜥蜴" << endl; sum++; }
else if(l == 3) { cout << "1只蝴蝶" << endl; sum++; }
else { cout << "什么也没捉到" << endl; }
}
else if(t == "5") // 池塘
{
if(flag <= 0)
{
cout << "你没有网子/鱼竿,不能去池塘!" << endl;
continue; // 直接跳过捕捞,不消耗耐久
}
int l = rand() % 10;
if(l == 0) { cout << "1只埃及鲶鱼" << endl; sum++; }
else if(l == 1) { cout << "1只小金鱼" << endl; sum++; }
else if(l == 2) { cout << "10只小龙虾" << endl; sum++; }
else if(l == 3) { cout << "1只大草鱼" << endl; sum++; }
else { cout << "什么也没捞到" << endl; }
flag -= 10; // 消耗耐久
if(flag < 0) flag = 0;
}
else if(t == "6") // 楼道
{
int l = rand() % 7;
if(l == 0) { cout << "1只小猫咪" << endl; sum++; }
else if(l == 1) { cout << "什么也没有" << endl; }
else { cout << "误食野生大蘑菇,送去医院,扣30元!" << endl; qs -= 30; }
}
else if(t == "Goodbye")
{
cout << "最终持有金钱:" << qs << endl;
return 0;
}
else
{
cout << "无效地点!" << endl;
}
}
else if(n == "2") // 寻找领养人
{
int l = rand() % 12;
if(l < 3)
{
cout << "今天没有人来领养" << endl;
}
else
{
cout << "一共有" << l << "位领养人!输入任意字符确认,Goodbye退出:" << endl;
string a;
cin >> a;
if(a == "Goodbye")
{
cout << "最终持有金钱:" << qs << endl;
return 0;
}
for(int i = 1; i <= l; i++)
{
int f = rand() % 8; // 0~7,对应8种动物,消除空串bug
string s;
if(f == 0) s = "1只独角仙";
else if(f == 1) s = "1只小猫";
else if(f == 2) s = "1只蜥蜴";
else if(f == 3) s = "1只蝴蝶";
else if(f == 4) s = "1只埃及鲶鱼";
else if(f == 5) s = "1只小金鱼";
else if(f == 6) s = "10只小龙虾";
else if(f == 7) s = "1只大草鱼";
cout << "第" << i << "人想领养" << s;
sum--;
int p = rand() % 40;
cout << ",愿意支付" << p << "元" << endl;
qs += p;
}
}
}
else if(n == "3") // 商店购买
{
cout << "\n商店商品:" << endl;
cout << "7.网子 100元(耐久100)" << endl;
cout << "8.鱼竿 10元(耐久10)" << endl;
string a;
cin >> a;
if(a == "7")
{
if(qs >= 100)
{
flag = 100;
qs -= 100;
cout << "成功购买网子,耐久100!" << endl;
}
else cout << "金钱不足,无法购买!" << endl;
}
else if(a == "8")
{
if(qs >= 10)
{
flag = 10;
qs -= 10;
cout << "成功购买鱼竿,耐久10!" << endl;
}
else cout << "金钱不足,无法购买!" << endl;
}
else cout << "无效商品编号!" << endl;
}
else
{
cout << "输入错误,请重新选择!" << endl;
}
cout << "\n当前小动物数量:" << sum << " | 工具耐久:" << flag << " | 现有金钱:" << qs << endl;
}
return 0;
}