利用c++编写一个养成类小游戏

利用c++编写一个养成类小游戏,第1张

根据b站up主“老九学堂”c++教程“小公主养成记”并结合所学编出一个小游戏:

目前仅结合了:数组、if语句、随机数、三目运算符、for循环、goto语句、设置输出宽度setw(a)、while语句、逻辑运算符等。

#include
using namespace std;
#include
#include
#include //setw()设置宽度要包含这个头文件

string xingzuo[12][2] =
{
	{"摩羯座","水瓶座"},{"水瓶座","双鱼座"},
	{"双鱼座","白羊座"},{"白羊座","金牛座"},
	{"金牛座","双子座"},{"双子座","巨蟹座"},
	{"巨蟹座","狮子座"},{"狮子座","处女座"},
	{"处女座","天秤座"},{"天秤座","天蝎座"},
	{"天蝎座","射手座"},{"射手座","摩羯座"}
};
int sz_weishu[12] = { 21,20,21,21,22,22,24,24,24,24,23,23 };//每个月划分不同星座的中间日期
int qingshang = 0;
int zhishang = 0;
int wugong = 0;
int money = 20;
string shuxing[4] = { "情商","智商","武功","金钱" };
int arr[4] = { qingshang,zhishang,wugong,money };

int main()
{
	//游戏背景
	cout << "故事发生在1878年,父亲捡了一个被丢弃在垃圾桶旁边的小女孩," <<
		"\n小女孩看起来只有3岁左右,父亲发现她的时候,小女孩在嚎啕大哭" <<
		"\n父亲刚好不孕不育,所以他决定将小女孩捡回家并把她养大" << endl;
	//1、输入父亲的信息
	string father_name;
	cout << "请输入父亲的名字:" << endl;
	cin >> father_name;
	//2、输入女儿信息(名字、生日)
	string daughter_name;
	int birthday_month;
	int birthday_day;
	cout << "请输入女儿的名字:" << endl;
	cin >> daughter_name;
	cout << "请输入女儿的生日 月:" << endl;
	cin >> birthday_month;
	while (birthday_month < 0 || birthday_month>12)
	{
		cout << "请输入正确的月" << endl;
		cin >> birthday_month;
	}
	cout << "请输入女儿的生日 日:" << endl;
	cin >> birthday_day;
	while (birthday_day < 0 || birthday_day>31)
	{
		cout << "请输入正确的日" << endl;
		cin >> birthday_day;
	}
	//3、根据女儿生日判断星座,并输出所有信息
	cout << "父亲的姓名为: " << father_name << endl;
	cout << "女儿的姓名为: " << daughter_name << endl;
	cout << "女儿的生日为 " << birthday_month << "月" << birthday_day <<"号 " << "\n女儿的星座为: "
		<< xingzuo[birthday_month - 1][birthday_day / sz_weishu[birthday_month - 1]] << endl;
	//4、根据星座给定不同的属性初值:【情商】【智商】【武功】【金钱】

	if (xingzuo[birthday_month - 1][birthday_day / sz_weishu[birthday_month - 1]] == "摩羯座")
	{
		arr[0] = 5;
		arr[1] = 1;
		arr[2] = 6;
	}
	else if (xingzuo[birthday_month - 1][birthday_day / sz_weishu[birthday_month - 1]] == "水瓶座")
	{
		arr[0] = 1;
		arr[1] = 1;
		arr[2] = 1;
	}
	else if (xingzuo[birthday_month - 1][birthday_day / sz_weishu[birthday_month - 1]] == "双鱼座")
	{
		arr[0] = 2;
		arr[1] = 2;
		arr[2] = 2;
	}
	else if (xingzuo[birthday_month - 1][birthday_day / sz_weishu[birthday_month - 1]] == "白羊座")
	{
		arr[0] = 3;
		arr[1] = 3;
		arr[2] = 3;
	}
	else if (xingzuo[birthday_month - 1][birthday_day / sz_weishu[birthday_month - 1]] == "金牛座")
	{
		arr[0] = 4;
		arr[1] = 4;
		arr[2] = 4;
	}
	else if (xingzuo[birthday_month - 1][birthday_day / sz_weishu[birthday_month - 1]] == "双子座")
	{
		arr[0] = 5;
		arr[1] = 5;
		arr[2] = 5;
	}
	else if (xingzuo[birthday_month - 1][birthday_day / sz_weishu[birthday_month - 1]] == "巨蟹座")
	{
		arr[0] = 6;
		arr[1] = 6;
		arr[2] = 6;
	}
	else if (xingzuo[birthday_month - 1][birthday_day / sz_weishu[birthday_month - 1]] == "狮子座")
	{
		arr[0] = 7;
		arr[1] = 7;
		arr[2] = 7;
	}
	else if (xingzuo[birthday_month - 1][birthday_day / sz_weishu[birthday_month - 1]] == "处女座")
	{
		arr[0] = 8;
		arr[1] = 8;
		arr[2] = 8;
	}
	else if (xingzuo[birthday_month - 1][birthday_day / sz_weishu[birthday_month - 1]] == "天秤座")
	{
		arr[0] = 9;
		arr[1] = 9;
		arr[2] = 9;
	}
	else if (xingzuo[birthday_month - 1][birthday_day / sz_weishu[birthday_month - 1]] == "天蝎座")
	{
		arr[0] = 10;
		arr[1] = 10;
		arr[2] = 10;
	}
	//游戏循环主体
	srand((unsigned int)time(NULL));
	cout << "7年过去了,小女孩慢慢长大了,到了该上学的年纪。但是这时爸爸不幸喝水呛死,"
		<< "\n只剩下小女孩孤苦伶仃一人生活,爸爸留下了10块钱"
		<< "\n这时小女孩不舒服,去看医生,医生告诉她:"
		<< "\n你患上了千年一遇的“小脑左部随机性螺旋翻转”,"
		<< "\n你最多只能再活  2  年,诶嘿,我很抱歉"
		<< "\n小女孩面临抉择,假如你是小女孩,你该如何抉择?" << endl;

	for (int year = 1885; year < 1888; year++)
	{
		for (int month = (year == 1885) ? 6 : 1; month <= 12; month++)
		{
			A:
			cout << "\n现在时间是" << year << "年" << month << "月。 \n你的选择是:"
				<< "\n1、上学 \n2、习武 \n3、打工\n4、查询自己能力" << endl;
			int choice = 0;
			cin >> choice;
			int zhishang_1 = rand() % 11;
			int wugong_1 = rand() % 11;
			int qingshang_1 = rand() % 11;
			int money_1 = rand() % 16;
			int jia_money = rand() % 31;
			if (choice == 1)
			{
				arr[1] += zhishang_1;
				arr[3] -= money_1;
				cout << "  一个月过去了,通过上学你的智商增加了" << zhishang_1 << endl;
				cout << "花费了 "< choice;
				if (choice == 3)
				{
					goto DAGONG;
				}
			}
		}
	}
	int max = 0;
	for (int i = 0; i < 3; i++)
	{
		if (arr[i] > max)
		{
			max = arr[i];
		}
	}
	//	int arr[4] = { qingshang,zhishang,wugong,money };
	string diwei[5] = { "女武神","女博士","富豪","企业高管","舞林盟主" };
	 if (max == arr[0])
	{
	cout << "你很有天赋,年纪轻轻就成了" << diwei[3] << endl;
	}
	 else if (max == arr[1])
	{
		cout << "你很有天赋,年纪轻轻就成了" << diwei[1] << endl;
	}
	 else if (max == arr[2])
	 {
		 cout << "你很有天赋,年纪轻轻就成了" << diwei[4] << endl;
	 }
	else if (max == arr[1] && arr[1] == arr[2])
	{
		cout << "你超有天赋,达到了世界之最" << diwei[0] << "!"
			<< "中华上下5000年仅有你一人达成如此成就,你可以复活你爹" << endl;
	}
	else if (max == arr[3])
	{
		cout << "你很有天赋,年纪轻轻就成了" << diwei[2] << endl;
	}

	cout << "游戏结束,欢迎您投胎再玩哟!" << endl;
	system("pause");
	return 0;
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/874815.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-13
下一篇 2022-05-13

发表评论

登录后才能评论

评论列表(0条)

保存