模拟帝国类游戏(c++语言)(保证能运行)

直接上代码(游戏有的功能没做,还不能用):

作者卑微申请:给个赞,再观看:

# include <bits/stdc++.h>
# include <stdlib.h>
# include <time.h>
using namespace std;
void player_one(int end)
{
int year,level,people,soldiers,money,food,point,a1,a2,a3,a4,mind,rate,people_money,assemble,ready=0,ready1=0;
year=0; level=1; people=100; soldiers=0; money=100000; food=200; mind=100; rate=5; assemble=0; 
cout<<"Note: The initial grain is only enough for the people to survive for 2 years"
	<<"<any key to continue>";
cin>>a1;
while (end==0)
{
	if (level==1)	point=5;
	if (level==2)   point=10;
	if (level==3)   point=15;
	if (level==4)   point=20;
	year+=1;
	system("cls");
	cout<<"                                                                "
		<<year<<" year "<<"level:"<<level<<endl;
	cout<<"                                                                "
		<<"people:"<<people<<" soldiers:"<<soldiers<<" money:"<<money<<endl
		<<"                                                                "
		<<"food:"<<food<<" point:"<<point<<"people's mind:"<<mind
		<<" Tax rate:"<<rate<<"%"<<endl;
	if (ready==1&&ready1==year)
	{
		cout<<"write random number.(the number must > 100)"<<endl;
		cin>>a3;
		a3=(a3%100*2/4%20+27)%10%2;
		if (a3==0)
		{
			cout<<"you win the war,lose soldiers:"<<soldiers/2<<" now soldiers:"<<soldiers-soldiers/2<<endl;
			soldiers-=soldiers/2;
		}
	}
	while (point>0)
	{
		cout<<"result:                                                 <1>make soldiers:                      2points "<<endl//招募士兵 
			<<"                                                        <2>make money:                         2points"<<endl//经商 
			<<"                                                        <3>make food:                          1point "<<endl//耕种 
			<<"                                                        <4>assemble soldiers:                  3points "<<endl//集结士兵 
			<<"                                                        <5>fight a war:                        3points"<<endl//打仗 
			<<"                                                        <6>change tax:                         no point"<<endl//加强税收 
			<<"                                                        <7>Diplomacy:                          2points "<<endl//外交 
			<<"                                                        <8>random event:                       3points "<<endl//随机事件 
			<<"                                                        <9>investigate the enemy's situation:  2points"<<endl//勘察敌情 
			<<"                                                        <10>next year"<<endl
			<<"                                                        <11>end"<<endl
			<<"                                                        now point:"<<point<<endl;
		cin>>a1;
		//招募士兵 
		if (a1==1)
		{
			if (point>=2)
			{
				point-=2;
				srand(time(0));
	    		cout<<"write the random number(the number must >2000)"<<endl;
	    		cin>>a2;
	    		if (level==1)a2=(a2%100/7*3/2*5)%90;
	    		if (level==2)a2=((a2%500/3*2+a2%100/2)/2+a1%200/3)%480;
	   			if (level==3)a2=(a2%1000+a2%1000/3)%800;
	    		if (level==4)a2=(a2%2000/2+a2%2000/3*2-a2%800)%2000;
				while (a2+soldiers>people)
				{
					if (level==1)a2=(a2%100/7*3/2*5)%90;
	    			if (level==2)a2=((a2%500/3*2+a2%100/2)/2+a1%200/3)%480;
	   				if (level==3)a2=(a2%1000+a2%1000/3)%800;
	    			if (level==4)a2=(a2%2000/2+a2%2000/3*2-a2%800)%2000;
			} 
			soldiers+=a2;
    		cout<<"make soldiers:"<<a2<<" now soldiers:"<<soldiers<<endl;
    		if (soldiers>people/2) cout<<"You seem to have too many soldiers,this will lead to a gradual shortage of food for you."
									   <<endl;
			}
			else 	cout<<"you have no points to do that."<<endl;
		}
		//经商 
		if (a1==2)
		{
			if (point>=2)
			{
			point-=2;
			srand(time(0));
			int b=rand()%money/5;
			money+=b;
			cout<<"make money:"<<b<<" now money:"<<money<<endl;
			}
			else	cout<<"you have no points to do that."<<endl;
		}
		//耕种
		if (a1==3)
		{
			if (point>=1)
			{
				point-=1;
				srand(time(0));
				int c=rand()%(people-soldiers)/5*80;
				food+=c;
				cout<<"make food:"<<c<<" now food:"<<food<<endl;	
			}
			else	cout<<"you have no points to do that."<<endl;
		}
		//集结士兵 
		if (a1==4)
		{
			if (point>=3)
			{
			
			cout<<"write your assemble soldiers's number."<<endl;
			cin>>a3;
			if (a3>soldiers||a3==0)
				cout<<"the number must < your all soldiers and the number must > 0."<<endl;
			else
			{
				cout<<"you assemble soldiers."<<endl;
				point-=3;
				assemble+=a3;
			}
			}
			else	cout<<"you have no points to do that."<<endl;
		}
		//发动战争
		if (a1==5)
		{
			if (point>=3)
			{
			if (a3==0)
				cout<<"you must assemble soldiers before you fight a war."<<endl;
			else
			{
				cout<<"you fight a war.the war end should wait one year."<<endl;
				ready=1;
				ready1=year+1;
			}
			}
			else	cout<<"you have no points to do that."<<endl;
		}
		//改变税收
		if (a1==6)
		{
			if (point>=1)
			{
				cout<<"+ or -(1 or 2)"<<endl; 
				cin>>a3;
				cout<<"write the number (after - must >= 0,after + must <=100)"<<endl;
				cin>>a4;
				if (a3==2)
				{
					while (a4>=rate)
					{
						cout<<"the number is wrong.please write again."<<endl;
						cout<<"write the number (after - must >= 0,after + must <=100)"<<endl;
						cin>>a4;
					}
					rate-=a4;
				}
				else
				{
					while (a4+rate>100)
					{
						cout<<"the number is wrong.please write again."<<endl;
						cout<<"write the number (after - must >= 0,after + must <=100)"<<endl;
						cin>>a4;
					}
					rate+=a4;
				}
				
			}
			else	cout<<"you have no points to do that."<<endl;
		}
		//外交
		if (a1==7)
		{
			if (point>=2)
			{
				cout<<"write your use money."<<endl;
				cin>>a3;
				if (a3>money)	cout<<"please write again."<<endl;
				else
				{
					cout<<"your country's people mind will add."<<endl;
					if (mind<95&&mind>=90) mind+=3;
					if (mind<90&&mind>=80) mind+=7;
					if (mind<80) mind+=10;
				}
			}
			else	cout<<"you have no points to do that."<<endl;
		}
		//随机事件
		if (a1==8)
		{
			if (point>=3)
			{
				cout<<"write the random number.(the number must >100)"<<endl;
				cin>>a3;
				a3=(a3%10*2%7*3%9+1)%3;
				if (a3==1)
				{
					cout<<"a major earthquake has struck your country,causing half of the money to be lost."<<endl;
					money=money/2;
				}
				if (a3==2)
				{
					cout<<"you have received assistance,with 500 more food and 1000 more money."<<endl;
					food+=500;
					money+=1000;
				}
				if (a3==0)
				{
					cout<<"people are dissatisfied with your governance,and their morale has decreased."<<endl;
					mind-=8;
				}
			}
			else	cout<<"you have no points to do that."<<endl;
		}
		//勘察敌情 
		if (a1==9)	cout<<"sorry,the part can't use now."<<endl;
		if (a1==10)	point=0;
		if (a1==11)
		{
			cout<<"have a good time"<<endl;
			exit(0);
		}
	}
	if (rate>10&&rate<25)
				{
					cout<<"the rate is too big!!!"<<endl;
					mind-=10;
				}
				if (rate>=25&&rate<50)
				{
					cout<<"the rate is too big!!!"<<endl;
					mind-=20;
				}
				if (rate>=50)
				{
					cout<<"the rate is too big!!!"<<endl;
					mind-=40;
				}
	food+=(people-soldiers)*2;
	if (people>food)
	{
		cout<<"this year,"<<people-food<<"people die because they have no food." <<endl;
		people=food;
		mind-=10;
	} 
	food-=people;
	people+=100;
	money=(people-soldiers)*500/rate;
	if (people<20)
	{
	cout<<"your country is end."<<endl<<"\033[31mgame over\033[0m"<<endl;
	exit(0);
	}
	if (year==100)
	{
	cout<<"\033[31myour country has been established for 100 years and will continue to prosper in the future.you win.\033[0m"<<endl;
	exit(0);
	}
	if (mind>=10&&mind<20)
	{
		cout<<"\033[31mcaution!!!:your country's people mind is too low\033[0m"
			<<"your country has suffered an uprising,which has failed.the number of soldiers and people has been halved."
			<<endl;
		people=people/2;
		soldiers=soldiers/2;
	}
	if (mind<10)
	{
		cout<<"\033[31mcaution!!!:your country's people mind is too low\033[0m"
			<<"your country has suffered an uprising.uprising win,your country is end."
			<<endl;
		exit(0);
	}
	cout<<"<any key to next year>";
	cin>>a1;
 }
}


int main()
{
int end,result,x1;
end=0;
cout<<"                                                              "
	  "         Empire          " 
	<<endl;
cout<<"                                                   "
	  "          English:stardusts Chinese:no          "
	<<endl;
cout<<"                               "
	  "                             "
	  "\033[31mAll rights reserved. Piracy will be prosecuted\033[0m"
	  "                                   "
	<<endl;
cout<<"                                         "
	  "                    "
	  "one player<1>  two player<2>"
	  "                       "
	<<endl;
cin>>x1;
if (x1==1)
{
	player_one(end);
}
else
{
	cout<<"sorry,the part is not open now."<<endl;
}
return 0;
}

  • 11
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值