C语言实现 人生重生模拟器游戏

目录

实现一个简化版的人生重开模拟器

1.菜单函数

2.game函数

 3.幼年时期(even函数)

 4.壮年时期(Juvenile函数)


课余时间实现的小游戏

实现一个简化版的人生重开模拟器

1.菜单函数

void menu()
{
	printf("-------------------------------------\n");
	printf("-------------------------------------\n");
	printf("-	   欢迎来到人生重开模拟器		-\n");
	printf("-              1.play               -\n");
	printf("-              2.exit               -\n");
	printf("-------------------------------------\n");
	printf("-------------------------------------\n");

}

2.game函数

 (1)颜值,体质,智力,家境,总和不能超过20,每一项取值都是1-10之间

(2)对用户输入的内容进行校验(使用while循环) 

(3)生成角色性别(利用rand函数srand函数time函数生成一个随机数,就可以间接的随机生成一个性别了) 

(4)根据家境设置角色的出生点

void game()
{
	srand((unsigned int)time(NULL));//利用rand函数srand函数time函数生成一个随机数,就可以间接的随机的生成一个性别
	int sex = rand() % 2;
	//输入初始属性
	int face = 0;//颜值
	int strong = 0;//体质
	int iq = 0;//智力
	int home = 0;//家境
	int count = 1;
	//随机初始家境
	int point = rand() % 3;
	//夭折
	int a = 1;
	//输入初始属性
	while (count)
	{
		printf("请设置初始属性(可用点数总数为 20)->\n");
		printf("请输入颜值(1-10):");
		scanf("%d", &face);
		printf("请输入体质(1-10):");
		scanf("%d", &strong);
		printf("请输入智力(1-10):");
		scanf("%d", &iq);
		printf("请输入家境(1-10):");
		scanf("%d", &home);
		if (face > 10 || face < 0 || strong>10 || strong < 0 || iq>10 || iq < 0 || home>10 || home < 0)
		{
			printf("属性点输入有误,请重新输入\a\n");//它告诉终端或控制台输出一个警报信号(声音或者视觉)
			count++;
		}
		else if (face + strong + iq + home > 20)
		{
			printf("属性总和大于20,请重新输入\a\n");
			count++;
		}
		count--;
		if (strong == 0)
		{
			printf("体质过低,先天夭折\n");
			a = 0;
			break;
		}
		if (strong < 2)
		{
			if (point == 1)
			{
				printf("体质过低,先天夭折\n");
				a = 0;
				break;
			}
		}
		if (face < 2)
		{
			printf("你长的太丑,被父母抛弃,暴尸荒野\n");
			a = 0;
			break;
		}
		if (home == 0)
		{
			printf("你出生了\n");
			Sleep(1000);
			printf("你死了\n");
			a = 0;
			break;
		}
	}
	

	//判断是否先天夭折
	if (a)
	{
		printf("初始属性输入完毕!\n");
		printf("颜值:%d,体质:%d,智力:%d,家境:%d\n", face, strong, iq, home);

		//随机性别
		if (sex == 1)
		{
			printf("你是一个男孩\n");
		}
		else
		{
			printf("你是一个女孩\n");
		}
		//第一档
		if (home == 10)
		{
			printf("你出生在帝都,你的父母皆是高管\n");
			home += 3;
			iq += 1;
			face += 1;
		}
		//第二档
		else if (home <= 9 && home >= 7)
		{
			if (point == 1)
			{
				printf("你出生在大城市,你的父母是公务员\n");
				home += 1;
			}
			else if (point == 2)
			{
				printf("你出生在大城市,你的父母是高智商人才\n");
				iq += 2;
			}
			else
			{
				printf("你出生在大城市,你的父母是明星\n");
				face += 2;
			}
		}
		//第三档
		else if (home <= 6 && home >= 4)
		{
			if (point == 1)
			{
				printf("你出生在三线城市,你的父母是医生\n");
				strong += 1;
			}
			else if (point == 2)
			{
				printf("你出生在镇上,你的父母是老师\n");
				iq += 1;
			}
			else
			{
				printf("你出生在镇上,你的父母是个体户\n");
				home += 1;
			}
		}
		//第四档
		else
		{
			if (point == 1)
			{
				printf("你出生在农村,你的父母是辛苦劳作的农民\n");
				strong += 1;
				face -= 1;
			}
			else if (point == 2)
			{
				printf("你出生在农村,你的父母是无业游民\n");
				home -= 2;
			}
			else
			{
				printf("你出生在镇上,你的父母感情不和\n");
				strong -= 1;
				home -= 1;
			}
		}
		printf("颜值:%d,体质:%d,智力:%d,家境:%d\n", face, strong, iq, home);
		even(face, strong, iq, home, sex, point);

	}

}

\a:它告诉终端或控制台输出一个警报信号(声音或者视觉)

srand((unsigned int)time(NULL)):生成随机数

rand() % 3:生成0-2的随机数

 3.幼年时期(even函数)

先使用for循环,按照年龄,从1循环到10

针对每一年,都生成一个随机数(1-3)

利用while与switch

根据角色,心别,年龄,各种属性,触发各种事件,随机数会对事件的结果造成影响

这里的事件可能会对属性带来变化

//幼年时期
void even(int face, int strong, int iq, int home, int sex, int point)
{
	srand((unsigned int)time(NULL));
	int t = 0, o = 0, w = 0, r = 0, f = 0, v = 0, s = 0, e = 0, n = 0, g = 0;
	//10岁,循环10次
	int count = 10;
	int age = 1;
	int Cend = 1;//记录是否结束游戏

	while (count)
	{

		int a = rand() % 10;
		struct Event arr[10];
	again:
		switch (a + 1)
		{
		case 1:
			if (sex == 0 && home <= 3 && point == 1)
			{
				strcpy(arr[0].eve, "你的家里人重男轻女观念非常严重,你被遗弃了!\n游戏结束!");
				printf("%s\n", arr[0].eve);
				count = 1;
			}
			else
			{
				if (o == 0)

				{
					strcpy(arr[0].eve, "全球范围实现碳中和。");
					o++;
				}
				else
				{
					a = rand((unsigned int)time(NULL)) % 10;
					goto again;
				}
			}
			break;
		case 2:
			if (strong < 6 && point < 3)
			{
				if (home >= 5)
				{
					strcpy(arr[1].eve, "你生了一场病,在你的父母悉心照顾下,你康复了");
					strong += 1;
					home -= 1;
				}
				else
				{
					strcpy(arr[1].eve, "你生了一场病,你的父母没精力管你,你的身体状况更糟糕了");
					strong -= 1;
				}
			}
			else
			{
				if (w == 0)

				{
					strcpy(arr[1].eve, "火星建立永久性人类居住基地。");
					w++;
				}
				else
				{
					a = rand() % 10;
					goto again;
				}

			}
			break;
		case 3:
			if (face <= 4 && age >= 7)
			{
				if (iq > 5)
				{
					strcpy(arr[2].eve, "你长得太丑了,别的小朋友不喜欢你,你决定用学习填充自己");
				}
				else
				{
					if (sex == 1)
					{
						strcpy(arr[2].eve, "你长得太丑了,别的小朋友不喜欢你,你和别的小朋友经常打架!");
						strong += 1;
						iq -= 1;
					}
					else
					{
						strcpy(arr[2].eve, "你长得太丑了,别的小朋友不喜欢你,你进常被被别的小朋友欺负");
						strong -= 1;
					}
				}
			}
			else
			{
				if (r == 0)

				{
					strcpy(arr[2].eve, "全球范围内的无人驾驶汽车技术普及。");
					r++;
				}
				else
				{
					a = rand() % 10;
					goto again;
				}

			}
			break;
		case 4:
			if (iq < 5)
			{
				if (home >= 8 && age >= 6)
				{
					strcpy(arr[3].eve, "你看起来傻傻的,你的父母把你送到更好的学校学习。");
					iq += 1;
				}
				else if (home >= 4 && home <= 7)
				{
					if (sex == 1)
					{
						strcpy(arr[3].eve, "你看起来傻傻的,你的父母鼓励你多运动,争取成为运动员。");
						strong += 1;
					}
					else
					{
						strcpy(arr[3].eve, "你看起来傻傻的,你的父母鼓励你多打扮自己。");
						face += 1;
					}
				}
				else
				{
					strcpy(arr[3].eve, "你看起来傻傻的,你的父母为此经常吵架。");
					if (point == 1)
						strong -= 1;
					else if (point == 2)
						iq -= 1;
				}
			}
			else
			{
				if (f == 0)

				{
					strcpy(arr[3].eve, "人工智能与人类共同创造新文化。");
					home += 1;
					f++;
				}
				else
				{
					a = rand() % 10;
					goto again;
				}
			}
			break;
		case 5:
		{
			if (point == 1)
			{
				strcpy(arr[4].eve, "你健康成长,你看起来更结实了。");
				strong += 1;
			}
			else if (point == 2)
			{
				strcpy(arr[4].eve, "你健康成长,你看起来更好看了。");
				face += 1;
			}
			else
			{
				if (v == 0)

				{
					strcpy(arr[4].eve, "人类开始探索宇宙深处,与外星文明建立联系。");
					v++;
				}
				else
				{
					a = rand() % 10;
					goto again;
				}
			}
		}
		break;
		case 6:
			if (s == 0)
			{
				strcpy(arr[5].eve, "人类成功实现核聚变能源的商业化应用,彻底解决能源危机问题。");
				home += 1;
				s++;
			}
			else
			{
				a = rand() % 10;
				goto again;
			}
			break;
		case 7:
			if (e == 0)
			{
				strcpy(arr[6].eve, "虚拟实现技术发展到一个全新的高度,人们可以随时地沉浸到虚拟世界中。");
				strong -= 2;
				e++;
			}
			else
			{
				a = rand() % 10;
				goto again;
			}
			break;
		case 8:
			if (n == 0)
			{
				strcpy(arr[7].eve, "全球范围内的高速交通网络初步建成,人们可以在几小时内穿越地球。");
				n++;
			}
			else
			{
				a = rand() % 10;
				goto again;
			}
			break;
		case 9:
			if (g == 0)

			{
				strcpy(arr[8].eve, "高考取消英语这门科目。");
				iq += 1;
				g++;
			}
			else
			{
				a = rand() % 10;
				goto again;
			}
			break;
		case 10:
			if (t == 0)
			{
				strcpy(arr[9].eve, "全球实现无国界教育,世界各地的学生都能接受优质的教育。");
				iq += 1;
				t++;
			}
			else
			{
				a = rand() % 10;
				goto again;
			}
			break;
		}
		if (strong <= 0)
		{
			printf("你今年 %d 岁\n", age);
			if (point == 1)
			{
				printf("你染上了新冠病毒,没能抗住病毒的侵袭,你死了!\n");
				printf("游戏结束!\n");
				Cend = 0;
				break;
			}
			else if (point == 2)
			{
				printf("你得了白血病,不幸去世!\n");
				printf("游戏结束!\n");
				Cend = 0;

				break;
			}
			else
			{
				printf("你吃东西的时候不小心被呛死了!\n");
				printf("游戏结束!\n");
				Cend = 0;

				break;
			}
		}
		else if (iq <= 0)
		{
			printf("你今年 %d 岁\n", age);
			if (point == 1)
			{
				printf("你发高烧的时候,由于治疗不及时变成了一个智障!\n");
				printf("游戏结束!\n");
				Cend = 0;

				break;
			}
			else if (point == 2)
			{
				printf("你不小心喝了日本核污水变成了一个智障!\n");

				printf("游戏结束!\n");
				Cend = 0;
				break;
			}
			else
			{
				printf("由于酒精中毒,你变成了一个智障\n");
				printf("游戏结束!\n");
				Cend = 0;
				break;
			}
		}
		printf("---------------------------------------------------------------\n");
		printf("你今年 %d 岁了\n", age);
		printf("%s\n", arr[a].eve);
		printf("颜值:%d,体质:%d,智力:%d,家境:%d\n", face, strong, iq, home);
		printf("---------------------------------------------------------------\n");
		Sleep(1000);
		age++;
		count--;

	}
	//juvenile 少年
	if (Cend)
	{
		Juvenile(face, strong, iq, home, sex, point);
	}
		
}

 4.壮年时期(Juvenile函数)

利用while与switch

 创建a1-a9记录每一年发生的事件,使故事连贯

//壮年时期
void Juvenile(int face, int strong, int iq, int home, int sex, int point)
{
	int a1 = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0, a6 = 0, a7 = 0, a8 = 0, a9 = 0;
	int count = 8;
	int age = 20;
	int b = 0;
	
	//修为
	int Revision = 0;
	while (count)
	{
		//int b = rand() % 10;
		struct Je add[10];
		//随机生成0-2
		int random = rand() % 3;
		switch (b+1)
		{
		case 1:
			if (strong < 5 && iq < 5)
			{
				strcpy(add[0].eve1, "感染了丧尸病毒,你死了!\n");
				printf("%s\n", add[0].eve1);
				count = 1;
			}
			else if (face > 8)
			{
				strcpy(add[0].eve1, "你颜值太高了,遭人嫉妒,被陷害而死\n");
				printf("%s\n", add[0].eve1);
				count = 1;
			}
			else
			{
				strcpy(add[0].eve1, "你平安度过一年\n");
			}
			break;
		case 2:
			if (random==0)
			{
				strcpy(add[1].eve1, "地球灵气复苏,世界开启修仙时代\n");
				a1 = 1;
				strong += 1;
				Revision += 1;
			}
			else if (random==1)
			{
				strcpy(add[1].eve1, "你穿越到了一个修仙世界\n");
				a1 = 2;
				strong += 2;
				Revision += 2;
			}
			else
			{
				strcpy(add[1].eve1, "大概一年前你传送来到一个仿佛地狱的地方,天空上挂着一轮土色的太阳,且空气中弥漫着一种难以名状的气味\n");
				a1 = 3;
				strong -= 1;
			}
			break;
		case 3:
			if (a1 == 1)
			{
				strcpy(add[2].eve1, "国家开始寻找修仙天赋异禀的人,但这跟你并没有什么关系\n");

			}
			else if (a1 == 2)
			{
				strcpy(add[2].eve1,"想当年初临此界,内心的激动心喜无法言说,但却被族老判定为无法修炼的废材\n");
				strong -= 2;
			}
			else
			{
				strcpy(add[2].eve1, "一年时间,你大概对这个世界有所了解,这是一个由“神”掌控的世界,想要逃出去唯有跟紧‘那人’");
				iq += 2;
				a1 = 4;
			}
			break;
		case 4:
			if (random == 0&&a1 == 4)
			{
				strcpy(add[3].eve1, "一年时间让你对这个世界绝望,一度想自杀\n");
				Revision -= 1;
				a2 = 1;
			}
			else if (random == 1)
			{
				strcpy(add[3].eve1, "你意外得到一颗美颜神丹,令无数人羡慕于你\n");
				a2 = 2;
				Revision += 3;
			}
			else
			{
				strcpy(add[3].eve1, "你突然醒悟,拼命锻炼,一年时间让你的实力得到了一大提升\n");
				a2 = 3;
				Revision += 6;
			}
			break;
		case 5:
			if (a2 == 1)
			{
				strcpy(add[4].eve1, "在这种极端的状态下,你变的更强、更疯,也找到了自己解放全部人的路:成为神\n");
				iq += 5;
				strong += 5;
				face += 2;
				a3 = 1;
			}
			else if (random==1 && a2 == 2)
			{
				strcpy(add[4].eve1, "你颜值太高,遭人嫉妒,被陷害而死\n游戏结束");
				count = 1;
			}
			else if (a2 == 2)
			{
				strcpy(add[4].eve1, "这一年受到了许多人的帮助,不再是废材,实力一路突飞猛进\n");
				Revision += 10;
				strong += 7;
				a3 = 2;
			}
			else if(a1 == 1 || a1 == 2)
			{
				strcpy(add[4].eve1, "你觉醒了先天圣体,成为了新一代的天骄\n");
				Revision += 12;
				strong += 10;
				a3 = 3;
			}
			else
			{
				strcpy(add[4].eve1, "这一年的实力得到了显著提升,逐渐成为了“那人”的得力助手\n");
				strong += 5;
				iq += 1;
				a3 = 4;
			}
			break;
		case 6:
			if (a3 == 1)
			{
				strcpy(add[5].eve1, "你走的路无人能理解你,你注定是孤独的\n");
				iq += 5;
				strong += 5;
			}
			else if(a3 == 2)
			{
				if (a1 == 1 || a1 == 2)
				{
					strcpy(add[5].eve1, "经过你不懈的努力,你终于觉醒了自己的天赋,从此打遍天下无敌手\n");
					Revision += 20;
					strong += 10;
				}
				else
				{
					strcpy(add[5].eve1, "经过你不懈的努力,你带领众多人成立极道组织,对抗神明\n");
					iq += 5;
				}
			}
			else if (a3 == 3)
			{
				strcpy(add[5].eve1, "你天赋异禀,成为了修仙界显著的天才,但同时也给你带来了很多敌人\n");
				strong += 20;
				Revision += 30;
			}
			else
			{
				strcpy(add[5].eve1, "这一年你逐渐解开了这个世界的迷雾,人你看到出去的希望\n");
				iq += 2;
				strong += 2;
			}
			break;
		case 7:
			if (random == 0)
			{
				strcpy(add[6].eve1, "你找到了一生挚爱,被最爱的人陷害而死\n游戏结束");
				count = 1;
			}
			else if (random == 1)
			{
				strcpy(add[6].eve1, "你遇到了此生最强大的敌人,你死了\n游戏结束");
				a4 = 1;
			}
			else
			{
				strcpy(add[6].eve1, "你与你的爱人结婚了,这是幸福的一年\n");
				Revision += 10;
				strong -= 5;
				a4 = 2;
			}
		case 8:
			if (a1 == 1 || a1 == 2)
			{
				if (a4 == 1)
				{
					strcpy(add[7].eve1, "你重生了,这一世你要把你失去的全都拿回来\n");
					strong = 5;
					iq = 5;
					Revision = 0;
				}
				else
				{
					strcpy(add[5].eve1, "异族入侵,为抵抗,你创建无念阁\n");
				}
			}
			else
			{
				if (a4 == 1)
				{
					strcpy(add[7].eve1, "你重生了,原来这里无限轮回的\n");
					iq = 5;
					strong += 5;
				}
				else
				{
					strcpy(add[7].eve1, "你亲手杀死了自己的爱人,只有这样才能让你变得更加疯,为了成神,这是必要的一步\n");
					iq += 10;
					strong += 5;
				}
			}
		}
		printf("---------------------------------------------------------------\n");
		printf("你今年 %d 岁了\n", age);
		printf("%s\n", add[b].eve1);
		
		if (a1 == 1 || a1 == 2)
		{
			printf("颜值:%d,体质:%d,智力:%d,修为:%d,家境:%d\n", face, strong, iq, Revision, home);
		}
		else
		{
			printf("颜值:%d,体质:%d,智力:%d,家境:%d\n", face, strong, iq, home);
		}
		printf("---------------------------------------------------------------\n");
		Sleep(1500);
		age++;
		b++;
		count--;
	}
}

感谢观看,

  • 14
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 16
    评论
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

pzn)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值