右键开始游戏即可开始 部分编译器可能不支持windows.h头文件,请谅解 注:无版权免费发放 格式会有点错误请自行更改
iostream头文件自己加
代码分享:
#include <windows.h>
#include <conio.h>
#include <tchar.h>
#include <time.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
void gotoxy(int x,int y); void HideTheCursor(); void ready(); void story(int a,int b,int c,int d);
int yz,zl,tz,jj;
int main(){ ready(); system("cls"); cout<<"颜值(0-10):"; cin>>yz; cout<<"智力(0-10):"; cin>>zl; cout<<"体质(0-10):"; cin>>tz; cout<<"家境(0-10):"; cin>>jj; system("cls"); story(yz,zl,tz,jj); }
void gotoxy(int x,int y){ COORD pos; pos.X=x;pos.Y=y; HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(hout,pos); }
void HideTheCursor(){ CONSOLE_CURSOR_INFO cci; HANDLE hstdout=GetStdHandle(STD_OUTPUT_HANDLE); if (GetConsoleCursorInfo(hstdout,&cci)){ cci.bVisible=FALSE; SetConsoleCursorInfo(hstdout,&cci); } }
void ready(){ HideTheCursor(); HWND window=GetForegroundWindow(); SetConsoleTitle("人生重开模拟器"); ShowWindow(window,SW_MAXIMIZE); gotoxy(75,1); cout<<"-------人生重开模拟器-------"; gotoxy(76,5); cout<<"这垃圾人生是一秒也不想呆了"; HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(handle,0x6); gotoxy(85,10); cout<<"立即重开"; SetConsoleTextAttribute(handle,0xF);
HWND controlTable,n;
controlTable=GetForegroundWindow();
POINT p;
HANDLE hOutput;
hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_FONT_INFO font;
GetCurrentConsoleFont(hOutput,FALSE,&font);
while(1){
GetCursorPos(&p);
ScreenToClient(controlTable,&p);
if (KEY_DOWN(VK_RBUTTON)){
int x=p.x/font.dwFontSize.X;
int y=p.y/font.dwFontSize.Y;
if (x>=85&&x<=93&&y==10){
return ;
}
}
}
}
void story(int a,int b,int c,int d){ int i=0,e=10; short male,tf=0; bool com=0,pad=0,sb=0;
srand(time(0));
male=rand()%2;
gotoxy(0,0);
cout<<"颜值:"<<a
<<"|智力:"<<b
<<"|体质:"<<c
<<"|家境:"<<d
<<"|快乐"<<e
<<endl;
while (1){
Sleep(4000);
cout<<i<<"岁: ";
if (i==0){
if (c<=1){
cout<<"你因为体质不足而死于胎中";
return ;
}
else{
if(male==1){
cout<<"你出生了, 是个男孩";
}else{
cout<<"你出生了, 是个女孩";
}
}
}else if(i==1){
if(a<=2){
cout<<"你因为颜值不够而被父母抛弃了;你到处流浪最后饿死了";
return ;
}
else{
if (d<=7){
cout<<"你从小生活在农村里";
}else{
cout<<"你从小生活在城市里";
}
}
}else if(i==2){
if (d>=10) {cout<<"你的父母对你视若珍宝, 呵护备至";e++;}
else if (b>=5&&d<=5){cout<<"你天资聪慧, 但家人们并不懂得培养";e--;}
else {cout<<"你的父母并没有精心照顾你";e--;}
}else if(i==3){
cout<<"你开始上幼儿园了";
}else if(i==6){
cout<<"你开始上小学了";
}else if(i==12){
cout<<"你开始上中学了";
}else{
int n=rand()%11;
if (n==0&&i<=10){
cout<<"你因为吃了太多糖拉了肚子";
c--;e--;
}else if(n==1&&i>=3&&i<=6){
cout<<"你在幼儿园参加了数学竞赛, ";
int v=rand()%3;
if(v==1||v==0){
cout<<"你赢了"<<v+1<<"等奖";
b++;e+=v*-1+2;
}else{
cout<<"但是很遗憾输了";
b--;e--;
}
}else if (n==2&&tf==0){
tf=rand()%4+1;
cout<<"你发现你有";
if(tf==1){
cout<<"画画";
}else if(tf==2){
cout<<"篮球";
}else if (tf==3&&com==1){
cout<<"编程";
}else{
cout<<"烹饪";
}
cout<<"的天赋";
tf++;
}else if (n==3&&c<=5){
cout<<"你生了一场大病,你的父母给了很多医疗费用";
d-=4;e-=2;
}else if (n==4&&i>=8&&i<=18&&d>=12&&com==0){
cout<<"你的父母送了你一台笔记本电脑";
com=1;e++;
}else if (n==5&&i>=8&&i<=16&&d>=10&&pad==0){
cout<<"你的父母送了你一台平板";
pad=1;e++;
}else if (n==6&&i>=14&&i<=18){
cout<<"你学会了用B站赚钱并分了一些给父母";
b++;
d++;
e++;
}else if (n==7&&i>=6&&i<=10&&d>=8&&sb==0){
cout<<"你的姐姐送了你一个小天才电话手表";
sb=1;
e++;
}else if (n==8&&i>=5&&rand()%10==1){
cout<<"有天打雷, 劈断了你家门口一棵树";
e--;
}else if (n==9&&i>=5&&e<=5){
cout<<"你经常坐在家门口发呆, 十分无聊";
}else if (n==10&&i>=7&&d<=10&&e<=7){
cout<<"可能是运气不佳, 这年里有好多小事让你烦心";
e--;
}else{
if (a<=3){
cout<<"有亲戚遗憾地说你声音很好听, 可以长得太丑了";
e--;
}else if (e<=3){
cout<<"你的情绪越来越低落, 尝试自杀";
e--;
}else if (c>=17&&b>=12){
cout<<"空气很清新,生活很健康";
}else if (e>=17){
cout<<"比较顺风顺水, 快乐的一年";
}else if (i==23){
cout<<"你结婚了";
e++;
}else if (i==20){
cout<<"你开始创业";
}else if (i==90){
cout<<"人类首次3D打印月球, 从此天上有了两个月亮";
}else if (i==80){
cout<<"人类登上了火星";
}else if (i==70){
cout<<"人类开发了速度能达到光速的9/10的火箭";
}else if (i==60){
cout<<"人类发明了飞行汽车";
}else if (i==50){
cout<<"人类利用火星车带来了火星上的一滴水";
}else if (i==40){
cout<<"我国可控核聚变有所突破, 离成功不远了";
}else if (i==30){
cout<<"电视机逐渐淡出舞台";
}else{
if (tf==1){
int g=rand()%4;
if (g==0){
cout<<"你给你的父母画了一张画";
}else if (g==1&&i<7){
cout<<"你不小心尿床尿出了一张世界地图";
}else if (g==2){
cout<<"你收到了一个绘画比赛的参加邀请";
}else{
cout<<"平平淡淡的一年";
}
}else if (tf==2){
int r=rand()%5;
if (r==0){
int v=rand()%8;
cout<<"你参加了篮球奥运会并拿到了"<<v<<"等奖";
}else if (r==1){
cout<<"你和你的朋友玩了一场篮球赛";
}else if (r==2){
cout<<"你喜欢篮球, 并通过发布篮球教学视频为家人攒了一笔钱";
d++;
}else if (r==3){
cout<<"你在网上有很多粉丝";
}else {
cout<<"平平淡淡的一年";
}
}else if (tf==3){
int h=rand()%10;
if (h==0){
cout<<"你做了一个游戏给自己玩, 玩自己做的游戏是永远都不会无聊的!";e++;
e++;
}else if (h==1){
cout<<"你参加了等级考试并考了满分,你很开心";e++;
}else if (h==2){
cout<<"你有很多粉丝, 大部分是大佬";
}else if (h==3){
cout<<"你通过发布python,c++,或java教学视频赚了不少钱";d++;
}else if (h==4){
cout<<"全国各地的记者都喜欢来拜访你";
}else if (h==5){
cout<<"你出版了一些书, 大部分都是关于编程的";
}else if (h==6){
cout<<"你开发了一种新的编程语言语言";
}else if (h==7){
cout<<"你在网站上被人吐槽装的像个大佬, 你很伤心";
e--;
}else if (h==8){
cout<<"你因为过于自信而做完游戏后不测试就直接发布,bug满屏幕,被游戏发布公司扣了不少钱";
d-=2;
e-=2;
}else if (h==9){
cout<<"你给一个用户编程下单的时候被骗了,损失了点钱";
e--;
d--;
}else {
cout<<"平平淡淡的一年";
}
}else if (tf==4){
int z=rand()%4;
if (z==0){
cout<<"你开发出了一种新的菜";
}else if (z==1){
cout<<"你通过直播煮菜过程在网上火了很久";
}else if (z==2){
cout<<"你为你的朋友煮了一道很好吃的菜";
}else{
cout<<"平平淡淡的一年";
}
}else{
cout<<"平平淡淡的一年";
}
}
}
}
i++;
if (a<=0){
cout<<";你因为颜值太低被父母抛弃, 你到处流浪但最后还是饿死了";return ;
}else if(b<=0){
cout<<";你因为智商太低变成了智障, 父母很生气并为你做了安乐死";return ;
}else if(c<=0){
cout<<";你因为体质太低而死, 你的朋友和家人为你举行了葬礼";return ;
}else if(d<=0){
cout<<";你因为家里太穷没东西吃, 最后你和父母饿死了";return ;
}else if (e<=0){
cout<<";你的情绪太低落, 自杀了";return ;
}
cout<<endl;
gotoxy(0,0);
//cout<<" ";
cout<<"颜值:"<<a
<<"|智力:"<<b
<<"|体质:"<<c
<<"|家境:"<<d
<<"|快乐"<<e;
gotoxy(0,i+1);
if (i>=65){
c--;
}
if (i>=75){
c--;
}
if (i>=90){
c-=2;
}
if (a>20) a=20;
if (b>20) b=20;
if (c>20) c=20;
if (d>20) d=20;
if (e>20) e=20;
}
}
共 3 条回复
我右键开始不了
你这也太乱了【捂脸】,头文件<Windows.h>的“w”还没有大写【哭笑不得】
我这里显示没有定义过变量 'CONSOLE_FONT_INFO'、 'GetCurrentConsoleFont'、 'font'