相比较 1.2 ,增加了升级模块
C++战列舰小游戏Lv. 1.2版本(半成品)-CSDN博客
相比较1.3,有了大规模完善和模块增加
C++战列舰小游戏Lv. 1.3版本(半成品)-CSDN博客
这是一组初始数据:
a[1].gas=1000;
a[1].attack=0;
a[1].att_1=0;
a[1].att_2=0;
a[1].att_3=0;
a[1].att_4=0;
a[1].fire=0;
a[1].gas_good=0.9;
a[1].guard=0;
a[1].HP=15000;
a[1].name="初级战列舰";
a[1].HPm=15000;
a[1].gasm=1200;
a[1].boat[40][15]=100;
a[1].long_=70;
a[1].att_s_1=0;
a[1].att_good_1=10;
a[1].att_good_2=40;
a[1].att_good_3=15;
a[1].att_good_4=80;
a[1].Lv=1;
cpp
a[1].gas=1000;
a[1].attack=0;
a[1].att_1=0;
a[1].att_2=0;
a[1].att_3=0;
a[1].att_4=0;
a[1].fire=0;
a[1].gas_good=0.9;
a[1].guard=0;
a[1].HP=15000;
a[1].name="初级战列舰";
a[1].HPm=15000;
a[1].gasm=1200;
a[1].boat[40][15]=100;
a[1].long_=70;
a[1].att_s_1=0;
a[1].att_good_1=10;
a[1].att_good_2=40;
a[1].att_good_3=15;
a[1].att_good_4=80;
a[1].Lv=1;
这是战舰的结构体
struct zhan
{
string name;
int attack,guard;//攻击 防御
int att_1,att_2,att_3,att_4;//主炮 副炮 鱼雷 水雷
int att_s_1,att_s_2;
double att_good_1,att_good_2,att_good_3,att_good_4;
double HP,fire,HPm;
double shut_down[100],gas_good;
int gas,gasm;
double boat[150][40];
double long_;
double Lv;
};
cpp
struct zhan
{
string name;
int attack,guard;//攻击 防御
int att_1,att_2,att_3,att_4;//主炮 副炮 鱼雷 水雷
int att_s_1,att_s_2;
double att_good_1,att_good_2,att_good_3,att_good_4;
double HP,fire,HPm;
double shut_down[100],gas_good;
int gas,gasm;
double boat[150][40];
double long_;
double Lv;
};
这是染色函数(特别致谢博主:夜若渊)
void pr(const char* s, int color)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | color);
printf(s);
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | 7);
}
/*
0 = 黑色 8 = 灰色
1 = 蓝色 9 = 淡蓝色
2 = 绿色 10 = 淡绿色
3 = 浅绿色 11 = 淡浅绿色
4 = 红色 12 = 淡红色
5 = 紫色 13 = 淡紫色
6 = 黄色 14 = 淡黄色
7 = 白色 15 = 亮白色
*/
cpp
void pr(const char* s, int color)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | color);
printf(s);
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | 7);
}
/*
0 = 黑色 8 = 灰色
1 = 蓝色 9 = 淡蓝色
2 = 绿色 10 = 淡绿色
3 = 浅绿色 11 = 淡浅绿色
4 = 红色 12 = 淡红色
5 = 紫色 13 = 淡紫色
6 = 黄色 14 = 淡黄色
7 = 白色 15 = 亮白色
*/
新手指南
void new_do()
{
system("cls");
Sleep(50);
cout<<setw(50)<<"----------新手指南----------"<<'\n';
cout<<"敌方会有1~3艘 旗舰(战列舰) ";
cout<<"它们的正面装甲级厚,尽量使用鱼雷或在侧面使用主炮攻击"<<'\n';
cout<<"敌方会有3~10艘副舰(驱逐舰、护卫舰)"<<'\n';
cout<<"它们防空能力强悍,副炮数量极多,就连战机都很难靠近它们,想办法用潜艇鱼雷攻击它们"<<'\n';
cout<<"敌方可能会有潜艇,如果你没有反潜设备就要小心了,它们不会出现在《战舰清单》中"<<'\n';
cout<<"你在开始游戏时会有1艘(几乎)空荡荡的战列舰"<<'\n';
cout<<"你可以在 加工厂 升级战舰"<<'\n';
cout<<"你可以在 制造厂 制造战列舰(的空壳,几乎啥都没有)"<<'\n';
cout<<"提示"<<'\n';
cout<<"战列舰的所有数据都在 战舰情况 中,随时可以查看"<<'\n';
cout<<"刚开始你会有 4000w 资金,到了游戏中你就会知道,这远远不够"<<'\n';
cout<<"这是战列舰时代的游戏,没有导弹"<<'\n';
system("pause");
}
cpp
void new_do()
{
system("cls");
Sleep(50);
cout<<setw(50)<<"----------新手指南----------"<<'\n';
cout<<"敌方会有1~3艘 旗舰(战列舰) ";
cout<<"它们的正面装甲级厚,尽量使用鱼雷或在侧面使用主炮攻击"<<'\n';
cout<<"敌方会有3~10艘副舰(驱逐舰、护卫舰)"<<'\n';
cout<<"它们防空能力强悍,副炮数量极多,就连战机都很难靠近它们,想办法用潜艇鱼雷攻击它们"<<'\n';
cout<<"敌方可能会有潜艇,如果你没有反潜设备就要小心了,它们不会出现在《战舰清单》中"<<'\n';
cout<<"你在开始游戏时会有1艘(几乎)空荡荡的战列舰"<<'\n';
cout<<"你可以在 加工厂 升级战舰"<<'\n';
cout<<"你可以在 制造厂 制造战列舰(的空壳,几乎啥都没有)"<<'\n';
cout<<"提示"<<'\n';
cout<<"战列舰的所有数据都在 战舰情况 中,随时可以查看"<<'\n';
cout<<"刚开始你会有 4000w 资金,到了游戏中你就会知道,这远远不够"<<'\n';
cout<<"这是战列舰时代的游戏,没有导弹"<<'\n';
system("pause");
}
完整半成品代码:
cpp
#include <bits/stdc++.h>
#include <time.h>
#include <windows.h>
#include <stdlib.h>
#include <unistd.h>
#include <conio.h>
#include <fstream>
#include <random>
using namespace std;
bool sea;
int km=0;
bool look[100][100];
long long money=4000000000;
int shuliang=1;
struct zhan
{
string name;
int attack,guard;//攻击 防御
int att_1,att_2,att_3,att_4;//主炮 副炮 鱼雷 水雷
int att_s_1,att_s_2;
int att_good_1,att_good_2,att_good_3,att_good_4;
double HP,fire,HPm;
double shut_down[20];
int gas_good;
int gas,gasm;
int boat[90][40];
int long_;
double Lv;
bool go;
int lx,ly;
int jiao;
double en_1,en_2,en_3,EPU;
};
zhan a[50];
zhan lmap[300][300];
void pr(const char* s, int color)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | color);
printf(s);
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | 7);
}
/*
0 = 黑色 8 = 灰色
1 = 蓝色 9 = 淡蓝色
2 = 绿色 10 = 淡绿色
3 = 浅绿色 11 = 淡浅绿色
4 = 红色 12 = 淡红色
5 = 紫色 13 = 淡紫色
6 = 黄色 14 = 淡黄色
7 = 白色 15 = 亮白色
*/
void new_do()
{
system("cls");
Sleep(50);
cout<<setw(50)<<"----------新手指南----------"<<'\n';
cout<<"敌方会有1~3艘 旗舰(战列舰) ";
cout<<"它们的正面装甲级厚,尽量使用鱼雷或在侧面使用主炮攻击"<<'\n';
cout<<"敌方会有3~10艘副舰(驱逐舰、护卫舰)"<<'\n';
cout<<"它们防空能力强悍,副炮数量极多,就连战机都很难靠近它们,想办法用潜艇鱼雷攻击它们";
cout<<'\n';
cout<<"敌方可能会有潜艇,如果你没有反潜设备就要小心了,它们不会出现在《战舰清单》中"<<'\n';
cout<<"你在开始游戏时会有1艘(几乎)空荡荡的战列舰"<<'\n';
cout<<"你可以在 加工厂 升级战舰"<<'\n';
cout<<"你可以在 制造厂 制造战列舰(的空壳,几乎啥都没有)"<<'\n';
cout<<"提示"<<'\n';
cout<<"战列舰的所有数据都在 战舰情况 中,随时可以查看"<<'\n';
cout<<"刚开始你会有 4000w 资金,到了游戏中你就会知道,这远远不够"<<'\n';
cout<<"这是战列舰时代的游戏,没有导弹"<<'\n';
system("pause");
}
void fight()
{
int xz;
cout<<"输入出航的船只(结束输入 其他数字 )"<<'\n';
for(int i=1; i<=shuliang; i++)
{
cout<<i<<" "<<a[i].name;
if(a[i].gas>0) pr(" 可以出战",2);
else pr(" 缺少燃油",4);
if(a[i].attack==0) pr(" 无战斗力",6);
else pr("战斗力:",2),cout<<a[i].attack;
cout<<'\n';
}
while(cin>>xz&&xz<=shuliang&&xz>=1)
{
a[xz].go=true;
}
cout<<"确认:"<<'\n';
for(int i=1; i<=shuliang; i++)
{
if(a[i].go==true)
{
cout<<a[i].name;
if(a[i].gas>0) pr(" 可以出战",2);
else pr(" 缺少燃油",4);
if(a[i].attack==0) pr(" 无战斗力",6);
else pr("战斗力:",2),cout<<a[i].attack;
cout<<'\n';
}
}
cout<<'\n';
system("pause");
int ling1;
string ling2;
while(ling1!=-1&&ling2!="-1")
{
cout<<"请输入指令- 按 0 0 查看您的指令输入方法"<<'\n';
cin>>ling1>>ling2;
if(ling2=="0"&&ling1==0)
{
cout<<"指令1 :编号+' '+w(小写) >>选中舰前进 例:1 w";
cout<<" 在一轮相同战舰中,该指令只能使用一次"<<'\n';
cout<<"指令2 :编号+' '+a(小写)+' '+左转角度 >>选中舰左转 例:1 a 30 角度越小,";
cout<<"转速越快"<<'\n';
cout<<"指令3 :编号+' '+d(小写)+' '+右转角度 >>选中舰右转 例:1 d 30 角度越小,";
cout<<"转速越快"<<'\n';
cout<<"指令4 :编号+' '+q(小写) >>打开雷达"<<'\n';
cout<<"指令5 :编号+' '+e(小写) >>关闭雷达"<<'\n';
cout<<"指令6 :编号+' '+x(小写)+' '+敌方编号 >>向敌方开火"<<'\n';
cout<<"指令7 :编号+' '+c(小写) >>选中舰加速"<<'\n';
pr("指令7 :-1 -1 >>回航",2);
cout<<'\n';
system("pause");
}
if(ling2=="w")
{
a[ling1].en_1+=10;
a[ling1].en_1+=10;
if(a[ling1].en_1>0&&a[ling1].en_2>0)
{
if(a[ling1].jiao>=1&&a[ling1].jiao<=90)
{
a[ling1].lx+=(a[ling1].en_1+a[ling1].en_2)*cos(a[ling1].jiao*M_PI/180)/100;
a[ling1].ly+=(a[ling1].en_1+a[ling1].en_2)*sin(a[ling1].jiao*M_PI/180)/100;
a[ling1].EPU+=5;
}
else if(a[ling1].jiao>90&&a[ling1].jiao<=180)
{
a[ling1].lx-=(a[ling1].en_1+a[ling1].en_2)*cos((180-a[ling1].jiao)*M_PI/180)/100;
a[ling1].ly+=(a[ling1].en_1+a[ling1].en_2)*sin((180-a[ling1].jiao)*M_PI/180)/100;
a[ling1].EPU+=5;
}
else if(a[ling1].jiao>180&&a[ling1].jiao<=270)
{
a[ling1].lx-=(a[ling1].en_1+a[ling1].en_2)*cos((a[ling1].jiao-180)*M_PI/180)/100;
a[ling1].ly-=(a[ling1].en_1+a[ling1].en_2)*sin((a[ling1].jiao-180)*M_PI/180)/100;
a[ling1].EPU+=5;
}
else if(a[ling1].jiao>270&&a[ling1].jiao<=360)
{
a[ling1].lx+=(a[ling1].en_1+a[ling1].en_2)*cos((360-a[ling1].jiao)*M_PI/180)/100;
a[ling1].ly-=(a[ling1].en_1+a[ling1].en_2)*sin((360-a[ling1].jiao)*M_PI/180)/100;
a[ling1].EPU+=35;
}
a[ling1].EPU+=5;
}
cout<<"坐标x:"<<a[ling1].lx<<" "<<"坐标y:"<<a[ling1].ly<<'\n';
}
if(ling2=="a")
{
double jiao;
cin>>jiao;
Sleep(jiao);
}
random_device rd;
default_random_engine e(rd());
uniform_int_distribution<int> dist(0,3);
random_device rd2;
default_random_engine k(rd2());
uniform_int_distribution<int> dist2(0,4);
int sj=dist(e);
if(sj==0)//战斗
{
sj=dist(e);
if(sj==0)
{
sj=dist(e)+3;
int dishu=sj;
for(int i=1; i<=dishu; i++)
{
int lx=95+i+dist(e),ly=70-i*2;
lmap[lx][ly].lx=lx,lmap[lx][ly].ly=ly;
lmap[lx][ly].name="敌";
int sj=dist2(k);
random_device rd;
default_random_engine l(rd());
uniform_int_distribution<int> dist(0,4);
if(sj==0)
{
lmap[lx][ly].name=lmap[lx][ly].name+"战列舰";
}
else if(sj==1)
{
lmap[lx][ly].name=lmap[lx][ly].name+"驱逐舰";
}
else if(sj==2)
{
lmap[lx][ly].name=lmap[lx][ly].name+"护卫舰";
}
else if(sj==3)
{
lmap[lx][ly].name=lmap[lx][ly].name+"巡洋舰";
}
else
{
lmap[lx][ly].name=lmap[lx][ly].name+"潜艇";
}
pr("敌方目标: x:",4);
cout<<lx<<" ";
pr("y:",4);
pr(" 血量值:",4);
}
}
}
else if(sj==1)
{
}
else if(sj==2)
{
}
else if(sj==3)
{
}
for(int i=1; i<=shuliang; i++)
{
if(a[i].HP<=0)
{
system("color 04");
cout<<a[i].name;
pr("被敌方击沉!",4);
cout<<'\n';
}
}
system("color 0F");
}
}
void up_gas()
{
cout<<"这里是加油站----------"<<'\n';
for(int i=1; i<=shuliang; i++)
{
Sleep(500);
system("cls");
cout<<i<<" "<<a[i].name<<":"<<a[i].gas<<"/"<<a[i].gasm<<'\n';
cout<<" 可以航行"<<a[i].gas*a[i].gas_good<<"km (需要在"<<a[i].gas*a[i].gas_good/2.0<<"km返回)";
cout<<'\n';
if(a[i].gas==0) pr("必须加油",4);
else if(a[i].gas>0&&a[i].gas!=a[i].gasm) pr("可以加油",6);
else pr("无需加油",2);
cout<<"(y/n)"<<'\n';
string xz;
cin>>xz;
if(xz=="y"||xz=="Y")
{
cout<<"正在加油..."<<'\n';
system("pause");
Sleep(500);
if(a[i].gasm==a[i].gas) cout<<"无需加油--"<<'\n';
else
{
long long money_want=(a[i].gasm-a[i].gas)/(a[i].gas_good)*600;
cout<<"需要"<<money_want<<"资金"<<'\n';
if(money_want>money)
{
cout<<"资金不足,为您尽量加油↖(^ω^)↗"<<'\n';
a[i].gas=a[i].gas+money/600*a[i].gas_good;
money=0;
}
else
{
money-=money_want;
a[i].gas=a[i].gasm;
}
cout<<"加油完成---"<<'\n';
cout<<i<<" "<<a[i].name<<":"<<a[i].gas<<"/"<<a[i].gasm<<'\n';
cout<<" 可以航行"<<a[i].gas/a[i].gas_good<<"km (需要在"<<a[i].gas/a[i].gas_good/2.0<<"km返回)";
cout<<'\n';
if(a[i].gas==0) pr("必须加油",4);
else if(a[i].gas>0&&a[i].gas!=a[i].gasm) pr("可以加油",6);
else pr("无需加油",2);
cout<<'\n';
}
}
else
{
cout<<'\n';
system("pause");
}
}
cout<<'\n';
system("pause");
}
void up_on1()
{
for(int i=1; i<=shuliang; i++)
{
cout<<i<<" "<<a[i].name<<": Lv. "<<a[i].Lv<<'\n';
a[i].HP=a[i].HPm;
cout<<"0 不升级 下一个"<<'\n';
cout<<"1 血量:"<<a[i].HP<<" / "<<a[i].HPm<<'\n';
cout<<"2 油量:"<<a[i].gas<<" / "<<a[i].gasm<<'\n';
cout<<"3 燃油等级:"<<a[i].gas_good<<"/1 (越小越好)"<<'\n';
cout<<"4 长度:"<<a[i].long_<<"m"<<'\n';
cout<<"5 主炮数量:"<<a[i].att_1<<'\n';
cout<<"6 精准度:"<<a[i].att_good_1<<"%"<<'\n';
cout<<"7 副炮数量:"<<a[i].att_2<<'\n';
cout<<"8 精准度:"<<a[i].att_good_2<<"%"<<'\n';
cout<<"9 鱼雷精准度:"<<a[i].att_good_3<<"%"<<'\n';
cout<<"10 水雷精准度:"<<a[i].att_good_4<<"%"<<'\n';
cout<<'\n';
system("pause");
short k;
cin>>k;
double l;
switch(k)
{
case 0:
break;
case 1:
cout<<"血量升级价格:2点/资金 等级≥5时 5点/资金"<<'\n';
cout<<"购买血量(最大";
if(a[i].Lv>=5) cout<<money*5,l=money*5;
else cout<<money*2,l=money*2;
cout<<") : ";
double xz;
cin>>xz;
while(xz>l) cout<<"Error!",cin>>xz;
if(a[i].Lv>=5) l=xz*5;
else l=xz*2;
money-=l;
a[i].HPm+=xz;
break;
case 2:
cout<<"油量升级价格:1点/资金 等级≥10时 2点/资金"<<'\n';
cout<<"购买油量(最大";
if(a[i].Lv>=5) cout<<money*1,l=money*1;
else cout<<money,l=money;
cout<<") : ";
cin>>xz;
while(xz>l) cout<<"Error!",cin>>xz;
if(a[i].Lv>=10) l=xz*2;
else l=xz;
money-=l;
a[i].gasm+=xz;
break;
case 3:
cout<<"90w变为1(需要将该舰现有油量清零)"<<'\n';
if(money>=900000) a[i].gas_good=1,a[i].gas=0,money-=900000;
else system("pause");
a[i].Lv+=1;
break;
case 4:
cout<<"长度升级价格:5w/m"<<'\n';
cout<<"购买长度(最大";
cout<<fixed<<setprecision(2)<<money/5.0,l=money/5.0;
cout<<") : ";
cin>>xz;
while(xz>l) cout<<"Error!",cin>>xz;
l=xz*50000;
money-=l;
a[i].long_+=xz;
a[i].Lv+=xz*0.1;
break;
case 5:
if(a[i].long_-a[i].att_1*2-a[i].att_2*2-a[i].att_1*1-a[i].att_1*1-a[i].gasm/100<2)
{
cout<<"甲板不够,去加长甲板吧"<<'\n';
}
else
{
cout<<"口径:1 80mm 10w"<<'\n';
cout<<" 2 95mm 12w"<<'\n';
cout<<" 3 110mm 20w"<<'\n';
cout<<" 4 160mm 50w"<<'\n';
cout<<" 5 320mm 90w"<<'\n';
}
int kj;
cin>>kj;
if(kj==1)
{
a[i].att_1++;
a[i].attack+=80;
a[i].Lv+=0.1;
money-=100000;
}
if(kj==2)
{
a[i].att_1++;
a[i].attack+=95;
a[i].Lv+=0.2;
money-=120000;
}
if(kj==3)
{
a[i].att_1++;
a[i].attack+=110;
a[i].Lv+=0.3;
money-=200000;
}
if(kj==4)
{
a[i].att_1++;
a[i].attack+=160;
a[i].Lv+=0.5;
money-=500000;
}
if(kj==5)
{
a[i].att_1++;
a[i].attack+=320;
a[i].Lv+=1;
money-=900000;
}
break;
case 6:
cout<<"精准度升级为 5000资金/ 0.1%"<<'\n';
cout<<"输入投入资金:";
int mon;
cin>>mon;
money-=mon;
a[i].att_good_1+=mon*1.0/5000.0;
a[i].Lv+=0.01*mon*1.0/5000.0;
break;
case 7:
if(a[i].long_-a[i].att_1*2-a[i].att_2*2-a[i].att_1*1-a[i].att_1*1-a[i].gasm/100<1)
{
cout<<"甲板不够,去加长甲板吧"<<'\n';
}
else
{
cout<<"口径:1 10mm 10w"<<'\n';
cout<<" 2 25mm 12w"<<'\n';
cout<<" 3 50mm 20w"<<'\n';
cout<<" 4 60mm 50w"<<'\n';
cout<<" 5 70mm 90w"<<'\n';
cin>>kj;
if(kj==1)
{
a[i].att_2++;
a[i].attack+=10;
money-=100000;
}
if(kj==2)
{
a[i].att_2++;
a[i].attack+=25;
money-=120000;
}
if(kj==3)
{
a[i].att_2++;
a[i].attack+=50;
money-=200000;
}
if(kj==4)
{
a[i].att_2++;
a[i].attack+=60;
money-=500000;
}
if(kj==5)
{
a[i].att_2++;
a[i].attack+=70;
money-=900000;
}
a[i].Lv=a[i].Lv+0.1*kj;
}
break;
/*
cout<<"8 精准度:"<<a[i].att_good_2<<"%"<<'\n';
cout<<"9 鱼雷精准度:"<<a[i].att_good_3<<"%"<<'\n';
cout<<"10 水雷精准度:"<<a[i].att_good_4<<"%"<<'\n';
*/
case 8:
cout<<"精准度升级为 5000资金/ 0.1%"<<'\n';
cout<<"输入投入资金:";
cin>>mon;
money-=mon;
a[i].att_good_2+=mon/5000;
a[i].Lv=a[i].Lv+=mon/5000;
break;
case 9:
cout<<"精准度升级为 5000资金/ 0.1%"<<'\n';
cout<<"输入投入资金:";
cin>>mon;
money-=mon;
a[i].att_good_3+=mon/5000;
break;
case 10:
cout<<"精准度升级为 5000资金/ 0.1%"<<'\n';
cout<<"输入投入资金:";
cin>>mon;
money-=mon;
a[i].att_good_4+=mon/5000;
break;
}
}
}
void up_build()
{
int xz;
cout<<"需要:"<<'\n';
cout<<"1 驱逐舰 7500w"<<'\n';
cout<<"2 护卫舰 7500w"<<'\n';
cout<<"3 巡洋舰 8000w"<<'\n';
cout<<"4 战列舰 9500w"<<'\n';
cout<<"5 潜艇 7000w"<<'\n';
cout<<"6 弹药"<<'\n';
cin>>xz;
string namel;
if(xz==1)
{
money-=75000000;
cout<<"名字:";
while(cin>>namel)
{
int f=1;
for(int i=1; i<=shuliang; i++)
{
if(a[i].name==namel)
{
f=0;
cout<<"已有重复名称"<<'\n';
}
}
if(f==1) break;
}
a[shuliang+1].gas=500;
a[shuliang+1].attack=0;
a[shuliang+1].att_1=0;
a[shuliang+1].att_2=0;
a[shuliang+1].att_3=0;
a[shuliang+1].att_4=0;
a[shuliang+1].fire=0;
a[shuliang+1].gas_good=10;
a[shuliang+1].guard=0;
a[shuliang+1].HP=6000;
a[shuliang+1].name=namel;
a[shuliang+1].HPm=6000;
a[shuliang+1].gasm=700;
a[shuliang+1].boat[40][15]=100;
a[shuliang+1].long_=40;
a[shuliang+1].att_s_1=0;
a[shuliang+1].att_good_1=50;
a[shuliang+1].att_good_2=50;
a[shuliang+1].att_good_3=95;
a[shuliang+1].att_good_4=90;
a[shuliang+1].Lv=1;
shuliang++;
}
if(xz==2)
{
money-=75000000;
cout<<"名字:";
while(cin>>namel)
{
int f=1;
for(int i=1; i<=shuliang; i++)
{
if(a[i].name==namel)
{
f=0;
cout<<"已有重复名称"<<'\n';
}
}
if(f==1) break;
}
a[shuliang+1].gas=500;
a[shuliang+1].attack=0;
a[shuliang+1].att_1=0;
a[shuliang+1].att_2=0;
a[shuliang+1].att_3=0;
a[shuliang+1].att_4=0;
a[shuliang+1].fire=0;
a[shuliang+1].gas_good=10;
a[shuliang+1].guard=0;
a[shuliang+1].HP=7000;
a[shuliang+1].name=namel;
a[shuliang+1].HPm=7000;
a[shuliang+1].gasm=900;
a[shuliang+1].boat[40][15]=100;
a[shuliang+1].long_=40;
a[shuliang+1].att_s_1=0;
a[shuliang+1].att_good_1=60;
a[shuliang+1].att_good_2=60;
a[shuliang+1].att_good_3=75;
a[shuliang+1].att_good_4=82;
a[shuliang+1].Lv=1;
shuliang++;
}
if(xz==3)
{
money-=80000000;
cout<<"名字:";
string namel;
while(cin>>namel)
{
int f=1;
for(int i=1; i<=shuliang; i++)
{
if(a[i].name==namel)
{
f=0;
cout<<"已有重复名称"<<'\n';
}
}
if(f==1) break;
}
a[shuliang+1].gas=1000;
a[shuliang+1].attack=0;
a[shuliang+1].att_1=0;
a[shuliang+1].att_2=0;
a[shuliang+1].att_3=0;
a[shuliang+1].att_4=0;
a[shuliang+1].fire=0;
a[shuliang+1].gas_good=10;
a[shuliang+1].guard=0;
a[shuliang+1].HP=10000;
a[shuliang+1].name=namel;
a[shuliang+1].HPm=10000;
a[shuliang+1].gasm=1200;
a[shuliang+1].boat[40][15]=100;
a[shuliang+1].long_=70;
a[shuliang+1].att_s_1=0;
a[shuliang+1].att_good_1=10;
a[shuliang+1].att_good_2=40;
a[shuliang+1].att_good_3=15;
a[shuliang+1].att_good_4=80;
a[shuliang+1].Lv=1;
shuliang++;
}
if(xz==4)
{
money-=95000000;
cout<<"名字:";
string namel;
while(cin>>namel)
{
int f=1;
for(int i=1; i<=shuliang; i++)
{
if(a[i].name==namel)
{
f=0;
cout<<"已有重复名称"<<'\n';
}
}
if(f==1) break;
}
a[shuliang+1].gas=1000;
a[shuliang+1].attack=0;
a[shuliang+1].att_1=0;
a[shuliang+1].att_2=0;
a[shuliang+1].att_3=0;
a[shuliang+1].att_4=0;
a[shuliang+1].fire=0;
a[shuliang+1].gas_good=10;
a[shuliang+1].guard=0;
a[shuliang+1].HP=15000;
a[shuliang+1].name=namel;
a[shuliang+1].HPm=15000;
a[shuliang+1].gasm=1200;
a[shuliang+1].boat[40][15]=100;
a[shuliang+1].long_=70;
a[shuliang+1].att_s_1=0;
a[shuliang+1].att_good_1=10;
a[shuliang+1].att_good_2=40;
a[shuliang+1].att_good_3=15;
a[shuliang+1].att_good_4=80;
a[shuliang+1].Lv=1;
shuliang++;
}
if(xz==5)
{
money-=70000000;
cout<<"名字:";
while(cin>>namel)
{
int f=1;
for(int i=1; i<=shuliang; i++)
{
if(a[i].name==namel)
{
f=0;
cout<<"已有重复名称"<<'\n';
}
}
if(f==1) break;
}
a[shuliang+1].gas=1500;
a[shuliang+1].attack=0;
a[shuliang+1].att_1=0;
a[shuliang+1].att_2=0;
a[shuliang+1].att_3=0;
a[shuliang+1].att_4=0;
a[shuliang+1].fire=0;
a[shuliang+1].gas_good=10;
a[shuliang+1].guard=0;
a[shuliang+1].HP=1000;
a[shuliang+1].name=namel;
a[shuliang+1].HPm=1000;
a[shuliang+1].gasm=3500;
a[shuliang+1].boat[40][3]=100;
a[shuliang+1].long_=8;
a[shuliang+1].att_s_1=0;
a[shuliang+1].att_good_1=0;
a[shuliang+1].att_good_2=0;
a[shuliang+1].att_good_3=95;
a[shuliang+1].att_good_4=90;
a[shuliang+1].Lv=1;
shuliang++;
}
if(xz==6)
{
for(int i=1; i<=shuliang; i++)
{
cout<<a[i].name;
cout<<"1 主炮弹药数量:";
int l=a[i].att_s_1;
cout<<l<<'\n';
if(l==0) pr("没有弹药 建议增添",4);
else if(l<=30) pr("弹药较少 建议增添",6);
else pr("基本足够(仅为评估)",2);
cout<<'\n';
int want;
cout<<"输入需要弹药(40w/枚)数量:";
cin>>want;
money-=want*400000;
a[i].att_s_1+=want;
cout<<"2 副炮弹药数量:";
l=a[i].att_s_2;
cout<<l<<'\n';
if(l==0) pr("没有弹药 建议增添",4);
else if(l<=30) pr("弹药较少 建议增添",6);
else pr("基本足够(仅为评估)",2);
cout<<'\n';
cout<<"输入需要弹药(40w/枚)数量:";
cin>>want;
money-=want*400000;
a[i].att_s_2+=want;
}
}
cout<<"OK"<<'\n';
return ;
}
void meself()
{
cout<<"以下是个人情况:"<<'\n';
for(int i=1; i<=shuliang; i++)
{
cout<<i<<" "<<a[i].name<<'\n';
a[i].HP=a[i].HPm;
int f=100;
if(a[i].gas<=0) pr("油量警告->必须加油",4),f-=40,cout<<'\n';
else if(a[i].gas<=100) pr("油量警告->需要加油",4),f-=40,cout<<'\n';
else if(a[i].gas<=400) pr("油量警告",6),f-=35,cout<<'\n';
if(a[i].fire==0) pr("舰艇无火灾",2),cout<<'\n';
else if(a[i].fire>0&&a[i].fire<=1.5) pr("舰艇火灾警告",6),f-=0.1,cout<<'\n';
else if(a[i].fire<=5) pr("中等火灾警告",6),f-=5,cout<<'\n';
else if(a[i].fire<=10) pr("最高火灾警告->立即返航/弃船",4),f-=40,cout<<'\n';
cout<<"血量:"<<a[i].HP<<" / "<<a[i].HPm<<'\n';
cout<<"油量:"<<a[i].gas<<" / "<<a[i].gasm<<'\n';
cout<<"长度:"<<a[i].long_<<'\n';
cout<<"主炮数量:"<<a[i].att_1<<'\n';
cout<<"副炮数量:"<<a[i].att_2<<'\n';
cout<<"1 主炮弹药数量:";
int l=a[i].att_s_1;
cout<<l<<'\n';
if(l==0) pr("没有弹药 建议增添",4);
else if(l<=30) pr("弹药较少 建议增添",6);
else pr("基本足够(仅为评估)",2);
cout<<'\n';
cout<<"2 副炮弹药数量:";
l=a[i].att_s_2;
cout<<l<<'\n';
if(l==0) pr("没有弹药 建议增添",4);
else if(l<=30) pr("弹药较少 建议增添",6);
else pr("基本足够(仅为评估)",2);
cout<<'\n';
if(a[i].att_1==0) pr("主炮不足",4),cout<<'\n';
if(a[i].att_2==0) pr("副炮不足",4),cout<<'\n';
if(a[i].att_2==0) pr("鱼雷不足",4),cout<<'\n';
if(a[i].att_2==0) pr("水雷不足",4),cout<<'\n';
cout<<'\n';
}
}
void up()
{
cout<<"1 加油站"<<'\n';
cout<<"2 加工厂"<<'\n';
cout<<"3 制造厂"<<'\n';
cout<<"4 出航" <<'\n';
cout<<"5 查看状态"<<'\n';
string xz;
cin>>xz;
while(xz!="1"&&xz!="2"&&xz!="3"&&xz!="4"&&xz!="5")
{
cout<<"错误--- 请再次输入"<<'\n';
system("pause");
cin>>xz;
}
int xz_int=stoi(xz);
switch(xz_int)
{
case 1:
up_gas();
break;
case 2:
up_on1();
break;
case 3:
up_build();
break;
case 4:
sea=true;
break;
default:
meself();
break;
}
}
void play()
{
shuliang=1;
a[1].gas=1000;
a[1].attack=0;
a[1].att_1=0;
a[1].att_2=0;
a[1].att_3=0;
a[1].att_4=0;
a[1].fire=0;
a[1].gas_good=10;
a[1].guard=0;
a[1].HP=15000;
a[1].name="max fight 1";
a[1].HPm=15000;
a[1].gasm=1200;
a[1].boat[40][15]=100;
a[1].long_=70;
a[1].att_s_1=0;
a[1].att_good_1=10;
a[1].att_good_2=40;
a[1].att_good_3=15;
a[1].att_good_4=80;
a[1].Lv=1;
cout<<"游戏开始"<<'\n';
system("pause");
system("cls");
while(1+1==2)
{
system("cls");
cout<<"游戏进行中----------"<<'\n';
system("pause");
cout<<"资金:"<<money;
if(money<-10000000)
{
cout<<"欠债过多 挑战失败"<<'\n';
return ;
}
if(sea)
{
for(int i=1; i<=shuliang; i++)
{
int f=100;
cout<<a[i].name<<":"<<'\n';
cout<<"该舰艇现在距离基地"<<km<<"km,需要"<<km*a[i].gas_good<<"升燃油"<<'\n';
if(a[i].fire==0) pr("舰艇无火灾",2),cout<<'\n';
else if(a[i].fire>0&&a[i].fire<=1.5) pr("舰艇火灾警告",6),f-=0.1,cout<<'\n';
else if(a[i].fire<=5) pr("中等火灾警告",6),f-=5,cout<<'\n';
else if(a[i].fire<=10) pr("最高火灾警告->立即返航/弃船",4),f-=40,cout<<'\n';
if(km*a[i].gas_good>=a[i].gas*2) pr("最高油量警告->立即返航",4),f-=40,cout<<'\n';
else if(km*a[i].gas_good>=a[i].gas) pr("油量警告",6),f-=35,cout<<'\n';
if(a[i].HP<=100) pr("重伤警告->立即返航/弃船",4),f-=60,cout<<'\n';
else if(a[i].HP<=1000) pr("警告->注意躲避火力",6),f-=20,cout<<'\n';
cout<<"1 主炮弹药数量:";
int l=a[i].att_s_1;
cout<<l<<'\n';
if(l==0) pr("没有弹药 建议增添",4);
else if(l<=30) pr("弹药较少 建议增添",6);
else pr("基本足够(仅为评估)",2);
cout<<'\n';
cout<<"2 副炮弹药数量:";
l=a[i].att_s_2;
cout<<l<<'\n';
if(l==0) pr("没有弹药 建议增添",4);
else if(l<=30) pr("弹药较少 建议增添",6);
else pr("基本足够(仅为评估)",2);
cout<<'\n';
if(a[i].att_1==0) pr("主炮不足",4),cout<<'\n';
if(a[i].att_2==0) pr("副炮不足",4),cout<<'\n';
if(a[i].att_2==0) pr("鱼雷不足",4),cout<<'\n';
if(a[i].att_2==0) pr("水雷不足",4),cout<<'\n';
}
fight();
}
else
{
for(int i=1; i<=shuliang; i++)
{
cout<<i<<" "<<a[i].name<<'\n';
a[i].HP=a[i].HPm;
a[i].fire=0;
a[i].go=false;
a[i].lx=0;
a[i].ly=0;
int f=100;
if(a[i].gas<=0) pr("油量警告->必须加油",4),f-=40,cout<<'\n';
else if(a[i].gas<=100) pr("油量警告->需要加油",4),f-=40,cout<<'\n';
else if(a[i].gas<=400) pr("油量警告",6),f-=35,cout<<'\n';
cout<<"血量:"<<a[i].HP<<" / "<<a[i].HPm<<'\n';
cout<<"油量:"<<a[i].gas<<" / "<<a[i].gasm<<'\n';
cout<<"长度:"<<a[i].long_<<'\n';
cout<<"主炮数量:"<<a[i].att_1<<'\n';
cout<<"副炮数量:"<<a[i].att_2<<'\n';
cout<<"1 主炮弹药数量:";
int l=a[i].att_s_1;
cout<<l<<'\n';
if(l==0) pr("没有弹药 建议增添",4);
else if(l<=30) pr("弹药较少 建议增添",6);
else pr("基本足够(仅为评估)",2);
cout<<'\n';
cout<<"2 副炮弹药数量:";
l=a[i].att_s_2;
cout<<l<<'\n';
if(l==0) pr("没有弹药 建议增添",4);
else if(l<=30) pr("弹药较少 建议增添",6);
else pr("基本足够(仅为评估)",2);
cout<<'\n';
if(a[i].att_1==0) pr("主炮不足",4),cout<<'\n';
if(a[i].att_2==0) pr("副炮不足",4),cout<<'\n';
if(a[i].att_2==0) pr("鱼雷不足",4),cout<<'\n';
if(a[i].att_2==0) pr("水雷不足",4),cout<<'\n';
cout<<'\n';
}
up();
}
sleep(1);
}
}
int main()
{
random_device rd;
a[1].gas=1000;
a[1].attack=0;
a[1].att_1=0;
a[1].att_2=0;
a[1].att_3=0;
a[1].att_4=0;
a[1].fire=0;
a[1].gas_good=10;
a[1].guard=0;
a[1].HP=15000;
a[1].name="max fight 1";
a[1].HPm=15000;
a[1].gasm=1200;
a[1].boat[40][15]=100;
a[1].long_=70;
a[1].att_s_1=0;
a[1].att_good_1=10;
a[1].att_good_2=40;
a[1].att_good_3=15;
a[1].att_good_4=80;
a[1].Lv=1;
cout<<"是否需要新手指南?(y/n)"<<'\n';
char xing;
cin>>xing;
if(xing=='y') new_do();
play();
cout<<"感谢游玩 个人主页: https://blog.csdn.net/YYDS314?type=blog"<<'\n';
return 0;
}
#include <bits/stdc++.h>
#include <time.h>
#include <windows.h>
#include <stdlib.h>
#include <unistd.h>
#include <conio.h>
#include <fstream>
#include <random>
using namespace std;
bool sea;
int km=0;
bool look[100][100];
long long money=4000000000;
int shuliang=1;
struct zhan
{
string name;
int attack,guard;//攻击 防御
int att_1,att_2,att_3,att_4;//主炮 副炮 鱼雷 水雷
int att_s_1,att_s_2;
int att_good_1,att_good_2,att_good_3,att_good_4;
double HP,fire,HPm;
double shut_down[20];
int gas_good;
int gas,gasm;
int boat[90][40];
int long_;
double Lv;
bool go;
int lx,ly;
int jiao;
double en_1,en_2,en_3,EPU;
};
zhan a[50];
zhan lmap[300][300];
void pr(const char* s, int color)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | color);
printf(s);
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | 7);
}
/*
0 = 黑色 8 = 灰色
1 = 蓝色 9 = 淡蓝色
2 = 绿色 10 = 淡绿色
3 = 浅绿色 11 = 淡浅绿色
4 = 红色 12 = 淡红色
5 = 紫色 13 = 淡紫色
6 = 黄色 14 = 淡黄色
7 = 白色 15 = 亮白色
*/
void new_do()
{
system("cls");
Sleep(50);
cout<<setw(50)<<"----------新手指南----------"<<'\n';
cout<<"敌方会有1~3艘 旗舰(战列舰) ";
cout<<"它们的正面装甲级厚,尽量使用鱼雷或在侧面使用主炮攻击"<<'\n';
cout<<"敌方会有3~10艘副舰(驱逐舰、护卫舰)"<<'\n';
cout<<"它们防空能力强悍,副炮数量极多,就连战机都很难靠近它们,想办法用潜艇鱼雷攻击它们";
cout<<'\n';
cout<<"敌方可能会有潜艇,如果你没有反潜设备就要小心了,它们不会出现在《战舰清单》中"<<'\n';
cout<<"你在开始游戏时会有1艘(几乎)空荡荡的战列舰"<<'\n';
cout<<"你可以在 加工厂 升级战舰"<<'\n';
cout<<"你可以在 制造厂 制造战列舰(的空壳,几乎啥都没有)"<<'\n';
cout<<"提示"<<'\n';
cout<<"战列舰的所有数据都在 战舰情况 中,随时可以查看"<<'\n';
cout<<"刚开始你会有 4000w 资金,到了游戏中你就会知道,这远远不够"<<'\n';
cout<<"这是战列舰时代的游戏,没有导弹"<<'\n';
system("pause");
}
void fight()
{
int xz;
cout<<"输入出航的船只(结束输入 其他数字 )"<<'\n';
for(int i=1; i<=shuliang; i++)
{
cout<<i<<" "<<a[i].name;
if(a[i].gas>0) pr(" 可以出战",2);
else pr(" 缺少燃油",4);
if(a[i].attack==0) pr(" 无战斗力",6);
else pr("战斗力:",2),cout<<a[i].attack;
cout<<'\n';
}
while(cin>>xz&&xz<=shuliang&&xz>=1)
{
a[xz].go=true;
}
cout<<"确认:"<<'\n';
for(int i=1; i<=shuliang; i++)
{
if(a[i].go==true)
{
cout<<a[i].name;
if(a[i].gas>0) pr(" 可以出战",2);
else pr(" 缺少燃油",4);
if(a[i].attack==0) pr(" 无战斗力",6);
else pr("战斗力:",2),cout<<a[i].attack;
cout<<'\n';
}
}
cout<<'\n';
system("pause");
int ling1;
string ling2;
while(ling1!=-1&&ling2!="-1")
{
cout<<"请输入指令- 按 0 0 查看您的指令输入方法"<<'\n';
cin>>ling1>>ling2;
if(ling2=="0"&&ling1==0)
{
cout<<"指令1 :编号+' '+w(小写) >>选中舰前进 例:1 w";
cout<<" 在一轮相同战舰中,该指令只能使用一次"<<'\n';
cout<<"指令2 :编号+' '+a(小写)+' '+左转角度 >>选中舰左转 例:1 a 30 角度越小,";
cout<<"转速越快"<<'\n';
cout<<"指令3 :编号+' '+d(小写)+' '+右转角度 >>选中舰右转 例:1 d 30 角度越小,";
cout<<"转速越快"<<'\n';
cout<<"指令4 :编号+' '+q(小写) >>打开雷达"<<'\n';
cout<<"指令5 :编号+' '+e(小写) >>关闭雷达"<<'\n';
cout<<"指令6 :编号+' '+x(小写)+' '+敌方编号 >>向敌方开火"<<'\n';
cout<<"指令7 :编号+' '+c(小写) >>选中舰加速"<<'\n';
pr("指令7 :-1 -1 >>回航",2);
cout<<'\n';
system("pause");
}
if(ling2=="w")
{
a[ling1].en_1+=10;
a[ling1].en_1+=10;
if(a[ling1].en_1>0&&a[ling1].en_2>0)
{
if(a[ling1].jiao>=1&&a[ling1].jiao<=90)
{
a[ling1].lx+=(a[ling1].en_1+a[ling1].en_2)*cos(a[ling1].jiao*M_PI/180)/100;
a[ling1].ly+=(a[ling1].en_1+a[ling1].en_2)*sin(a[ling1].jiao*M_PI/180)/100;
a[ling1].EPU+=5;
}
else if(a[ling1].jiao>90&&a[ling1].jiao<=180)
{
a[ling1].lx-=(a[ling1].en_1+a[ling1].en_2)*cos((180-a[ling1].jiao)*M_PI/180)/100;
a[ling1].ly+=(a[ling1].en_1+a[ling1].en_2)*sin((180-a[ling1].jiao)*M_PI/180)/100;
a[ling1].EPU+=5;
}
else if(a[ling1].jiao>180&&a[ling1].jiao<=270)
{
a[ling1].lx-=(a[ling1].en_1+a[ling1].en_2)*cos((a[ling1].jiao-180)*M_PI/180)/100;
a[ling1].ly-=(a[ling1].en_1+a[ling1].en_2)*sin((a[ling1].jiao-180)*M_PI/180)/100;
a[ling1].EPU+=5;
}
else if(a[ling1].jiao>270&&a[ling1].jiao<=360)
{
a[ling1].lx+=(a[ling1].en_1+a[ling1].en_2)*cos((360-a[ling1].jiao)*M_PI/180)/100;
a[ling1].ly-=(a[ling1].en_1+a[ling1].en_2)*sin((360-a[ling1].jiao)*M_PI/180)/100;
a[ling1].EPU+=35;
}
a[ling1].EPU+=5;
}
cout<<"坐标x:"<<a[ling1].lx<<" "<<"坐标y:"<<a[ling1].ly<<'\n';
}
if(ling2=="a")
{
double jiao;
cin>>jiao;
Sleep(jiao);
}
random_device rd;
default_random_engine e(rd());
uniform_int_distribution<int> dist(0,3);
random_device rd2;
default_random_engine k(rd2());
uniform_int_distribution<int> dist2(0,4);
int sj=dist(e);
if(sj==0)//战斗
{
sj=dist(e);
if(sj==0)
{
sj=dist(e)+3;
int dishu=sj;
for(int i=1; i<=dishu; i++)
{
int lx=95+i+dist(e),ly=70-i*2;
lmap[lx][ly].lx=lx,lmap[lx][ly].ly=ly;
lmap[lx][ly].name="敌";
int sj=dist2(k);
random_device rd;
default_random_engine l(rd());
uniform_int_distribution<int> dist(0,4);
if(sj==0)
{
lmap[lx][ly].name=lmap[lx][ly].name+"战列舰";
}
else if(sj==1)
{
lmap[lx][ly].name=lmap[lx][ly].name+"驱逐舰";
}
else if(sj==2)
{
lmap[lx][ly].name=lmap[lx][ly].name+"护卫舰";
}
else if(sj==3)
{
lmap[lx][ly].name=lmap[lx][ly].name+"巡洋舰";
}
else
{
lmap[lx][ly].name=lmap[lx][ly].name+"潜艇";
}
pr("敌方目标: x:",4);
cout<<lx<<" ";
pr("y:",4);
pr(" 血量值:",4);
}
}
}
else if(sj==1)
{
}
else if(sj==2)
{
}
else if(sj==3)
{
}
for(int i=1; i<=shuliang; i++)
{
if(a[i].HP<=0)
{
system("color 04");
cout<<a[i].name;
pr("被敌方击沉!",4);
cout<<'\n';
}
}
system("color 0F");
}
}
void up_gas()
{
cout<<"这里是加油站----------"<<'\n';
for(int i=1; i<=shuliang; i++)
{
Sleep(500);
system("cls");
cout<<i<<" "<<a[i].name<<":"<<a[i].gas<<"/"<<a[i].gasm<<'\n';
cout<<" 可以航行"<<a[i].gas*a[i].gas_good<<"km (需要在"<<a[i].gas*a[i].gas_good/2.0<<"km返回)";
cout<<'\n';
if(a[i].gas==0) pr("必须加油",4);
else if(a[i].gas>0&&a[i].gas!=a[i].gasm) pr("可以加油",6);
else pr("无需加油",2);
cout<<"(y/n)"<<'\n';
string xz;
cin>>xz;
if(xz=="y"||xz=="Y")
{
cout<<"正在加油..."<<'\n';
system("pause");
Sleep(500);
if(a[i].gasm==a[i].gas) cout<<"无需加油--"<<'\n';
else
{
long long money_want=(a[i].gasm-a[i].gas)/(a[i].gas_good)*600;
cout<<"需要"<<money_want<<"资金"<<'\n';
if(money_want>money)
{
cout<<"资金不足,为您尽量加油↖(^ω^)↗"<<'\n';
a[i].gas=a[i].gas+money/600*a[i].gas_good;
money=0;
}
else
{
money-=money_want;
a[i].gas=a[i].gasm;
}
cout<<"加油完成---"<<'\n';
cout<<i<<" "<<a[i].name<<":"<<a[i].gas<<"/"<<a[i].gasm<<'\n';
cout<<" 可以航行"<<a[i].gas/a[i].gas_good<<"km (需要在"<<a[i].gas/a[i].gas_good/2.0<<"km返回)";
cout<<'\n';
if(a[i].gas==0) pr("必须加油",4);
else if(a[i].gas>0&&a[i].gas!=a[i].gasm) pr("可以加油",6);
else pr("无需加油",2);
cout<<'\n';
}
}
else
{
cout<<'\n';
system("pause");
}
}
cout<<'\n';
system("pause");
}
void up_on1()
{
for(int i=1; i<=shuliang; i++)
{
cout<<i<<" "<<a[i].name<<": Lv. "<<a[i].Lv<<'\n';
a[i].HP=a[i].HPm;
cout<<"0 不升级 下一个"<<'\n';
cout<<"1 血量:"<<a[i].HP<<" / "<<a[i].HPm<<'\n';
cout<<"2 油量:"<<a[i].gas<<" / "<<a[i].gasm<<'\n';
cout<<"3 燃油等级:"<<a[i].gas_good<<"/1 (越小越好)"<<'\n';
cout<<"4 长度:"<<a[i].long_<<"m"<<'\n';
cout<<"5 主炮数量:"<<a[i].att_1<<'\n';
cout<<"6 精准度:"<<a[i].att_good_1<<"%"<<'\n';
cout<<"7 副炮数量:"<<a[i].att_2<<'\n';
cout<<"8 精准度:"<<a[i].att_good_2<<"%"<<'\n';
cout<<"9 鱼雷精准度:"<<a[i].att_good_3<<"%"<<'\n';
cout<<"10 水雷精准度:"<<a[i].att_good_4<<"%"<<'\n';
cout<<'\n';
system("pause");
short k;
cin>>k;
double l;
switch(k)
{
case 0:
break;
case 1:
cout<<"血量升级价格:2点/资金 等级≥5时 5点/资金"<<'\n';
cout<<"购买血量(最大";
if(a[i].Lv>=5) cout<<money*5,l=money*5;
else cout<<money*2,l=money*2;
cout<<") : ";
double xz;
cin>>xz;
while(xz>l) cout<<"Error!",cin>>xz;
if(a[i].Lv>=5) l=xz*5;
else l=xz*2;
money-=l;
a[i].HPm+=xz;
break;
case 2:
cout<<"油量升级价格:1点/资金 等级≥10时 2点/资金"<<'\n';
cout<<"购买油量(最大";
if(a[i].Lv>=5) cout<<money*1,l=money*1;
else cout<<money,l=money;
cout<<") : ";
cin>>xz;
while(xz>l) cout<<"Error!",cin>>xz;
if(a[i].Lv>=10) l=xz*2;
else l=xz;
money-=l;
a[i].gasm+=xz;
break;
case 3:
cout<<"90w变为1(需要将该舰现有油量清零)"<<'\n';
if(money>=900000) a[i].gas_good=1,a[i].gas=0,money-=900000;
else system("pause");
a[i].Lv+=1;
break;
case 4:
cout<<"长度升级价格:5w/m"<<'\n';
cout<<"购买长度(最大";
cout<<fixed<<setprecision(2)<<money/5.0,l=money/5.0;
cout<<") : ";
cin>>xz;
while(xz>l) cout<<"Error!",cin>>xz;
l=xz*50000;
money-=l;
a[i].long_+=xz;
a[i].Lv+=xz*0.1;
break;
case 5:
if(a[i].long_-a[i].att_1*2-a[i].att_2*2-a[i].att_1*1-a[i].att_1*1-a[i].gasm/100<2)
{
cout<<"甲板不够,去加长甲板吧"<<'\n';
}
else
{
cout<<"口径:1 80mm 10w"<<'\n';
cout<<" 2 95mm 12w"<<'\n';
cout<<" 3 110mm 20w"<<'\n';
cout<<" 4 160mm 50w"<<'\n';
cout<<" 5 320mm 90w"<<'\n';
}
int kj;
cin>>kj;
if(kj==1)
{
a[i].att_1++;
a[i].attack+=80;
a[i].Lv+=0.1;
money-=100000;
}
if(kj==2)
{
a[i].att_1++;
a[i].attack+=95;
a[i].Lv+=0.2;
money-=120000;
}
if(kj==3)
{
a[i].att_1++;
a[i].attack+=110;
a[i].Lv+=0.3;
money-=200000;
}
if(kj==4)
{
a[i].att_1++;
a[i].attack+=160;
a[i].Lv+=0.5;
money-=500000;
}
if(kj==5)
{
a[i].att_1++;
a[i].attack+=320;
a[i].Lv+=1;
money-=900000;
}
break;
case 6:
cout<<"精准度升级为 5000资金/ 0.1%"<<'\n';
cout<<"输入投入资金:";
int mon;
cin>>mon;
money-=mon;
a[i].att_good_1+=mon*1.0/5000.0;
a[i].Lv+=0.01*mon*1.0/5000.0;
break;
case 7:
if(a[i].long_-a[i].att_1*2-a[i].att_2*2-a[i].att_1*1-a[i].att_1*1-a[i].gasm/100<1)
{
cout<<"甲板不够,去加长甲板吧"<<'\n';
}
else
{
cout<<"口径:1 10mm 10w"<<'\n';
cout<<" 2 25mm 12w"<<'\n';
cout<<" 3 50mm 20w"<<'\n';
cout<<" 4 60mm 50w"<<'\n';
cout<<" 5 70mm 90w"<<'\n';
cin>>kj;
if(kj==1)
{
a[i].att_2++;
a[i].attack+=10;
money-=100000;
}
if(kj==2)
{
a[i].att_2++;
a[i].attack+=25;
money-=120000;
}
if(kj==3)
{
a[i].att_2++;
a[i].attack+=50;
money-=200000;
}
if(kj==4)
{
a[i].att_2++;
a[i].attack+=60;
money-=500000;
}
if(kj==5)
{
a[i].att_2++;
a[i].attack+=70;
money-=900000;
}
a[i].Lv=a[i].Lv+0.1*kj;
}
break;
/*
cout<<"8 精准度:"<<a[i].att_good_2<<"%"<<'\n';
cout<<"9 鱼雷精准度:"<<a[i].att_good_3<<"%"<<'\n';
cout<<"10 水雷精准度:"<<a[i].att_good_4<<"%"<<'\n';
*/
case 8:
cout<<"精准度升级为 5000资金/ 0.1%"<<'\n';
cout<<"输入投入资金:";
cin>>mon;
money-=mon;
a[i].att_good_2+=mon/5000;
a[i].Lv=a[i].Lv+=mon/5000;
break;
case 9:
cout<<"精准度升级为 5000资金/ 0.1%"<<'\n';
cout<<"输入投入资金:";
cin>>mon;
money-=mon;
a[i].att_good_3+=mon/5000;
break;
case 10:
cout<<"精准度升级为 5000资金/ 0.1%"<<'\n';
cout<<"输入投入资金:";
cin>>mon;
money-=mon;
a[i].att_good_4+=mon/5000;
break;
}
}
}
void up_build()
{
int xz;
cout<<"需要:"<<'\n';
cout<<"1 驱逐舰 7500w"<<'\n';
cout<<"2 护卫舰 7500w"<<'\n';
cout<<"3 巡洋舰 8000w"<<'\n';
cout<<"4 战列舰 9500w"<<'\n';
cout<<"5 潜艇 7000w"<<'\n';
cout<<"6 弹药"<<'\n';
cin>>xz;
string namel;
if(xz==1)
{
money-=75000000;
cout<<"名字:";
while(cin>>namel)
{
int f=1;
for(int i=1; i<=shuliang; i++)
{
if(a[i].name==namel)
{
f=0;
cout<<"已有重复名称"<<'\n';
}
}
if(f==1) break;
}
a[shuliang+1].gas=500;
a[shuliang+1].attack=0;
a[shuliang+1].att_1=0;
a[shuliang+1].att_2=0;
a[shuliang+1].att_3=0;
a[shuliang+1].att_4=0;
a[shuliang+1].fire=0;
a[shuliang+1].gas_good=10;
a[shuliang+1].guard=0;
a[shuliang+1].HP=6000;
a[shuliang+1].name=namel;
a[shuliang+1].HPm=6000;
a[shuliang+1].gasm=700;
a[shuliang+1].boat[40][15]=100;
a[shuliang+1].long_=40;
a[shuliang+1].att_s_1=0;
a[shuliang+1].att_good_1=50;
a[shuliang+1].att_good_2=50;
a[shuliang+1].att_good_3=95;
a[shuliang+1].att_good_4=90;
a[shuliang+1].Lv=1;
shuliang++;
}
if(xz==2)
{
money-=75000000;
cout<<"名字:";
while(cin>>namel)
{
int f=1;
for(int i=1; i<=shuliang; i++)
{
if(a[i].name==namel)
{
f=0;
cout<<"已有重复名称"<<'\n';
}
}
if(f==1) break;
}
a[shuliang+1].gas=500;
a[shuliang+1].attack=0;
a[shuliang+1].att_1=0;
a[shuliang+1].att_2=0;
a[shuliang+1].att_3=0;
a[shuliang+1].att_4=0;
a[shuliang+1].fire=0;
a[shuliang+1].gas_good=10;
a[shuliang+1].guard=0;
a[shuliang+1].HP=7000;
a[shuliang+1].name=namel;
a[shuliang+1].HPm=7000;
a[shuliang+1].gasm=900;
a[shuliang+1].boat[40][15]=100;
a[shuliang+1].long_=40;
a[shuliang+1].att_s_1=0;
a[shuliang+1].att_good_1=60;
a[shuliang+1].att_good_2=60;
a[shuliang+1].att_good_3=75;
a[shuliang+1].att_good_4=82;
a[shuliang+1].Lv=1;
shuliang++;
}
if(xz==3)
{
money-=80000000;
cout<<"名字:";
string namel;
while(cin>>namel)
{
int f=1;
for(int i=1; i<=shuliang; i++)
{
if(a[i].name==namel)
{
f=0;
cout<<"已有重复名称"<<'\n';
}
}
if(f==1) break;
}
a[shuliang+1].gas=1000;
a[shuliang+1].attack=0;
a[shuliang+1].att_1=0;
a[shuliang+1].att_2=0;
a[shuliang+1].att_3=0;
a[shuliang+1].att_4=0;
a[shuliang+1].fire=0;
a[shuliang+1].gas_good=10;
a[shuliang+1].guard=0;
a[shuliang+1].HP=10000;
a[shuliang+1].name=namel;
a[shuliang+1].HPm=10000;
a[shuliang+1].gasm=1200;
a[shuliang+1].boat[40][15]=100;
a[shuliang+1].long_=70;
a[shuliang+1].att_s_1=0;
a[shuliang+1].att_good_1=10;
a[shuliang+1].att_good_2=40;
a[shuliang+1].att_good_3=15;
a[shuliang+1].att_good_4=80;
a[shuliang+1].Lv=1;
shuliang++;
}
if(xz==4)
{
money-=95000000;
cout<<"名字:";
string namel;
while(cin>>namel)
{
int f=1;
for(int i=1; i<=shuliang; i++)
{
if(a[i].name==namel)
{
f=0;
cout<<"已有重复名称"<<'\n';
}
}
if(f==1) break;
}
a[shuliang+1].gas=1000;
a[shuliang+1].attack=0;
a[shuliang+1].att_1=0;
a[shuliang+1].att_2=0;
a[shuliang+1].att_3=0;
a[shuliang+1].att_4=0;
a[shuliang+1].fire=0;
a[shuliang+1].gas_good=10;
a[shuliang+1].guard=0;
a[shuliang+1].HP=15000;
a[shuliang+1].name=namel;
a[shuliang+1].HPm=15000;
a[shuliang+1].gasm=1200;
a[shuliang+1].boat[40][15]=100;
a[shuliang+1].long_=70;
a[shuliang+1].att_s_1=0;
a[shuliang+1].att_good_1=10;
a[shuliang+1].att_good_2=40;
a[shuliang+1].att_good_3=15;
a[shuliang+1].att_good_4=80;
a[shuliang+1].Lv=1;
shuliang++;
}
if(xz==5)
{
money-=70000000;
cout<<"名字:";
while(cin>>namel)
{
int f=1;
for(int i=1; i<=shuliang; i++)
{
if(a[i].name==namel)
{
f=0;
cout<<"已有重复名称"<<'\n';
}
}
if(f==1) break;
}
a[shuliang+1].gas=1500;
a[shuliang+1].attack=0;
a[shuliang+1].att_1=0;
a[shuliang+1].att_2=0;
a[shuliang+1].att_3=0;
a[shuliang+1].att_4=0;
a[shuliang+1].fire=0;
a[shuliang+1].gas_good=10;
a[shuliang+1].guard=0;
a[shuliang+1].HP=1000;
a[shuliang+1].name=namel;
a[shuliang+1].HPm=1000;
a[shuliang+1].gasm=3500;
a[shuliang+1].boat[40][3]=100;
a[shuliang+1].long_=8;
a[shuliang+1].att_s_1=0;
a[shuliang+1].att_good_1=0;
a[shuliang+1].att_good_2=0;
a[shuliang+1].att_good_3=95;
a[shuliang+1].att_good_4=90;
a[shuliang+1].Lv=1;
shuliang++;
}
if(xz==6)
{
for(int i=1; i<=shuliang; i++)
{
cout<<a[i].name;
cout<<"1 主炮弹药数量:";
int l=a[i].att_s_1;
cout<<l<<'\n';
if(l==0) pr("没有弹药 建议增添",4);
else if(l<=30) pr("弹药较少 建议增添",6);
else pr("基本足够(仅为评估)",2);
cout<<'\n';
int want;
cout<<"输入需要弹药(40w/枚)数量:";
cin>>want;
money-=want*400000;
a[i].att_s_1+=want;
cout<<"2 副炮弹药数量:";
l=a[i].att_s_2;
cout<<l<<'\n';
if(l==0) pr("没有弹药 建议增添",4);
else if(l<=30) pr("弹药较少 建议增添",6);
else pr("基本足够(仅为评估)",2);
cout<<'\n';
cout<<"输入需要弹药(40w/枚)数量:";
cin>>want;
money-=want*400000;
a[i].att_s_2+=want;
}
}
cout<<"OK"<<'\n';
return ;
}
void meself()
{
cout<<"以下是个人情况:"<<'\n';
for(int i=1; i<=shuliang; i++)
{
cout<<i<<" "<<a[i].name<<'\n';
a[i].HP=a[i].HPm;
int f=100;
if(a[i].gas<=0) pr("油量警告->必须加油",4),f-=40,cout<<'\n';
else if(a[i].gas<=100) pr("油量警告->需要加油",4),f-=40,cout<<'\n';
else if(a[i].gas<=400) pr("油量警告",6),f-=35,cout<<'\n';
if(a[i].fire==0) pr("舰艇无火灾",2),cout<<'\n';
else if(a[i].fire>0&&a[i].fire<=1.5) pr("舰艇火灾警告",6),f-=0.1,cout<<'\n';
else if(a[i].fire<=5) pr("中等火灾警告",6),f-=5,cout<<'\n';
else if(a[i].fire<=10) pr("最高火灾警告->立即返航/弃船",4),f-=40,cout<<'\n';
cout<<"血量:"<<a[i].HP<<" / "<<a[i].HPm<<'\n';
cout<<"油量:"<<a[i].gas<<" / "<<a[i].gasm<<'\n';
cout<<"长度:"<<a[i].long_<<'\n';
cout<<"主炮数量:"<<a[i].att_1<<'\n';
cout<<"副炮数量:"<<a[i].att_2<<'\n';
cout<<"1 主炮弹药数量:";
int l=a[i].att_s_1;
cout<<l<<'\n';
if(l==0) pr("没有弹药 建议增添",4);
else if(l<=30) pr("弹药较少 建议增添",6);
else pr("基本足够(仅为评估)",2);
cout<<'\n';
cout<<"2 副炮弹药数量:";
l=a[i].att_s_2;
cout<<l<<'\n';
if(l==0) pr("没有弹药 建议增添",4);
else if(l<=30) pr("弹药较少 建议增添",6);
else pr("基本足够(仅为评估)",2);
cout<<'\n';
if(a[i].att_1==0) pr("主炮不足",4),cout<<'\n';
if(a[i].att_2==0) pr("副炮不足",4),cout<<'\n';
if(a[i].att_2==0) pr("鱼雷不足",4),cout<<'\n';
if(a[i].att_2==0) pr("水雷不足",4),cout<<'\n';
cout<<'\n';
}
}
void up()
{
cout<<"1 加油站"<<'\n';
cout<<"2 加工厂"<<'\n';
cout<<"3 制造厂"<<'\n';
cout<<"4 出航" <<'\n';
cout<<"5 查看状态"<<'\n';
string xz;
cin>>xz;
while(xz!="1"&&xz!="2"&&xz!="3"&&xz!="4"&&xz!="5")
{
cout<<"错误--- 请再次输入"<<'\n';
system("pause");
cin>>xz;
}
int xz_int=stoi(xz);
switch(xz_int)
{
case 1:
up_gas();
break;
case 2:
up_on1();
break;
case 3:
up_build();
break;
case 4:
sea=true;
break;
default:
meself();
break;
}
}
void play()
{
shuliang=1;
a[1].gas=1000;
a[1].attack=0;
a[1].att_1=0;
a[1].att_2=0;
a[1].att_3=0;
a[1].att_4=0;
a[1].fire=0;
a[1].gas_good=10;
a[1].guard=0;
a[1].HP=15000;
a[1].name="max fight 1";
a[1].HPm=15000;
a[1].gasm=1200;
a[1].boat[40][15]=100;
a[1].long_=70;
a[1].att_s_1=0;
a[1].att_good_1=10;
a[1].att_good_2=40;
a[1].att_good_3=15;
a[1].att_good_4=80;
a[1].Lv=1;
cout<<"游戏开始"<<'\n';
system("pause");
system("cls");
while(1+1==2)
{
system("cls");
cout<<"游戏进行中----------"<<'\n';
system("pause");
cout<<"资金:"<<money;
if(money<-10000000)
{
cout<<"欠债过多 挑战失败"<<'\n';
return ;
}
if(sea)
{
for(int i=1; i<=shuliang; i++)
{
int f=100;
cout<<a[i].name<<":"<<'\n';
cout<<"该舰艇现在距离基地"<<km<<"km,需要"<<km*a[i].gas_good<<"升燃油"<<'\n';
if(a[i].fire==0) pr("舰艇无火灾",2),cout<<'\n';
else if(a[i].fire>0&&a[i].fire<=1.5) pr("舰艇火灾警告",6),f-=0.1,cout<<'\n';
else if(a[i].fire<=5) pr("中等火灾警告",6),f-=5,cout<<'\n';
else if(a[i].fire<=10) pr("最高火灾警告->立即返航/弃船",4),f-=40,cout<<'\n';
if(km*a[i].gas_good>=a[i].gas*2) pr("最高油量警告->立即返航",4),f-=40,cout<<'\n';
else if(km*a[i].gas_good>=a[i].gas) pr("油量警告",6),f-=35,cout<<'\n';
if(a[i].HP<=100) pr("重伤警告->立即返航/弃船",4),f-=60,cout<<'\n';
else if(a[i].HP<=1000) pr("警告->注意躲避火力",6),f-=20,cout<<'\n';
cout<<"1 主炮弹药数量:";
int l=a[i].att_s_1;
cout<<l<<'\n';
if(l==0) pr("没有弹药 建议增添",4);
else if(l<=30) pr("弹药较少 建议增添",6);
else pr("基本足够(仅为评估)",2);
cout<<'\n';
cout<<"2 副炮弹药数量:";
l=a[i].att_s_2;
cout<<l<<'\n';
if(l==0) pr("没有弹药 建议增添",4);
else if(l<=30) pr("弹药较少 建议增添",6);
else pr("基本足够(仅为评估)",2);
cout<<'\n';
if(a[i].att_1==0) pr("主炮不足",4),cout<<'\n';
if(a[i].att_2==0) pr("副炮不足",4),cout<<'\n';
if(a[i].att_2==0) pr("鱼雷不足",4),cout<<'\n';
if(a[i].att_2==0) pr("水雷不足",4),cout<<'\n';
}
fight();
}
else
{
for(int i=1; i<=shuliang; i++)
{
cout<<i<<" "<<a[i].name<<'\n';
a[i].HP=a[i].HPm;
a[i].fire=0;
a[i].go=false;
a[i].lx=0;
a[i].ly=0;
int f=100;
if(a[i].gas<=0) pr("油量警告->必须加油",4),f-=40,cout<<'\n';
else if(a[i].gas<=100) pr("油量警告->需要加油",4),f-=40,cout<<'\n';
else if(a[i].gas<=400) pr("油量警告",6),f-=35,cout<<'\n';
cout<<"血量:"<<a[i].HP<<" / "<<a[i].HPm<<'\n';
cout<<"油量:"<<a[i].gas<<" / "<<a[i].gasm<<'\n';
cout<<"长度:"<<a[i].long_<<'\n';
cout<<"主炮数量:"<<a[i].att_1<<'\n';
cout<<"副炮数量:"<<a[i].att_2<<'\n';
cout<<"1 主炮弹药数量:";
int l=a[i].att_s_1;
cout<<l<<'\n';
if(l==0) pr("没有弹药 建议增添",4);
else if(l<=30) pr("弹药较少 建议增添",6);
else pr("基本足够(仅为评估)",2);
cout<<'\n';
cout<<"2 副炮弹药数量:";
l=a[i].att_s_2;
cout<<l<<'\n';
if(l==0) pr("没有弹药 建议增添",4);
else if(l<=30) pr("弹药较少 建议增添",6);
else pr("基本足够(仅为评估)",2);
cout<<'\n';
if(a[i].att_1==0) pr("主炮不足",4),cout<<'\n';
if(a[i].att_2==0) pr("副炮不足",4),cout<<'\n';
if(a[i].att_2==0) pr("鱼雷不足",4),cout<<'\n';
if(a[i].att_2==0) pr("水雷不足",4),cout<<'\n';
cout<<'\n';
}
up();
}
sleep(1);
}
}
int main()
{
random_device rd;
a[1].gas=1000;
a[1].attack=0;
a[1].att_1=0;
a[1].att_2=0;
a[1].att_3=0;
a[1].att_4=0;
a[1].fire=0;
a[1].gas_good=10;
a[1].guard=0;
a[1].HP=15000;
a[1].name="max fight 1";
a[1].HPm=15000;
a[1].gasm=1200;
a[1].boat[40][15]=100;
a[1].long_=70;
a[1].att_s_1=0;
a[1].att_good_1=10;
a[1].att_good_2=40;
a[1].att_good_3=15;
a[1].att_good_4=80;
a[1].Lv=1;
cout<<"是否需要新手指南?(y/n)"<<'\n';
char xing;
cin>>xing;
if(xing=='y') new_do();
play();
cout<<"感谢游玩 个人主页: https://blog.csdn.net/YYDS314?type=blog"<<'\n';
return 0;
}