HUST Online Judge WebBoard
Problem 128732 >> 古代战争模拟器(v.05.07.004).cpp(优化版)
zhaodongqiang @ 2025-08-31 10:20:16
[ Quote ] [ Edit ] [ Delete ] 1#
#include<bits/stdc++.h>
#include<Windows.h>
using namespace std;
int fy,gj;
int zdq;
long long f=500;
int jdxr=100;
int i;
string x;
int q;
int t;
int rq=2;
int r=3000;
int w=rand();
int bt;
int xr;
double qw;
int tre;
int sq=100;
void dfs(int in){
if(in==1){
f=f-300;
}
while(f>0&&r>=0&&sq>=50){
cout<<"公元"<<rq<<"年"<<endl<<endl;
cout<<"军队人数:"<<f<<" 钱数:"<<r<<" 攻击:"<<gj<<" 防御:"<<fy<<" 士气: "<<sq<<endl<<endl;
cout<<"你选择 1.招兵买马(增加军队200人) 2.进攻它地(概率领土扩大,士气增加 否则军队伤亡,士气减少) 3.搞钱 4.商城"<<endl<<endl;
cin>>t;
int zdq=0;
if(t==1){
cout<<"你获得了200人"<<endl<<endl;
cout<<"军队增加到"<<f+200<<"人"<<endl<<endl;
f=f+200;
cout<<"钱数减少1000"<<endl<<endl;
cout<<"钱数减少到"<<r-1000<<endl<<endl;
r=r-1000;
Sleep(3000);
}else if(t==2){
if(w%2!=0){
cout<<"你战胜了!"<<endl<<endl;
cout<<"你获得了2000元,100人"<<endl<<endl;
r=r+2000;
f=f+100;
Sleep(3000);
zdq++;
sq=sq+20;
if(zdq==100){
cout<<"游戏胜利!!!"<<endl<<endl;
cout<<"感谢您的游玩!!!"<<endl<<endl;
cout<<"再见!!!"<<endl;
break;
}
}else{
cout<<"你战败了"<<endl<<endl;
cout<<"军队减少1000"<<endl<<endl;
f=f-1000;
sq=sq-30;
Sleep(3000);
}
}else if(t==3){
cout<<"你要投资药品吗?"<<endl<<endl;
cout<<"1.投 2.不投"<<endl<<endl;
cin>>bt;
if(bt==1){
cout<<"输入你要投多少"<<endl<<endl;
cin>>qw;
if(qw>r){
cout<<"拜拜"<<endl<<endl;
Sleep(3000);
break;
}else{
if(xr<=100){
r=r-qw;
cout<<"投的钱数*1.5"<<endl<<endl;
qw=qw*1.5;
r=r+qw;
}else{
r=r-qw;
cout<<"投的钱数/1.5"<<endl<<endl;
qw=qw/1.5;
r=r+qw;
}
}
}else if(bt==2){
cout<<"6"<<endl<<endl;
}else if(t==4){
cout<<"欢迎来到商城"<<endl<<endl;
cout<<"在这里你可以买到你需要的东西"<<endl<<endl;
cout<<"1.防具 1000元(增加1000防御) 2.武器 10000元(增加5000攻击) 3.返回"<<endl<<endl;
cin>>tre;
if(tre==1){
if(r>=1000){
cout<<"购买成功!!!"<<endl<<endl;
r=r-1000;
fy=fy+1000;
Sleep(3000);
system("cls");
}else{
cout<<"抱歉你的钱数不够,购买失败......"<<endl<<endl;
Sleep(3000);
system("cls");
}
zhaodongqiang @ 2025-08-31 10:20:30
[ Quote ] [ Edit ] [ Delete ] 2#
}else if(tre==2){
if(r>=10000){
cout<<"购买成功!!!"<<endl<<endl;
Sleep(3000);
system("cls");
r=r-10000;
gj=gj+5000;
}else{
cout<<"抱歉你的钱数不够,购买失败......"<<endl<<endl;
Sleep(3000);
system("cls");
}
}else if(t==3){
}
}else{
cout<<"抱歉,输入错误,结束游戏!"<<endl<<endl;
Sleep(3000);
break;
}
}else{
cout<<"抱歉,输入错误,结束游戏!"<<endl<<endl;
Sleep(3000);
break;
}
rq++;
system("cls");
jdxr--;
if(jdxr<=0){
break;
}
}
if(f==0){
cout<<endl<<"您的军队全部战亡"<<endl;
}else if(r<0){
cout<<endl<<"您破产了"<<endl;
}else if(sq<50){
cout<<endl<<"士气过低,士兵叛乱,你被叛军活捉后惨遭杀害"<<endl;
}
system("cls");
cout<<"游戏失败"<<endl;
}
int main() {
cout<<"欢迎进入古代战争模拟器(v.07.03.094).cpp版本 "<<endl;
Sleep(3000);
system("cls");
cout<<"本游戏由恒远工作室制作(室长:赵东强)"<<endl<<endl;
Sleep(3000);
system("cls");
cout<<"开始加载游戏......"<<endl;
Sleep(2000);
system("cls");
for(i=1;i<=70;i+=(rand()%5+1)){
printf("加载中%d%%",i);
system("cls");
}
for(i=i+1;i<=98;i++){
printf("加载中%d%%",i);
Sleep(200);
system("cls");
}
printf("加载中99%%");
Sleep(3000);
system("cls");
printf("加载成功!");
Sleep(2000);
system("cls");
cout<<"请输入你的姓"<<endl<<endl;
cin>>x;
cout<<endl;
system("cls");
cout<<"公元1年"<<endl<<endl;
cout<<"你联合自家兵团创建了"<<x<<"家军"<<endl<<endl;
cout<<x<<"家军"<<"共有"<<f<<"人"<<endl<<endl;
cout<<"请选择你要攻打的城市"<<endl<<endl;
cout<<"1.合肥(守兵2000人) 2.长丰(守兵1000人) 3.黄山(守兵200人)"<<endl<<endl;
cin>>q;
cout<<endl;
zhaodongqiang @ 2025-08-31 10:20:41
[ Quote ] [ Edit ] [ Delete ] 3#
if(q==1){
cout<<"你领兵500向合肥进攻"<<endl<<endl;
Sleep(3000);
cout<<"你惨遭战败,兵团500人全部阵亡"<<endl<<endl;
Sleep(3000);
cout<<"你被敌人活捉后惨遭杀害"<<endl<<endl;
Sleep(3000);
system("cls");
cout<<"游戏失败"<<endl<<endl;
}else if(q==2){
cout<<"你领兵500向长丰进攻"<<endl<<endl;
Sleep(3000);
cout<<"你惨遭战败,兵团500人阵亡300人"<<endl<<endl;
Sleep(3000);
cout<<"你领军撤退"<<endl<<endl;
Sleep(3000);
system("cls");
sq=sq-30;
dfs(1);
}else if(q==3){
cout<<"你领兵500向黄山进攻"<<endl<<endl;
Sleep(3000);
cout<<"你战胜敌方,兵团500人"<<endl<<endl;
Sleep(3000);
cout<<"你领军撤退"<<endl<<endl;
Sleep(3000);
system("cls");
sq=sq+30;
dfs(2);
}
return 0;
}
zhaodongqiang @ 2025-08-31 10:24:08
[ Quote ] [ Edit ] [ Delete ] 4#
用函数优化了一下,代码量减少了不少
zhaodongqiang @ 2025-08-31 10:33:16
[ Quote ] [ Edit ] [ Delete ] 5#
论滑动解锁
luoen @ 2025-09-03 19:33:31
[ Quote ] [ Edit ] [ Delete ] 6#
666
yuzihao @ 2025-09-06 08:26:44
[ Quote ] [ Edit ] [ Delete ] 7#
666
qianzixuan @ 2025-09-19 17:32:03
[ Quote ] [ Edit ] [ Delete ] 8#
《外挂》已窃入
qianzixuan @ 2025-09-19 17:32:03
[ Quote ] [ Edit ] [ Delete ] 9#
《外挂》已窃入
yuzihao @ 2025-10-02 17:21:24
[ Quote ] [ Edit ] [ Delete ] 10#
chenyuxiang @ 2025-10-03 11:54:23
[ Quote ] [ Edit ] [ Delete ] 11#
666,盐都不盐了
huangzichen @ 2025-10-03 15:52:03
[ Quote ] [ Edit ] [ Delete ] 12#
6666
huangzichen @ 2025-10-03 15:52:48
[ Quote ] [ Edit ] [ Delete ] 13#
@罗恩