可以把游戏代码分开
库:
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#include<unistd.h>
#include<time.h>
变量定义
double zzl=0;
struct stu
{
int sl,money;//数量
short qd;//期待值
};
stu a[20];
//main中的定义
long long jf=0;
short dd=0;
short day=1;
short xz;
int scl=2,ss=1;//生产力
long long kc=5;//库存
bool k=false;
long double money=0;
int sss=0;
主函数
while(money<6000||dd<10)
{
for(int i=1; i<=sss; i++)
{
if(a[i].money>0&&a[i].sl!=0)
{
if(a[i].qd>0)
{
a[i].qd--;
a[i].money=a[i].sl*a[i].qd;
}
else
{
a[i].money=0;
money-=200;
if(money<=0)
{
cout<<" ***************"<<'\n';
cout<<" * LOSE *"<<'\n';
cout<<" ***************"<<'\n';
return 0;
}
}
}
}
system("CLS");
cout<<"第"<<day<<"天";
fast(" ——————————————————————————————————");
cout<<'\n';
sleep(1);
if(day%7==0)
{
slow("员工休假!");
cout<<'\n';
k=true;
money-=rand()%3+1;
}
else
{
k=false;
}
day=day+1;
kc+=scl*ss;
int yn=rand()%3;
srand(time(0));
if(yn%2==0&&k==false)
{
slow("订单+1");
cout<<endl;
sss++;
sleep(1);
//订单详情
a[sss].sl=rand()%25+5;
a[sss].qd=rand()%24+1;
a[sss].money=a[sss].sl*a[sss].qd;
}
slow("1 查看订单");
cout<<'\n';
slow("2 提高生产力");
cout<<'\n';
slow("3 增加生产线");
cout<<'\n';
slow("4 接受订单");
cout<<'\n';
slow("5 个人情况");
cout<<'\n';
cin>>xz;
switch(xz)
{
case 1:
cout<<"订单:"<<'\n';
sleep(1);
for(int i=1; i<=sss; i++)
{
cout<<'\n';
cout<<"订单"<<i<<":"<<'\n';
sleep(1);
fast("价值:");
cout<<a[i].money<<"$"<<'\n';
fast("客户期待值:");
cout<<a[i].qd<<'\n';
fast("订单数量:");
cout<<a[i].sl<<'\n';
sleep(1);
}
break;
case 2:
if(k==true)
{
fast("生产力+3 $+5w");
cout<<'\n';
sleep(1);
money+=5;
scl+=3;
}
else
{
fast("生产力+1 $+0.5w");
cout<<'\n';
sleep(1);
money+=0.5;
scl++;
}
break;
case 3:
if(money<10&&k==false)
{
cout<<"不够!"<<endl;
}
else
{
if(k==true)
{
fast("生产线+2 $-1w");
cout<<'\n';
sleep(1);
money-=1;
ss+=2;
}
else
{
fast("生产线+1 $-10w");
cout<<'\n';
sleep(1);
money-=10;
ss++;
}
}
break;
case 4:
cout<<"订单:"<<'\n';
sleep(1);
for(int i=1; i<=sss; i++)
{
cout<<'\n';
cout<<"订单"<<i<<":"<<'\n';
sleep(1);
fast("价值:");
cout<<a[i].money<<"$"<<'\n';
fast("客户期待值:");
cout<<a[i].qd<<'\n';
fast("订单数量:");
cout<<a[i].sl<<'\n';
sleep(1);
}
cout<<"订单编号:";
cin>>xz;
if(xz<=sss&&a[xz].sl<=kc)
{
cout<<xz<<"号订单交付成功!"<<endl;
dd++;
money+=a[xz].money+a[xz].qd*a[xz].sl*5;
a[xz].money=0;
a[xz].qd=0;
a[xz].sl=0;
sleep(1);
}
else
{
cout<<"Error!"<<'\n';
}
break;
case 5:
cout<<"[1] 获得总金额($):"<<money<<"w"<<'\n';
sleep(1);
cout<<"[2] 生产线数量(条):"<<ss<<'\n';
sleep(1);
cout<<"[3] 生产效率(件/天):"<<scl<<'\n';
sleep(1);
cout<<"[4] 库存(件):"<<kc<<'\n';
sleep(1);
cout<<"[5] 完成订单(项):"<<dd<<'\n'<<'\n';
sleep(2);
break;
default:
cout<<"Error!"<<'\n';
break;
}
}
判断成功/失败
//[1] main
cout<<" ***************"<<'\n';
cout<<" * WIN *"<<'\n';
cout<<" ***************"<<'\n';
cout<<"[1] 获得总金额($):"<<money<<"w";
sleep(1);
pd(money,1);
cout<<'\n';
cout<<"[2] 生产线数量(条):"<<ss;
sleep(1);
pd(ss,2);
cout<<'\n';
cout<<"[3] 生产效率(件/天):"<<scl;
sleep(1);
pd(scl,3);
cout<<'\n';
cout<<"[4] 库存(件):"<<kc;
sleep(1);
pd(kc,4);
cout<<'\n';
cout<<"[5] 完成订单(项):"<<dd<<'\n';
sleep(1);
pd(ss,5);
cout<<'\n';
cout<<"满分:5分 您的分数:"<<zzl<<"分"<<'\n';
cout<<"总评:";
if(zzl>=5)
{
cout<<"S++"<<'\n';
}
else if(zzl>=3.5)
{
cout<<"A+"<<'\n';
}
else if(zzl>=2)
{
cout<<"B"<<'\n';
}
else if(zzl>1)
{
cout<<"C"<<'\n';
}
else
{
cout<<"D Poor"<<'\n';
}
//[2]函数
void pd(int a,int tj)
{
switch(tj)
{
case 1:
zzl++;
if(a<=5500)
{
cout<<" B+"<<'\n';
}
else if(a<=6000)
{
cout<<" A"<<'\n';
}
else
{
cout<<" A+"<<'\n';
zzl+=0.05;
}
break;
case 2:
if(a==1)
{
cout<<" B+"<<'\n';
zzl+=0.2;
}
else if(a<=3)
{
cout<<" A"<<'\n';
zzl+=0.7;
}
else if(a<=5)
{
cout<<" A+"<<'\n';
zzl+=0.85;
}
else
{
cout<<" S++"<<'\n';
zzl++;
}
break;
case 3:
if(a==2)
{
cout<<" 1个字----(⊙o⊙)傻 等级:B"<<'\n';
zzl-=0.2;
}
else if(a<=5)
{
cout<<" 等级: B+"<<'\n';
zzl+=0.35;
}
else if(a<=10)
{
cout<<" 等级: A"<<'\n';
zzl+=0.75;
}
else if(a<=15)
{
cout<<" 等级: A+"<<'\n';
zzl+=0.85;
}
else
{
cout<<" 等级: S++"<<'\n';
zzl++;
}
break;
case 4:
if(a<=10)
{
cout<<" 等级: B+"<<'\n';
zzl+=0.15;
}
else if(a<=15)
{
cout<<" 等级: B"<<'\n';
zzl+=0.35;
}
else if(a<=20)
{
cout<<" 等级: A"<<'\n';
zzl+=0.6;
}
else if(a<=50)
{
cout<<" 等级: A+"<<'\n';
zzl+=0.85;
}
else
{
cout<<" 等级: S++"<<'\n';
zzl++;
}
break;
case 5:
cout<<setw(20)<<"-够了-";
zzl++;
break;
}
}
定义输出方式 快和慢
Sleep()函数“S”大写
void slow(string a)
{
for(int i=0; i<a.size(); i++)
{
Sleep(100);
cout<<a[i];
}
}
void fast(string a)
{
for(int i=0; i<a.size(); i++)
{
Sleep(10);
cout<<a[i];
}
}
源代码:
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#include<unistd.h>
#include<time.h>
using namespace std;
double zzl=0;
struct stu
{
int sl,money;//数量
short qd;//期待值
};
stu a[20];
void slow(string a)
{
for(int i=0; i<a.size(); i++)
{
Sleep(100);
cout<<a[i];
}
}
void fast(string a)
{
for(int i=0; i<a.size(); i++)
{
Sleep(10);
cout<<a[i];
}
}
void pd(int a,int tj)
{
switch(tj)
{
case 1:
zzl++;
if(a<=5500)
{
cout<<" B+"<<'\n';
}
else if(a<=6000)
{
cout<<" A"<<'\n';
}
else
{
cout<<" A+"<<'\n';
zzl+=0.05;
}
break;
case 2:
if(a==1)
{
cout<<" B+"<<'\n';
zzl+=0.2;
}
else if(a<=3)
{
cout<<" A"<<'\n';
zzl+=0.7;
}
else if(a<=5)
{
cout<<" A+"<<'\n';
zzl+=0.85;
}
else
{
cout<<" S++"<<'\n';
zzl++;
}
break;
case 3:
if(a==2)
{
cout<<" 1个字----(⊙o⊙)傻 等级:B"<<'\n';
zzl-=0.2;
}
else if(a<=5)
{
cout<<" 等级: B+"<<'\n';
zzl+=0.35;
}
else if(a<=10)
{
cout<<" 等级: A"<<'\n';
zzl+=0.75;
}
else if(a<=15)
{
cout<<" 等级: A+"<<'\n';
zzl+=0.85;
}
else
{
cout<<" 等级: S++"<<'\n';
zzl++;
}
break;
case 4:
if(a<=10)
{
cout<<" 等级: B+"<<'\n';
zzl+=0.15;
}
else if(a<=15)
{
cout<<" 等级: B"<<'\n';
zzl+=0.35;
}
else if(a<=20)
{
cout<<" 等级: A"<<'\n';
zzl+=0.6;
}
else if(a<=50)
{
cout<<" 等级: A+"<<'\n';
zzl+=0.85;
}
else
{
cout<<" 等级: S++"<<'\n';
zzl++;
}
break;
case 5:
cout<<setw(20)<<"-够了-";
zzl++;
break;
}
}
int main()
{
long long jf=0;
short dd=0;
short day=1;
short xz;
int scl=2,ss=1;//生产力
long long kc=5;//库存
bool k=false;
long double money=0;
int sss=0;
while(money<6000||dd<10)
{
for(int i=1; i<=sss; i++)
{
if(a[i].money>0&&a[i].sl!=0)
{
if(a[i].qd>0)
{
a[i].qd--;
a[i].money=a[i].sl*a[i].qd;
}
else
{
a[i].money=0;
money-=200;
if(money<=0)
{
cout<<" ***************"<<'\n';
cout<<" * LOSE *"<<'\n';
cout<<" ***************"<<'\n';
return 0;
}
}
}
}
system("CLS");
cout<<"第"<<day<<"天";
fast(" ——————————————————————————————————");
cout<<'\n';
sleep(1);
if(day%7==0)
{
slow("员工休假!");
cout<<'\n';
k=true;
money-=rand()%3+1;
}
else
{
k=false;
}
day=day+1;
kc+=scl*ss;
int yn=rand()%3;
srand(time(0));
if(yn%2==0&&k==false)
{
slow("订单+1");
cout<<endl;
sss++;
sleep(1);
//订单详情
a[sss].sl=rand()%25+5;
a[sss].qd=rand()%24+1;
a[sss].money=a[sss].sl*a[sss].qd;
}
slow("1 查看订单");
cout<<'\n';
slow("2 提高生产力");
cout<<'\n';
slow("3 增加生产线");
cout<<'\n';
slow("4 接受订单");
cout<<'\n';
slow("5 个人情况");
cout<<'\n';
cin>>xz;
switch(xz)
{
case 1:
cout<<"订单:"<<'\n';
sleep(1);
for(int i=1; i<=sss; i++)
{
cout<<'\n';
cout<<"订单"<<i<<":"<<'\n';
sleep(1);
fast("价值:");
cout<<a[i].money<<"$"<<'\n';
fast("客户期待值:");
cout<<a[i].qd<<'\n';
fast("订单数量:");
cout<<a[i].sl<<'\n';
sleep(1);
}
break;
case 2:
if(k==true)
{
fast("生产力+3 $+5w");
cout<<'\n';
sleep(1);
money+=5;
scl+=3;
}
else
{
fast("生产力+1 $+0.5w");
cout<<'\n';
sleep(1);
money+=0.5;
scl++;
}
break;
case 3:
if(money<10&&k==false)
{
cout<<"不够!"<<endl;
}
else
{
if(k==true)
{
fast("生产线+2 $-1w");
cout<<'\n';
sleep(1);
money-=1;
ss+=2;
}
else
{
fast("生产线+1 $-10w");
cout<<'\n';
sleep(1);
money-=10;
ss++;
}
}
break;
case 4:
cout<<"订单:"<<'\n';
sleep(1);
for(int i=1; i<=sss; i++)
{
cout<<'\n';
cout<<"订单"<<i<<":"<<'\n';
sleep(1);
fast("价值:");
cout<<a[i].money<<"$"<<'\n';
fast("客户期待值:");
cout<<a[i].qd<<'\n';
fast("订单数量:");
cout<<a[i].sl<<'\n';
sleep(1);
}
cout<<"订单编号:";
cin>>xz;
if(xz<=sss&&a[xz].sl<=kc)
{
cout<<xz<<"号订单交付成功!"<<endl;
dd++;
money+=a[xz].money+a[xz].qd*a[xz].sl*5;
a[xz].money=0;
a[xz].qd=0;
a[xz].sl=0;
sleep(1);
}
else
{
cout<<"Error!"<<'\n';
}
break;
case 5:
cout<<"[1] 获得总金额($):"<<money<<"w"<<'\n';
sleep(1);
cout<<"[2] 生产线数量(条):"<<ss<<'\n';
sleep(1);
cout<<"[3] 生产效率(件/天):"<<scl<<'\n';
sleep(1);
cout<<"[4] 库存(件):"<<kc<<'\n';
sleep(1);
cout<<"[5] 完成订单(项):"<<dd<<'\n'<<'\n';
sleep(2);
break;
default:
cout<<"Error!"<<'\n';
break;
}
}
cout<<" ***************"<<'\n';
cout<<" * WIN *"<<'\n';
cout<<" ***************"<<'\n';
cout<<"[1] 获得总金额($):"<<money<<"w";
sleep(1);
pd(money,1);
cout<<'\n';
cout<<"[2] 生产线数量(条):"<<ss;
sleep(1);
pd(ss,2);
cout<<'\n';
cout<<"[3] 生产效率(件/天):"<<scl;
sleep(1);
pd(scl,3);
cout<<'\n';
cout<<"[4] 库存(件):"<<kc;
sleep(1);
pd(kc,4);
cout<<'\n';
cout<<"[5] 完成订单(项):"<<dd<<'\n';
sleep(1);
pd(ss,5);
cout<<'\n';
cout<<"满分:5分 您的分数:"<<zzl<<"分"<<'\n';
cout<<"总评:";
if(zzl>=5)
{
cout<<"S++"<<'\n';
}
else if(zzl>=3.5)
{
cout<<"A+"<<'\n';
}
else if(zzl>=2)
{
cout<<"B"<<'\n';
}
else if(zzl>1)
{
cout<<"C"<<'\n';
}
else
{
cout<<"D Poor"<<'\n';
}
return 0;
}
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#include<unistd.h>
#include<time.h>
using namespace std;
double zzl=0;
struct stu
{
int sl,money;//数量
short qd;//期待值
};
stu a[20];
void slow(string a)
{
for(int i=0; i<a.size(); i++)
{
Sleep(100);
cout<<a[i];
}
}
void fast(string a)
{
for(int i=0; i<a.size(); i++)
{
Sleep(10);
cout<<a[i];
}
}
void pd(int a,int tj)
{
switch(tj)
{
case 1:
zzl++;
if(a<=5500)
{
cout<<" B+"<<'\n';
}
else if(a<=6000)
{
cout<<" A"<<'\n';
}
else
{
cout<<" A+"<<'\n';
zzl+=0.05;
}
break;
case 2:
if(a==1)
{
cout<<" B+"<<'\n';
zzl+=0.2;
}
else if(a<=3)
{
cout<<" A"<<'\n';
zzl+=0.7;
}
else if(a<=5)
{
cout<<" A+"<<'\n';
zzl+=0.85;
}
else
{
cout<<" S++"<<'\n';
zzl++;
}
break;
case 3:
if(a==2)
{
cout<<" 1个字----(⊙o⊙)傻 等级:B"<<'\n';
zzl-=0.2;
}
else if(a<=5)
{
cout<<" 等级: B+"<<'\n';
zzl+=0.35;
}
else if(a<=10)
{
cout<<" 等级: A"<<'\n';
zzl+=0.75;
}
else if(a<=15)
{
cout<<" 等级: A+"<<'\n';
zzl+=0.85;
}
else
{
cout<<" 等级: S++"<<'\n';
zzl++;
}
break;
case 4:
if(a<=10)
{
cout<<" 等级: B+"<<'\n';
zzl+=0.15;
}
else if(a<=15)
{
cout<<" 等级: B"<<'\n';
zzl+=0.35;
}
else if(a<=20)
{
cout<<" 等级: A"<<'\n';
zzl+=0.6;
}
else if(a<=50)
{
cout<<" 等级: A+"<<'\n';
zzl+=0.85;
}
else
{
cout<<" 等级: S++"<<'\n';
zzl++;
}
break;
case 5:
cout<<setw(20)<<"-够了-";
zzl++;
break;
}
}
int main()
{
long long jf=0;
short dd=0;
short day=1;
short xz;
int scl=2,ss=1;//生产力
long long kc=5;//库存
bool k=false;
long double money=0;
int sss=0;
while(money<6000||dd<10)
{
for(int i=1; i<=sss; i++)
{
if(a[i].money>0&&a[i].sl!=0)
{
if(a[i].qd>0)
{
a[i].qd--;
a[i].money=a[i].sl*a[i].qd;
}
else
{
a[i].money=0;
money-=200;
if(money<=0)
{
cout<<" ***************"<<'\n';
cout<<" * LOSE *"<<'\n';
cout<<" ***************"<<'\n';
return 0;
}
}
}
}
system("CLS");
cout<<"第"<<day<<"天";
fast(" ——————————————————————————————————");
cout<<'\n';
sleep(1);
if(day%7==0)
{
slow("员工休假!");
cout<<'\n';
k=true;
money-=rand()%3+1;
}
else
{
k=false;
}
day=day+1;
kc+=scl*ss;
int yn=rand()%3;
srand(time(0));
if(yn%2==0&&k==false)
{
slow("订单+1");
cout<<endl;
sss++;
sleep(1);
//订单详情
a[sss].sl=rand()%25+5;
a[sss].qd=rand()%24+1;
a[sss].money=a[sss].sl*a[sss].qd;
}
slow("1 查看订单");
cout<<'\n';
slow("2 提高生产力");
cout<<'\n';
slow("3 增加生产线");
cout<<'\n';
slow("4 接受订单");
cout<<'\n';
slow("5 个人情况");
cout<<'\n';
cin>>xz;
switch(xz)
{
case 1:
cout<<"订单:"<<'\n';
sleep(1);
for(int i=1; i<=sss; i++)
{
cout<<'\n';
cout<<"订单"<<i<<":"<<'\n';
sleep(1);
fast("价值:");
cout<<a[i].money<<"$"<<'\n';
fast("客户期待值:");
cout<<a[i].qd<<'\n';
fast("订单数量:");
cout<<a[i].sl<<'\n';
sleep(1);
}
break;
case 2:
if(k==true)
{
fast("生产力+3 $+5w");
cout<<'\n';
sleep(1);
money+=5;
scl+=3;
}
else
{
fast("生产力+1 $+0.5w");
cout<<'\n';
sleep(1);
money+=0.5;
scl++;
}
break;
case 3:
if(money<10&&k==false)
{
cout<<"不够!"<<endl;
}
else
{
if(k==true)
{
fast("生产线+2 $-1w");
cout<<'\n';
sleep(1);
money-=1;
ss+=2;
}
else
{
fast("生产线+1 $-10w");
cout<<'\n';
sleep(1);
money-=10;
ss++;
}
}
break;
case 4:
cout<<"订单:"<<'\n';
sleep(1);
for(int i=1; i<=sss; i++)
{
cout<<'\n';
cout<<"订单"<<i<<":"<<'\n';
sleep(1);
fast("价值:");
cout<<a[i].money<<"$"<<'\n';
fast("客户期待值:");
cout<<a[i].qd<<'\n';
fast("订单数量:");
cout<<a[i].sl<<'\n';
sleep(1);
}
cout<<"订单编号:";
cin>>xz;
if(xz<=sss&&a[xz].sl<=kc)
{
cout<<xz<<"号订单交付成功!"<<endl;
dd++;
money+=a[xz].money+a[xz].qd*a[xz].sl*5;
a[xz].money=0;
a[xz].qd=0;
a[xz].sl=0;
sleep(1);
}
else
{
cout<<"Error!"<<'\n';
}
break;
case 5:
cout<<"[1] 获得总金额($):"<<money<<"w"<<'\n';
sleep(1);
cout<<"[2] 生产线数量(条):"<<ss<<'\n';
sleep(1);
cout<<"[3] 生产效率(件/天):"<<scl<<'\n';
sleep(1);
cout<<"[4] 库存(件):"<<kc<<'\n';
sleep(1);
cout<<"[5] 完成订单(项):"<<dd<<'\n'<<'\n';
sleep(2);
break;
default:
cout<<"Error!"<<'\n';
break;
}
}
cout<<" ***************"<<'\n';
cout<<" * WIN *"<<'\n';
cout<<" ***************"<<'\n';
cout<<"[1] 获得总金额($):"<<money<<"w";
sleep(1);
pd(money,1);
cout<<'\n';
cout<<"[2] 生产线数量(条):"<<ss;
sleep(1);
pd(ss,2);
cout<<'\n';
cout<<"[3] 生产效率(件/天):"<<scl;
sleep(1);
pd(scl,3);
cout<<'\n';
cout<<"[4] 库存(件):"<<kc;
sleep(1);
pd(kc,4);
cout<<'\n';
cout<<"[5] 完成订单(项):"<<dd<<'\n';
sleep(1);
pd(ss,5);
cout<<'\n';
cout<<"满分:5分 您的分数:"<<zzl<<"分"<<'\n';
cout<<"总评:";
if(zzl>=5)
{
cout<<"S++"<<'\n';
}
else if(zzl>=3.5)
{
cout<<"A+"<<'\n';
}
else if(zzl>=2)
{
cout<<"B"<<'\n';
}
else if(zzl>1)
{
cout<<"C"<<'\n';
}
else
{
cout<<"D Poor"<<'\n';
}
return 0;
}