跳到正文

闲话

小学生做的游戏有多好?2.0

huangzhiyao约 66 分钟
原文
文章信息与版本

文章信息

发布
2026年5月12日
收录
2026年5月16日
更新
2026年10月8日
篇幅
约 66 分钟
获赞
1

版本

  1. v3当前
  2. v2
  3. v1

前记

大家好啊(反正我不好),几天前(怎么可能),我做了这个,现在,我终于兑现承诺,做完了2.0!!!!!

——良心作者huangzhiyao

再感谢D老师
给我关注吧,必回关

源程序

蒟蒻源代码
C++
#include<cstdio>
#include<windows.h>
#include<conio.h>
#include<string>
#include<cstdlib>
#include<random>
#include<chrono>
#include<vector>
#include<cmath>
#include <algorithm>
using namespace std;
void Slowsay(const string& s){
	int l=s.size();
	for(int i=0;i<l;){
		int len=1;
        unsigned char c=s[i];
        if(c>=0xF0) len=4;
        else if(c>=0xE0) len=3;
        else if(c>=0xC0) len=2;
        printf("%.*s",len,&s[i]);
        fflush(stdout);
        i+=len;
        Sleep(1);
	}
	return;
}
void wait(){
	Slowsay("按任意键继续...");
	_getch();
	system("cls");
}
int enter(char l,char r){
	char c;
	c=_getch();
	while(c<l||c>r){
		Slowsay("未知输入!\n");
		c=_getch();
	}
	return c-48;
}
int getint(int l,int r){
	int f;
	scanf("%d",&f);
	while(f<l||r<f){
		Slowsay("未知输入!\n");
		scanf("%d",&f);
	}
	return f;
}

//教师模拟器 Teacher Simulator
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string Name_database[100]={"double_2","alpha7","betaMax","cool_cat","dragon42","echo_1","falconX","gamma99","hero_123","ice_cream",
                           "joker_8","king_pin","lunar_22","matrix3","neo_01","omega_77","phoenix0","quantum9","rocket_5","shadow_11",
                           "titan_4","ultra_v","vector9","wolf_666","xenon_7","yellow6","zebra_2","astro_99","blaze_f","comet_8a",
                           "dark_04","eagle_1","frost_12","ghost_3","hyper_x","iron_man","jade_77","knight9","light_8","moon_22",
                           "nebula7","orion_5","pirate3","quake_1","raven_8","storm_6","thunder9","unity_2","viper_4","whale_0",
                           "xray_33","yeti_6","zenith7","atomic8","binary2","cobalt3","delta_7","ember_1","frosty5","glitch_9",
                           "hunter2","inferno","jolt_4","krypto1","laser_5","magnet6","nova_01","onyx_22","pixel_7","quasar8",
                           "ranger1","sigma_9","turbo_2","umbrella","vortex5","warp_99","xenith3","yonder7","zipper8","archon1",
                           "blitz_3","cipher9","drift_2","enigma0","flare_7","gadget4","havoc_5","impact3","jazz_1","karma_6",
                           "legend2","mirage8","ninja_0","outlaw7","phantom","quest_9","ripple5","saber_2","trick_4","uproar8"};
string Grade[9]={"D","C","B","A","S","SS","SSS","SSS+","QP"};
string School_name[180]={"未录取","未录取","未录取","未录取","未录取",
                         "未录取","未录取","未录取","未录取","未录取",
                         "未录取","未录取","未录取","未录取","未录取",
                         "未录取","未录取","未录取","未录取","未录取",
                         "未录取","未录取","未录取","未录取","未录取",
                         "未录取","未录取","未录取","未录取","未录取",
                         "未录取","未录取","未录取","未录取","未录取",
                         "未录取","未录取","未录取","未录取","未录取",
                         "未录取","未录取","未录取","未录取","未录取",
                         "未录取","未录取","未录取","未录取","未录取",
                         "深圳大学","深圳大学","浙江工业大学","浙江工业大学","南京工业大学",
                         "南京工业大学","燕山大学","燕山大学","扬州大学","江苏大学",
                         "福建师范大学","青岛大学","武汉科技大学","湖北大学","西安理工大学",
                         "上海理工大学","西安建筑科技大学","昆明理工大学","长春理工大学","山东科技大学",
                         "成都理工大学","东北财经大学","杭州电子科技大学","广东工业大学","浙江师范大学",
                         "上海师范大学","山东师范大学","长沙理工大学","西安科技大学","北方工业大学",
                         "首都经济贸易大学","南京邮电大学","重庆邮电大学","中国民航大学","西南政法大学",
                         "华东政法大学","河北大学","河南大学","山西大学","湘潭大学",
                         "南京信息工程大学","成都信息工程大学","天津工业大学","浙江理工大学","西安邮电大学",
                         "重庆交通大学","广州大学","济南大学","安徽师范大学","西北师范大学",
                         "兰州交通大学","东北石油大学","华侨大学","集美大学","北京邮电大学",
                         "对外经济贸易大学","北京科技大学","南京航空航天大学","上海财经大学","中央财经大学",
                         "北京交通大学","南京理工大学","西安电子科技大学","中国政法大学","华东理工大学",
                         "北京工业大学","天津医科大学","西南交通大学","哈尔滨工程大学","武汉理工大学",
                         "中国传媒大学","北京化工大学","中南财经政法大学","河海大学","东华大学",
                         "华中师范大学","苏州大学","暨南大学","西南财经大学","南京师范大学",
                         "华南师范大学","中国地质大学","西北大学","东北师范大学","北京林业大学",
                         "中国石油大学","合肥工业大学","南昌大学","郑州大学","湖南师范大学",
                         "云南大学","中国人民大学","北京航空航天大学","同济大学","北京师范大学",
                         "武汉大学","华中科技大学","南开大学","中山大学","东南大学",
                         "天津大学","厦门大学","四川大学","山东大学","西北工业大学",
                         "电子科技大学","华南理工大学","吉林大学","湖南大学","中南大学",
                         "重庆大学","大连理工大学","兰州大学","华东师范大学","中国农业大学",
                         "东北大学","中国海洋大学","中央民族大学","西北农林科技大学","哈尔滨工业大学",
                         "西安交通大学","南京大学","浙江大学","中国科学技术大学","上海交通大学",
                         "复旦大学","北京大学","清华大学","清华大学","清华大学"};
int score[9]={0,60,85,95,105,115,125,135,149};
int stamina,lastweek,money;
struct Mate{
	string name;
	int Chinese_score=0;
	string Chinese_grade;
	int Maths_score=0;
	string Maths_grade;
	int English_score=0;
	string English_grade;
	int Physics_score=0;
	string Physics_grade;
	int Chemistry_score=0;
	string Chemistry_grade;
	int Biology_score=0;
	string Biology_grade;
	int CEE_score=0;
	string CEE_grade;
}mate[6];
void Class_Initialization(){
	vector<string> namePool;
    for(int i=0;i<100;i++) namePool.push_back(Name_database[i]);
	for(int i=0;i<6;i++){
		uniform_int_distribution<int> namedist(0,namePool.size()-1);
		int idx=namedist(rng);
		mate[i].name=namePool[idx];
		namePool.erase(namePool.begin()+idx);
		uniform_int_distribution<int> scoredist(5,40);
		mate[i].Chinese_score=scoredist(rng);
		mate[i].Maths_score=scoredist(rng);
		mate[i].English_score=scoredist(rng);
		mate[i].Physics_score=scoredist(rng);
		mate[i].Chemistry_score=scoredist(rng);
		mate[i].Biology_score=scoredist(rng);
	}
	return;
}
void Outputclass(){
	for(int i=0;i<6;i++){
		string out="学生"+mate[i].name+"\n";
    	out+="语文:"+mate[i].Chinese_grade+"\n";
    	out+="数学:"+mate[i].Maths_grade+"\n";
    	out+="英语:"+mate[i].English_grade+"\n";
    	out+="物理:"+mate[i].Physics_grade+"\n";
    	out+="化学:"+mate[i].Chemistry_grade+"\n";
    	out+="生物:"+mate[i].Biology_grade+"\n";
    	out+="\n";
    	Slowsay(out);
	}
	return;
}
void Resetgrade(){
	for(int i=0;i<6;i++){
		for(int j=0;j<=8;j++){
			if(mate[i].Chinese_score>=score[j]) mate[i].Chinese_grade=Grade[j];
		}
		for(int j=0;j<=8;j++){
			if(mate[i].Maths_score>=score[j]) mate[i].Maths_grade=Grade[j];
		}
		for(int j=0;j<=8;j++){
			if(mate[i].English_score>=score[j]) mate[i].English_grade=Grade[j];
		}
		for(int j=0;j<=8;j++){
			if(mate[i].Physics_score>=score[j]) mate[i].Physics_grade=Grade[j];
		}
		for(int j=0;j<=8;j++){
			if(mate[i].Chemistry_score>=score[j]) mate[i].Chemistry_grade=Grade[j];
		}
		for(int j=0;j<=8;j++){
			if(mate[i].Biology_score>=score[j]) mate[i].Biology_grade=Grade[j];
		}
	}
	return;
}
int CalcBonus(int curScore,int maxBonus){
    if (curScore>=150) return 0;
    int diff=150-curScore;
    int bonus=round(maxBonus*diff/150.0);
    bonus+=uniform_int_distribution<int>(-2,2)(rng);
    bonus=(std::max)(0,bonus);
    bonus=(std::min)(bonus,(150-curScore));
    return bonus;
}
int displayWidth(const string& s){
    int width=0;
    for(unsigned char c:s){
        if(c<0x80) width+=1;
        else width+=2;
    }
    return width;
}
string padRight(const string& s, int totalWidth){
    int cur=displayWidth(s);
    if(cur>=totalWidth) return s;
    return s+string(totalWidth-cur,' ');
}
void Outputresults(){
	uniform_int_distribution<int> dist(-5,5);
    Slowsay("学生姓名    语文  数学  英语  物理  化学  生物\n");
    for(int i=0;i<6;i++){
        string line;
        line+=padRight(mate[i].name,12);
        line+=padRight(to_string((std::min)(mate[i].Chinese_score+dist(rng),150)),6);
        line+=padRight(to_string((std::min)(mate[i].Maths_score+dist(rng),150)),6);
        line+=padRight(to_string((std::min)(mate[i].English_score+dist(rng),150)),6);
        line+=padRight(to_string((std::min)(mate[i].Physics_score+dist(rng),150)),6);
        line+=padRight(to_string((std::min)(mate[i].Chemistry_score+dist(rng),150)),6);
        line+=padRight(to_string((std::min)(mate[i].Biology_score+dist(rng),150)),6);
        Slowsay(line);
        Slowsay("\n");
    }
}
void CEE(){
	Slowsay("学生姓名    语文  数学  英语  物理  化学  生物  总分\n");
	for(int i=0;i<6;i++){
		int CEEscore[6];
		string line;
		uniform_int_distribution<int> dist(-5,5);
		CEEscore[0]=(std::min)(mate[i].Chinese_score+dist(rng),150);
		CEEscore[1]=(std::min)(mate[i].Maths_score+dist(rng),150);
		CEEscore[2]=(std::min)(mate[i].English_score+dist(rng),150);
		CEEscore[3]=(std::min)(mate[i].Physics_score+dist(rng),150);
		CEEscore[4]=(std::min)(mate[i].Chemistry_score+dist(rng),150);
		CEEscore[5]=(std::min)(mate[i].Biology_score+dist(rng),150);
		int sum=0;
		for(int j=0;j<6;j++) sum+=CEEscore[j];
		int idx=sum/5;
		if(idx<0) idx=0;
		if(idx>179) idx=179;
		mate[i].CEE_grade=School_name[idx];
		mate[i].CEE_score=sum;
        line+=padRight(mate[i].name,12);
        line+=padRight(to_string(CEEscore[0]),6);
        line+=padRight(to_string(CEEscore[1]),6);
        line+=padRight(to_string(CEEscore[2]),6);
        line+=padRight(to_string(CEEscore[3]),6);
        line+=padRight(to_string(CEEscore[4]),6);
        line+=padRight(to_string(CEEscore[5]),6);
        line+=to_string(CEEscore[0]+CEEscore[1]+CEEscore[2]+CEEscore[3]+CEEscore[4]+CEEscore[5]);
        line+="/900";
        Slowsay(line+'\n');
	}
}
void Teacher_Simulator(){
	Slowsay("欢迎来到教师模拟器\n\n");
	wait();
	while(true){
		Class_Initialization();
		Resetgrade();
		lastweek=10,money=1000;
		while(lastweek!=0){
			money+=1000;
			stamina=3;
			bool weekEended=false;
			do{
				system("cls");
				string out;
				out="距离高考还有 ";
				out+=to_string(lastweek);
				out+=" 周\n";
				out+="您的体力:";
				out+=to_string(stamina);
				out+="/3\n您的班费:";
				out+=to_string(money);
				out+="\n";
				Slowsay(out);
				Slowsay("您的班级:\n\n");
				Outputclass();
				Slowsay("请选择\n");
				Slowsay("1.自习:消耗一点体力,完成小量任务\n");
				Slowsay("2.课堂测:消耗一点体力,200班费,完成中量任务\n");
				Slowsay("3.试卷:消耗两点体力,500班费,完成大量任务\n");
				Slowsay("4.模拟测:消耗三点体力,1000班费,完成全部科目\n");
				Slowsay("5.结束本周\n");
				int num=enter('1','5');
				switch(num){
					case 1:{
						if(stamina<1){
							Slowsay("体力不足,请重输\n");
							wait();
							break;
						}else{
							stamina-=1;
							Slowsay("请选择\n");
							Slowsay("1.语英自习\n");
							Slowsay("2.数物自习\n");
							Slowsay("3.化生自习\n");
							char chn=_getch();
							while(chn<'1'||chn>'3'){
								Slowsay("未知输入!\n");
								chn=_getch();
							}
							int numn=chn-48;
							switch(numn){
								case 1:
									for(int i=0;i<6;i++){
										mate[i].Chinese_score+=CalcBonus(mate[i].Chinese_score,10);
										mate[i].English_score+=CalcBonus(mate[i].English_score,10);
									}
									break;
								case 2:
									for(int i=0;i<6;i++){
										mate[i].Maths_score+=CalcBonus(mate[i].Maths_score,10);
										mate[i].Physics_score+=CalcBonus(mate[i].Physics_score,10);
									}
									break;
								case 3:
									for(int i=0;i<6;i++){
										mate[i].Chemistry_score+=CalcBonus(mate[i].Chemistry_score,10);
										mate[i].Biology_score+=CalcBonus(mate[i].Biology_score,10);
									}
									break;
							}
						}
						wait();
						break;
					}
					case 2:{
						if(stamina<1){
							Slowsay("体力不足,请重输\n");
							wait();
							break;
						}else if(money<200){
							Slowsay("班费不足,请重输\n");
							wait();
							break;
						}else{
							stamina-=1;
							money-=200;
							Slowsay("请选择\n");
							Slowsay("1.语英小测\n");
							Slowsay("2.数物小测\n");
							Slowsay("3.化生小测\n");
							char chn=_getch();
							while(chn<'1'||chn>'3'){
								Slowsay("未知输入!\n");
								chn=_getch();
							}
							int numn=chn-48;
							switch(numn){
								case 1:
									for(int i=0;i<6;i++){
										mate[i].Chinese_score+=CalcBonus(mate[i].Chinese_score,15);
										mate[i].English_score+=CalcBonus(mate[i].English_score,15);
									}
									break;
								case 2:
									for(int i=0;i<6;i++){
										mate[i].Maths_score+=CalcBonus(mate[i].Maths_score,15);
										mate[i].Physics_score+=CalcBonus(mate[i].Physics_score,15);
									}
									break;
								case 3:
									for(int i=0;i<6;i++){
										mate[i].Chemistry_score+=CalcBonus(mate[i].Chemistry_score,15);
										mate[i].Biology_score+=CalcBonus(mate[i].Biology_score,15);
									}
									break;
							}
						}
						wait();
						break;
					}
					case 3:{
						if(stamina<2){
							Slowsay("体力不足,请重输\n");
							wait();
							break;
						}else if(money<500){
							Slowsay("班费不足,请重输\n");
							wait();
							break;
						}else{
							stamina-=2;
							money-=500;
							Slowsay("请选择\n");
							Slowsay("1.语文大考试\n");
							Slowsay("2.数学大考试\n");
							Slowsay("3.英语大考试\n");
							Slowsay("4.物理大考试\n");
							Slowsay("5.化学大考试\n");
							Slowsay("6.生物大考试\n");
							char chn=_getch();
							while(chn<'1'||chn>'6'){
								Slowsay("未知输入!\n");
								chn=_getch();
							}
							int numn=chn-48;
							switch(numn){
								case 1:
									for(int i=0;i<6;i++){
										mate[i].Chinese_score+=CalcBonus(mate[i].Chinese_score,30);
									}
									break;
								case 2:
									for(int i=0;i<6;i++){
										mate[i].Maths_score+=CalcBonus(mate[i].Maths_score,30);
									}
									break;
								case 3:
									for(int i=0;i<6;i++){
										mate[i].English_score+=CalcBonus(mate[i].English_score,30);
									}
									break;
								case 4:
									for(int i=0;i<6;i++){
										mate[i].Physics_score+=CalcBonus(mate[i].Physics_score,30);
									}
									break;
								case 5:
									for(int i=0;i<6;i++){
										mate[i].Chemistry_score+=CalcBonus(mate[i].Chemistry_score,30);
									}
									break;
								case 6:
									for(int i=0;i<6;i++){
										mate[i].Biology_score+=CalcBonus(mate[i].Biology_score,30);
									}
									break;
								}
						}
						wait();
						break;
					}
					case 4:{
						if(stamina<3){
							Slowsay("体力不足,请重输\n");
							wait();
							break;
						}else if(money<1000){
							Slowsay("班费不足,请重输\n");
							wait();
							break;
						}else{
							stamina-=3;
							money-=1000;
							Outputresults();
							for(int i=0;i<6;i++){
								mate[i].Chinese_score+=CalcBonus(mate[i].Chinese_score,30);
								mate[i].Maths_score+=CalcBonus(mate[i].Maths_score,30);
								mate[i].English_score+=CalcBonus(mate[i].English_score,30);
								mate[i].Physics_score+=CalcBonus(mate[i].Physics_score,30);
								mate[i].Chemistry_score+=CalcBonus(mate[i].Chemistry_score,30);
								mate[i].Biology_score+=CalcBonus(mate[i].Biology_score,30);
							}
							wait();
							break;
						}
					}
					case 5:{
						lastweek--;
						weekEended=true;
						Slowsay("本周结束。\n");
						wait();
						break;
					}
				}
				Resetgrade();
			}while(!weekEended);
		}
		Slowsay("高考开始!\n\n");
		wait();
		CEE();
		int num_C9=0,num_985=0,num_211=0,num_no211=0;
		for(int i=0;i<6;i++){
			string s="";
			s=mate[i].name;
			s+="的学校:";
			s+=mate[i].CEE_grade;
			s+='\n';
			Slowsay(s);
			if(mate[i].CEE_score<249);
			else if(mate[i].CEE_score<599) num_no211++;
			else if(mate[i].CEE_score<749) num_211++;
			else if(mate[i].CEE_score<849) num_985++;
			else num_C9++;
		}
		if(num_C9==6) Slowsay("恭喜你,全员C9!\n");
		else if(num_C9+num_985==6) Slowsay("恭喜你,全员985!\n");
		else if(num_C9+num_985+num_211==6) Slowsay("恭喜你,全员211!\n");
		else if(num_C9+num_985+num_211+num_no211==6) Slowsay("恭喜你,全员上岸!\n");
		wait();
		Slowsay("按R再带一届学生!\n");
		char chh=_getch();
		if(chh!='R'&&chh!='r') break;
	}
	Slowsay("感谢游玩!!!\n");
	wait();
	return;
}

//数字炸弹之就要踩雷版 Digital Bomb: About to Step on a Mine Edition
void Digital_Bomb__About_to_Step_on_a_Mine_Edition(){
	Slowsay("欢迎游玩数字炸弹之就要踩雷版\n");
	Slowsay("温馨提示:“a~b”指的是[a,b],也就是a到b的一个数字(包括a和b)\n");
	wait();
	char chs;
	do{
		Slowsay("请选择难度:\n");
		Slowsay("1.简单\n");
		Slowsay("2.普通\n");
		Slowsay("3.困难\n");
		int level=enter('1','3');
		wait();
		switch(level){
			case 1:{
				uniform_int_distribution<int> dist(1,100);
				int left=1,right=100,ans=dist(rng),score=1;
				while(true){
					string s="请在";
					s+=to_string(left);
					s+="~";
					s+=to_string(right);
					s+="中选择一个数字:";
					Slowsay(s);
					int w=getint(left,right);
					if(w==ans){
						string ss="你用了";
						ss+=to_string(score);
						ss+="次,就完成了这个挑战";
						if(score<=6) ss+="!\n太厉害了!佩服佩服!\n";
						else if(score<=10) ss+="。\n还要加油哦!\n";
						else ss+="。\n再试试吧。\n";
						Slowsay(ss);
						break;
					}
					else if(w<ans){
						Slowsay("太小了,再试试!\n");
						left=w+1;
					}
					else{
						Slowsay("太大了,再试试!\n");
						right=w-1;
					}
					score++;
					wait();
				}
				break;
			}
			case 2:{
				uniform_int_distribution<int> dist(1,1000);
				int left=1,right=1000,ans=dist(rng),score=1;
				while(true){
					string s="请在";
					s+=to_string(left);
					s+="~";
					s+=to_string(right);
					s+="中选择一个数字:";
					Slowsay(s);
					int w=getint(left,right);
					if(w==ans){
						string ss="你用了";
						ss+=to_string(score);
						ss+="次,就完成了这个挑战";
						if(score<=8) ss+="!\n太厉害了!佩服佩服!\n";
						else if(score<=12) ss+="。\n还要加油哦!\n";
						else ss+="。\n再试试吧。\n";
						Slowsay(ss);
						break;
					}
					else if(w<ans){
						Slowsay("太小了,再试试!\n");
						left=w+1;
					}
					else{
						Slowsay("太大了,再试试!\n");
						right=w-1;
					}
					score++;
					wait();
				}
				break;
			}
			case 3:{
				uniform_int_distribution<int> dist(1,10000);
				int left=1,right=10000,ans=dist(rng),score=1;
				while(true){
					string s="请在";
					s+=to_string(left);
					s+="~";
					s+=to_string(right);
					s+="中选择一个数字:";
					Slowsay(s);
					int w=getint(left,right);
					if(w==ans){
						string ss="你用了";
						ss+=to_string(score);
						ss+="次,就完成了这个挑战";
						if(score<=10) ss+="!\n太厉害了!佩服佩服!\n";
						else if(score<=15) ss+="。\n还要加油哦!\n";
						else ss+="。\n再试试吧。\n";
						Slowsay(ss);
						break;
					}
					else if(w<ans){
						Slowsay("太小了,再试试!\n");
						left=w+1;
					}
					else{
						Slowsay("太大了,再试试!\n");
						right=w-1;
					}
					score++;
					wait();
				}
				break;
			}
		}
		Slowsay("按R继续\n");
		chs=_getch();
	}while(chs=='r'||chs=='R');
	return;
}

//闪电反应 Lightning Reflex
void Lightning_Reflex(){
	Slowsay("欢迎来到闪电反应测试!\n");
	Slowsay("看到提示后立即按空格键,别提前抢跑哦~\n");
	Slowsay("还有特性:不要按两次空格!\n");
	wait();
	char ch;
	do{
		system("cls");
		Slowsay("准备...\n");
		uniform_int_distribution<int> delayDist(1000,7000);
		int delay=delayDist(rng);
		Sleep(delay);
		if(_kbhit()){
			ch=_getch();
			Slowsay("别急!还没让你按呢!\n");
			wait();
			continue;
		}
		printf("按空格键!\n");
		DWORD start=GetTickCount();
		ch=_getch();
		DWORD end=GetTickCount();
		if(ch!=' '){
			Slowsay("按错了键!请按空格键而不是其他键~\n");
			wait();
			continue;
		}
		DWORD reaction=end-start;
		string result="你的反应时间:"+to_string(reaction)+" 毫秒\n";
		if(reaction<200) result+="闪电般的速度!\n";
		else if(reaction<500) result+="优秀!很快哦!\n";
		else if(reaction<1000) result+="一般般,再练练吧。\n";
		else result+="太慢了,你睡着了吗?\n";
		Slowsay(result);
		Slowsay("按 R 再测一次,其他键退出。\n");
		ch=_getch();
	}while(ch=='r'||ch=='R');
	Slowsay("感谢游玩,再见!\n");
	wait();
}

//记忆大师 Memory Master
void Memory_Master(){
	Slowsay("欢迎来到记忆大师!\n");
	Slowsay("我会给你一串数字,3秒后消失,你能记住吗?\n");
	wait();
	char ch;
	do{
		system("cls");
		int len=4;
		int round=0;
		while(true){
			uniform_int_distribution<int> digDist(0,9);
			string target="";
			for(int i=0;i<len;i++) target+=to_string(digDist(rng));
			Slowsay("第"+to_string(round+1)+"轮,数字长度:"+to_string(len)+"\n");
			printf("请看这串数字:%s\n",target.c_str());
			Sleep(1000);
			system("cls");
			Slowsay("请输入你记得的数字(连续输入,无空格):\n");
			string input="";
			char c;
			while(true){
				c=_getch();
				if(c=='\r'||c=='\n') break;
				if(c=='\b'){
					if(!input.empty()){
						input.pop_back();
						printf("\b \b");
					}
					continue;
				}
				if(c>='0'&&c<='9'){
					input+=c;
					printf("*");
				}
			}
			printf("\n");
			if(input==target){
				Slowsay("完全正确!\n");
				len++;
				round++;
				wait();
			}else{
				Slowsay("错误!这轮的数字是:"+target+"\n");
				Slowsay("你输入的是:"+input+"\n");
				break;
			}
		}
		string over="游戏结束,你一共通过了"+to_string(round)+"轮。\n";
		if(round>=15) over+="绝世天才!\n";
		else if(round>=10) over+="记忆力很强!\n";
		else if(round>=6) over+="还不错,继续加油。\n";
		else if(round>=3) over+="再练练吧。\n";
		else over+="你刚才走神了吧?\n";
		Slowsay(over);
		Slowsay("按 R 再测一次,其他键退出。\n");
		ch=_getch();
	}while(ch=='r'||ch=='R');
	Slowsay("感谢游玩,再见!\n");
	wait();
}

int main(){
	SetConsoleOutputCP(65001);
	SetConsoleCP(65001);
	Slowsay("欢迎游玩小游戏合集!\n");
	Slowsay("良心作者:黄智垚\n洛谷账号:huangzhiyao\n\n");
	Slowsay("史上最温馨的提示:多位数一定要输入数字,不然会有特性。\n");
	Slowsay("对,是特性,而不是Bug。\n");
	wait();
	Slowsay("请选择颜色:\n");
	Slowsay("1.璀璨星河(黑底亮白字)\n");
	Slowsay("2.墨韵白笺(亮白底黑字)\n");
	Slowsay("3.翡翠金辉(深绿底亮黄字)\n");
	Slowsay("4.极客矩阵(黑底亮绿字)\n");
	Slowsay("5.海洋之心(深蓝底亮白字)\n");
	Slowsay("6.冰湖晨曦(浅青底亮白字)\n");
	Slowsay("7.赤焰星芒(深红底亮白字)\n");
	Slowsay("8.青空之镜(黑底亮青字)\n");
	Slowsay("9.月下霜白(黑底亮灰字)\n");
	int f=enter('1','9');
	switch(f){
		case 1:{
			system("color 0F");
			break;
		}
		case 2:{
			system("color F0");
			break;
		}
		case 3:{
			system("color 2E");
			break;
		}
		case 4:{
			system("color 0A");
			break;
		}
		case 5:{
			system("color 1F");
			break;
		}
		case 6:{
			system("color 3F");
			break;
		}
		case 7:{
			system("color 4F");
			break;
		}
		case 8:{
			system("color 0B");
			break;
		}
		case 9:{
			system("color 07");
			break;
		}
	}
	wait();
	Slowsay("请选择游戏:\n");
	Slowsay("1.教师模拟器\n");
	Slowsay("2.数字炸弹之就要踩雷版\n");
	Slowsay("3.闪电反应\n");
	Slowsay("4.记忆大师\n");
	int num=enter('1','4');
	switch(num){
		case 1:{
			wait();
			Teacher_Simulator();
			break;
		}
		case 2:{
			wait();
			Digital_Bomb__About_to_Step_on_a_Mine_Edition();
			break;
		}
		case 3:{
			wait();
			Lightning_Reflex();
			break;
		}
		case 4:{
			wait();
			Memory_Master();
			break;
		}
	}
	Slowsay("感谢游玩!再见。");
	return 0;
}

讲解

1.开头

详情
a.头文件

#include<cstdio>用于提供 C 风格的输入输出函数(如 printf、scanf、getchar、putchar 等)。

#include<windows.h>用于提供 Windows API 函数、宏、类型和常量的声明,用于操作窗口、进程、线程、文件、控制台、注册表、GDI 等底层系统功能。

#include<conio.h>用于提供控制台无缓冲输入(如 _getch()、_kbhit())和屏幕操作(如 clrscr()、gotoxy())等非标准 DOS/Windows 函数。

#include<string>用于提供 C++ 标准库中的 std::string 类及相关的字符串操作函数。

#include<cstdlib>用于提供 C 标准库中的通用工具函数,包括 malloc、free、system、rand、atoi、exit 等。

#include<random>用于提供 C++11 起的高质量随机数生成器(如 mt19937)和统计分布(如 uniform_int_distribution)。

#include<chrono>用于提供 C++11 中的时间库,用于高精度计时、时间点与时长计算(如 steady_clock、duration)。

#include<vector>用于提供 C++ 标准库中的动态数组容器 std::vector,支持自动扩容、随机访问和高效尾部操作。

#include<cmath>用于提供 C++ 中的数学函数,如 sin、sqrt、pow、fabs 等。

#include<algorithm>用于提供 C++ 标准库中的大量泛型算法,如排序、查找、归并、堆操作等。

b.函数Slowsay
C++
void Slowsay(const string& s){
	int l=s.size();
	for(int i=0;i<l;){
		int len=1;
        unsigned char c=s[i];
        if(c>=0xF0) len=4;
        else if(c>=0xE0) len=3;
        else if(c>=0xC0) len=2;
        printf("%.*s",len,&s[i]);
        fflush(stdout);
        i+=len;
        Sleep(1);
	}
	return;
}

先读入一个字符串s
然后计算长度l
接下来输出

遍历 UTF-8 字符串时,先读第一个字节,根据该字节决定需要连续读取几个字节才能组成一个完整的 Unicode 字符。注意 0xC0 和 0xC1 是无效的 UTF-8 起始字节(它们本应表示 2 字节但实际码位只有 1 字节),严谨应用应额外排除。

然后输出
每输出一个字符
等一秒
就可以完成慢慢输出

c.函数wait
C++
void wait(){
	Slowsay("按任意键继续...");
	_getch();
	system("cls");
}

应该不用说什么。。。。。。说点吧
_getch()是等待按下一个字符
system("cls");是清空黑框中的内容

为什么不用system("pause");,是因为它是英文。。。。。。

d.函数enter
C++
int enter(char l,char r){
	char c;
	c=_getch();
	while(c<l||c>r){
		Slowsay("未知输入!\n");
		c=_getch();
	}
	return c-48;
}

读入字符l,r
再等待输入一个字符
如果不在l,r间
不断重输
最后返还一位数字

e.函数getint
C++
int getint(int l,int r){
	int f;
	scanf("%d",&f);
	while(f<l||r<f){
		Slowsay("未知输入!\n");
		scanf("%d",&f);
	}
	return f;
}

和enter的差别只有输入是多位数字

f.随机数rng定义

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());是基于梅森旋转算法(Mersenne Twister)的伪随机数生成器,并利用高精度时间来为它设置一个随机的“种子”。

部分含义
mt19937标准的 32 位梅森旋转随机数引擎,周期为219937−12^{19937}-1,是目前最常用的伪随机数生成器之一
rng随机数生成器的对象名,可以换成你喜欢的名字。
chrono::steady_clock::now()获取当前的单调时间点,该时钟不受系统时间调整的影响,适合用于测量时间间隔或生成种子。
.time_since_epoch().count()返回从时钟纪元(epoch)到当前时刻的计数值,这个值的单位由实现决定(可能是纳秒、微秒等)。

2.main

详情
a.UTF-8标签页
C++
SetConsoleOutputCP(65001);//设置控制台输出的代码页为 65001(UTF-8)
SetConsoleCP(65001);//设置控制台输入的代码页为 65001(UTF-8)

这两行代码专门用于输出中文会输出正常的内容

如果不用这两行代码,输出你好,会变成浣犲ソ 输出今天天气不错,你觉得呢?,会变成浠婂ぉ澶╂皵涓嶉敊锛屼綘瑙夊緱鍛紵

所以,加上这两行代码就没事了

b.开局输出内容
C++
    Slowsay("欢迎游玩小游戏合集!\n");
	Slowsay("良心作者:黄智垚\n洛谷账号:huangzhiyao\n\n");
	Slowsay("史上最温馨的提示:多位数一定要输入数字,不然会有特性。\n");
	Slowsay("对,是特性,而不是Bug。\n");
	wait();

没什么好说的……

c.改颜色
C++
    Slowsay("请选择颜色:\n");
	Slowsay("1.璀璨星河(黑底亮白字)\n");
	Slowsay("2.墨韵白笺(亮白底黑字)\n");
	Slowsay("3.翡翠金辉(深绿底亮黄字)\n");
	Slowsay("4.极客矩阵(黑底亮绿字)\n");
	Slowsay("5.海洋之心(深蓝底亮白字)\n");
	Slowsay("6.冰湖晨曦(浅青底亮白字)\n");
	Slowsay("7.赤焰星芒(深红底亮白字)\n");
	Slowsay("8.青空之镜(黑底亮青字)\n");
	Slowsay("9.月下霜白(黑底亮灰字)\n");
	int f=enter('1','9');
	switch(f){
		case 1:{
			system("color 0F");
			break;
		}
		case 2:{
			system("color F0");
			break;
		}
		case 3:{
			system("color 2E");
			break;
		}
		case 4:{
			system("color 0A");
			break;
		}
		case 5:{
			system("color 1F");
			break;
		}
		case 6:{
			system("color 3F");
			break;
		}
		case 7:{
			system("color 4F");
			break;
		}
		case 8:{
			system("color 0B");
			break;
		}
		case 9:{
			system("color 07");
			break;
		}
	}
	wait();

system("color XY")能改颜色
X是背景色
Y是前景色(文字颜色)
X,Y都是十六进制数

代码颜色代码颜色
0黑色1蓝色
2绿色3湖蓝色 / 浅绿色
4红色5紫色
6黄色7白色
8灰色9亮蓝色
A亮绿色B亮湖蓝 / 淡浅绿色
C亮红色D亮紫色
E亮黄色F亮白色
d.选游戏
C++
    Slowsay("请选择游戏:\n");
	Slowsay("1.教师模拟器\n");
	Slowsay("2.数字炸弹之就要踩雷版\n");
	Slowsay("3.闪电反应\n");
	Slowsay("4.记忆大师\n");
	int num=enter('1','4');
	switch(num){
		case 1:{
			wait();
			Teacher_Simulator();
			break;
		}
		case 2:{
			wait();
			Digital_Bomb__About_to_Step_on_a_Mine_Edition();
			break;
		}
		case 3:{
			wait();
			Lightning_Reflex();
			break;
		}
		case 4:{
			wait();
			Memory_Master();
			break;
		}
	}

也没什么好说的……

e.结束
C++
Slowsay("感谢游玩!再见。");
return 0;

真真真没什么好说的了

3.教师模拟器(Teacher Simulator)部分

详情
a.全局定义

string Name_database[100]存储了名字库

string Grade[9]存储了等级

string School_name[180]是不同分数对应的学校

score[9]存储的是对应等级所需分数

int stamina,lastweek,money分别是剩余体力,剩余周数,剩余钱数

struct Mate是每个人的信息

Mate mate[6]是全班信息

b.函数Class_Initialization
C++
void Class_Initialization(){
	vector<string> namePool;
    for(int i=0;i<100;i++) namePool.push_back(Name_database[i]);
	for(int i=0;i<6;i++){
		uniform_int_distribution<int> namedist(0,namePool.size()-1);
		int idx=namedist(rng);
		mate[i].name=namePool[idx];
		namePool.erase(namePool.begin()+idx);
		uniform_int_distribution<int> scoredist(5,40);
		mate[i].Chinese_score=scoredist(rng);
		mate[i].Maths_score=scoredist(rng);
		mate[i].English_score=scoredist(rng);
		mate[i].Physics_score=scoredist(rng);
		mate[i].Chemistry_score=scoredist(rng);
		mate[i].Biology_score=scoredist(rng);
	}
	return;
}

初始化全班成绩

c.函数Outputclass
C++
void Outputclass(){
	for(int i=0;i<6;i++){
		string out="学生"+mate[i].name+"\n";
    	out+="语文:"+mate[i].Chinese_grade+"\n";
    	out+="数学:"+mate[i].Maths_grade+"\n";
    	out+="英语:"+mate[i].English_grade+"\n";
    	out+="物理:"+mate[i].Physics_grade+"\n";
    	out+="化学:"+mate[i].Chemistry_grade+"\n";
    	out+="生物:"+mate[i].Biology_grade+"\n";
    	out+="\n";
    	Slowsay(out);
	}
	return;
}

输出班级情况

d.函数Resetgrade
C++
void Resetgrade(){
	for(int i=0;i<6;i++){
		for(int j=0;j<=8;j++){
			if(mate[i].Chinese_score>=score[j]) mate[i].Chinese_grade=Grade[j];
		}
		for(int j=0;j<=8;j++){
			if(mate[i].Maths_score>=score[j]) mate[i].Maths_grade=Grade[j];
		}
		for(int j=0;j<=8;j++){
			if(mate[i].English_score>=score[j]) mate[i].English_grade=Grade[j];
		}
		for(int j=0;j<=8;j++){
			if(mate[i].Physics_score>=score[j]) mate[i].Physics_grade=Grade[j];
		}
		for(int j=0;j<=8;j++){
			if(mate[i].Chemistry_score>=score[j]) mate[i].Chemistry_grade=Grade[j];
		}
		for(int j=0;j<=8;j++){
			if(mate[i].Biology_score>=score[j]) mate[i].Biology_grade=Grade[j];
		}
	}
	return;
}

计算班级每个人的等级

e.函数CalcBonus
C++
int CalcBonus(int curScore,int maxBonus){
    if (curScore>=150) return 0;
    int diff=150-curScore;
    int bonus=round(maxBonus*diff/150.0);
    bonus+=uniform_int_distribution<int>(-2,2)(rng);
    bonus=(std::max)(0,bonus);
    bonus=(std::min)(bonus,(150-curScore));
    return bonus;
}

计算每次行动,每个人能加多少分,加分非线性

f.函数displayWidth
C++
int displayWidth(const string& s){
    int width=0;
    for(unsigned char c:s){
        if(c<0x80) width+=1;
        else width+=2;
    }
    return width;
}

计算字符串宽度

g.函数padRight
C++
string padRight(const string& s, int totalWidth){
    int cur=displayWidth(s);
    if(cur>=totalWidth) return s;
    return s+string(totalWidth-cur,' ');
}

右填充

h.函数Outputresults
C++
void Outputresults(){
	uniform_int_distribution<int> dist(-5,5);
    Slowsay("学生姓名    语文  数学  英语  物理  化学  生物\n");
    for(int i=0;i<6;i++){
        string line;
        line+=padRight(mate[i].name,12);
        line+=padRight(to_string((std::min)(mate[i].Chinese_score+dist(rng),150)),6);
        line+=padRight(to_string((std::min)(mate[i].Maths_score+dist(rng),150)),6);
        line+=padRight(to_string((std::min)(mate[i].English_score+dist(rng),150)),6);
        line+=padRight(to_string((std::min)(mate[i].Physics_score+dist(rng),150)),6);
        line+=padRight(to_string((std::min)(mate[i].Chemistry_score+dist(rng),150)),6);
        line+=padRight(to_string((std::min)(mate[i].Biology_score+dist(rng),150)),6);
        Slowsay(line);
        Slowsay("\n");
    }
}

输出模拟考成绩

i.函数CEE
C++
void CEE(){
	Slowsay("学生姓名    语文  数学  英语  物理  化学  生物  总分\n");
	for(int i=0;i<6;i++){
		int CEEscore[6];
		string line;
		uniform_int_distribution<int> dist(-5,5);
		CEEscore[0]=(std::min)(mate[i].Chinese_score+dist(rng),150);
		CEEscore[1]=(std::min)(mate[i].Maths_score+dist(rng),150);
		CEEscore[2]=(std::min)(mate[i].English_score+dist(rng),150);
		CEEscore[3]=(std::min)(mate[i].Physics_score+dist(rng),150);
		CEEscore[4]=(std::min)(mate[i].Chemistry_score+dist(rng),150);
		CEEscore[5]=(std::min)(mate[i].Biology_score+dist(rng),150);
		int sum=0;
		for(int j=0;j<6;j++) sum+=CEEscore[j];
		int idx=sum/5;
		if(idx<0) idx=0;
		if(idx>179) idx=179;
		mate[i].CEE_grade=School_name[idx];
		mate[i].CEE_score=sum;
        line+=padRight(mate[i].name,12);
        line+=padRight(to_string(CEEscore[0]),6);
        line+=padRight(to_string(CEEscore[1]),6);
        line+=padRight(to_string(CEEscore[2]),6);
        line+=padRight(to_string(CEEscore[3]),6);
        line+=padRight(to_string(CEEscore[4]),6);
        line+=padRight(to_string(CEEscore[5]),6);
        line+=to_string(CEEscore[0]+CEEscore[1]+CEEscore[2]+CEEscore[3]+CEEscore[4]+CEEscore[5]);
        line+="/900";
        Slowsay(line+'\n');
	}
}

输出高考成绩

j.函数Teacher_Simulator

不水了

这个函数相当于主函数

有请D老师带来讲解:

Markdown
初始化班级,每周开始时补充1000班费,体力重置为3。
玩家选择自习/小测/大考/模拟考(消耗体力与班费)提升特定科目。
10周结束后自动高考,统计C9/985/211/上岸人数。
可按R重开新一届。

4.数字炸弹之就要踩雷版(Digital Bomb: About to Step on a Mine Edition)部分

详情

直接用Digital_Bomb__About_to_Step_on_a_Mine_Edition(),没有其它函数了

再次有请D老师:

Markdown
这段代码是一个**猜数字小游戏(数字炸弹·踩雷版)**,逻辑如下:

- **难度选择**:简单(1~100)、普通(1~1000)、困难(1~10000),区间依次扩大。
- **核心玩法**:系统随机生成答案,玩家每次猜一个数,根据反馈缩小范围(太小则提高下限,太大则降低上限),直到猜中。
- **评价系统**:用猜测次数评判表现,不同难度有不同评级线(如简单≤6次为“太厉害了”),并鼓励重试。
- **循环重玩**:按R可继续挑战同难度或重选难度。

一句话:**带难度分级和次数评价的二分猜数小游戏**。

5.闪电反应(Lightning Reflex)部分

详情

继续水

再再再再再次有请D老师:

Markdown
这是一个**反应速度测试小游戏**:

- 随机等待1~7秒后,屏幕出现“按空格键!”,测试玩家从提示到按键的**毫秒级反应时间**。
- 若提前抢跑会警告;按错键也会提醒。
- 根据反应时间给评价:<200ms 闪电、<500ms 优秀、<1000ms 一般、>1000ms 太慢。
- 按 `R` 重测,其他键退出。

6.记忆大师(Memory Master)部分

详情

默认描述

Markdown
这是一个**数字记忆测试小游戏**:

- 游戏从 **长度为4** 的随机数字串开始,显示 **1秒后消失**,玩家需凭记忆正确输入。
- 每答对一轮,数字长度 **+1**,继续挑战;答错则游戏结束并显示正确数字。
- 根据通过的轮数给出评价:≥15轮为“绝世天才”,≥10轮“记忆力很强”,≥6轮“还不错”,≥3轮“再练练”,否则“走神了”。
- 按 `R` 重玩,其他键退出。

后记

好累累累累累~~
我写了32752字符,总得给个赞吧,
求求了!!!

完结撒花~

当然,我应该、大概、可能、有概率、似乎会更新吧。。。。。。

原文
存档评论1 条抓取于