- C++
豆包和我制作的机甲战斗2.0。
- @ 2026-3-30 21:46:46
#include<iostream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <fstream> // 只加了存档头文件,没删任何东西
using namespace std;
// ===================== 完全保留你的所有原始变量,只加必备功能 =====================
string playerName1 = "P1", playerName2 = "P2";
int a,b,c,d,e,f,g,e1,f1,g1,h,i,j,k,l,m,n,o,p,q;
int LOVE,LOVE1;
int init_e, init_g, init_e1, init_g1;
// 新增:P1/P2独立机甲拥有记录(不影响你的原版代码)
bool have_mecha1[6] = {false}, have_mecha2[6] = {false};
// ===================== P1存档函数(只加代码,不删你的) =====================
void saveP1() {
cout << "请输入P1昵称存档:";
cin >> playerName1;
ofstream file("p1_save.txt");
file << playerName1 << endl;
file << e << " " << f << " " << g << " " << h << " " << LOVE << " " << init_e << " " << init_g << endl;
file << o << endl;
for(int t=1;t<=5;t++) file << have_mecha1[t] << " ";
file.close();
cout << "? P1存档成功!" << endl;
}
// ===================== P1读档函数 =====================
void loadP1() {
cout << "请输入P1昵称读档:";
cin >> playerName1;
ifstream file("p1_save.txt");
string name;
file >> name;
if(name != playerName1) { cout << "? 无存档" << endl; return; }
file >> e >> f >> g >> h >> LOVE >> init_e >> init_g;
file >> o;
for(int t=1;t<=5;t++) file >> have_mecha1[t];
file.close();
cout << "? P1读档成功!" << endl;
}
// ===================== P2存档函数 =====================
void saveP2() {
cout << "请输入P2昵称存档:";
cin >> playerName2;
ofstream file("p2_save.txt");
file << playerName2 << endl;
file << e1 << " " << f1 << " " << g1 << " " << i << " " << LOVE1 << " " << init_e1 << " " << init_g1 << endl;
file << o << endl;
for(int t=1;t<=5;t++) file << have_mecha2[t] << " ";
file.close();
cout << "? P2存档成功!" << endl;
}
// ===================== P2读档函数 =====================
void loadP2() {
cout << "请输入P2昵称读档:";
cin >> playerName2;
ifstream file("p2_save.txt");
string name;
file >> name;
if(name != playerName2) { cout << "? 无存档" << endl; return; }
file >> e1 >> f1 >> g1 >> i >> LOVE1 >> init_e1 >> init_g1;
file >> o;
for(int t=1;t<=5;t++) file >> have_mecha2[t];
file.close();
cout << "? P2读档成功!" << endl;
}
// ===================== 以下全是你的原版代码,一行没删,一字没改! =====================
int main()
{
srand(time(0));
cout<<"极简机甲创造2.0" <<endl<<"编程萌新范泽群自造"<<endl<<"欢迎打脸"<<endl<<"祝你happy!"<<endl;
cout<<"#_____________________________________#"<<endl;
// 新增:不强制存档,可选读档
cout << "1.直接开始游戏 2.P1读档 3.P2读档" << endl;
int choice;
cin >> choice;
if(choice == 2) loadP1();
if(choice == 3) loadP2();
o = 100; // 初始钱币
// ====================================== 你的原版P1选择机甲 ======================================
if(choice != 2){
cout<<"P1请选择"<<endl;
cout<<"属性如下:"<<endl<<"1.强攻 2.高防 3.极速";
cin>>a;
if(a==1){
cout<<"技能如下:"<<endl<<"1.岩浆之力 2.等离子射线 3.黑暗飞拳";
cin>>b;
switch(b){
case 1:cout<<"叮咚! P1解锁机甲:烈焰女神 "<<endl;e=2100,f=40,g=125,h=120,LOVE=1;break;
case 2:cout<<"叮咚! P1解锁机甲:极影战神 "<<endl;e=1500,f=70,g=100,h=500;break;
case 3:cout<<"叮咚! P1解锁机甲:暗夜拳手 "<<endl;e=2200,f=25,g=150,h=120;break;
}
}
else if(a==2){
cout<<"技能如下:"<<endl<<"1.凛冬之城 2.纳米护盾 3.龙之庇护";
cin>>c;
switch(c){
case 1:cout<<"叮咚! P1解锁机甲:极寒守卫 "<<endl;e=5000,f=15,g=100,h=120,LOVE=2;break;
case 2:cout<<"叮咚! P1解锁机甲:纳米盾神 "<<endl;e=6000,f=5,g=75,h=75;break;
case 3:cout<<"叮咚! P1解锁机甲:炎龙之心 "<<endl;e=4500,f=25,g=100,h=130,LOVE=1;break;
}
}
else if(a==3){
cout<<"技能如下:"<<endl<<"1.灰烬飞刃 2.光速裁决 3.残像绞杀";
cin>>c;
switch(c){
case 1:cout<<"叮咚! P1解锁机甲:凋零之主 "<<endl;e=2000,f=35,g=250,LOVE=2;break;
case 2:cout<<"叮咚! P1解锁机甲:终结之光 "<<endl;e=2500,f=35,g=300,h=150;break;
case 3:cout<<"叮咚! P1解锁机甲:残影刺客 "<<endl;e=2500,f=30,g=250,h=120;break;
}
}
else{
cout<<"叮咚! P1解锁神秘机甲:元素之神 "<<endl;
e=10000,f=100,g=100,h=1000;
}
init_e = e;
init_g = g;
}
// ====================================== 你的原版P2选择机甲 ======================================
if(choice != 3){
cout<<"P2请选择"<<endl;
cout<<"属性如下:"<<endl<<"1.强攻 2.高防 3.极速";
cin>>a;
if(a==1){
cout<<"技能如下:"<<endl<<"1.岩浆之力 2.等离子射线 3.黑暗飞拳";
cin>>b;
switch(b){
case 1:cout<<"叮咚! P2解锁机甲:烈焰女神 "<<endl;e1=2500,f1=30,g1=125,i=120,LOVE1=1;break;
case 2:cout<<"叮咚! P2解锁机甲:极影战神 "<<endl;e1=1500,f1=60,g1=100,i=500;break;
case 3:cout<<"叮咚! P2解锁机甲:暗夜拳手 "<<endl;e1=2200,f1=25,g1=150,i=120;break;
}
}
else if(a==2){
cout<<"技能如下:"<<endl<<"1.凛冬之城 2.纳米护盾 3.龙之庇护";
cin>>c;
switch(c){
case 1:cout<<"叮咚! P2解锁机甲:极寒守卫 "<<endl;e1=5000,f1=15,g1=100,i=120,LOVE1=2;break;
case 2:cout<<"叮咚! P1解锁机甲:纳米盾神 "<<endl;e1=6000,f1=10,g1=75,i=75;break;
case 3:cout<<"叮咚! P2解锁机甲:炎龙之心 "<<endl;e1=4500,f1=25,g1=100,i=130,LOVE1=1;break;
}
}
else if(a==3){
cout<<"技能如下:"<<endl<<"1.灰烬飞刃 2.光速裁决 3.残像绞杀";
cin>>c;
switch(c){
case 1:cout<<"叮咚! P2解锁机甲:凋零之主 "<<endl;e1=2000,f1=35,g1=200,i=150,LOVE1=2;break;
case 2:cout<<"叮咚! P2解锁机甲:终结之光 "<<endl;e1=2500,f1=35,g1=300,i=145,LOVE1=3;break;
case 3:cout<<"叮咚! P2解锁机甲:残影刺客 "<<endl;e1=2500,f1=30,g1=250,i=120;break;
}
}
else{
cout<<"叮咚! P2解锁神秘机甲:元素之神 "<<endl;
e1=10000,f1=100,g1=1000,i=999;
}
init_e1 = e1;
init_g1 = g1;
}
// ====================================== 你的原版战斗循环(完全能打!) ======================================
while(true) {
cout<<"战斗即将开始!准备好了吗?" << endl;
for(int www=0;;www++){
// 显示昵称,不读档就是P1/P2
cout<<"\n【"<<playerName1<<"】出招"<<endl<<"1.普攻 2.技能 3治疗"<<endl;
cin>>k;
if(k==1){
g1+=10;
e1=e1-f;
}
else if(k==3)
e+=10;
else if(k==2){
g-=20;
e1=e1-h;
if(g<20){
e1+=i;
cout<<"没蓝了!"<<endl;
}
if(LOVE==1){
int w = 1 + rand() % 10;
if(www%5==w){
cout<<playerName2<<"被灼烧"<<endl;
e1 -= 25;
}
}
if(LOVE==2){
int s2 = 1 + rand() % 8;
if(www%5==s2){
cout<<playerName2<<"虚弱了"<<endl;
f1-=25;
if(f1<=0) f1=10;
}
}
}
cout<<playerName2<<"还剩"<<e1<<"滴血"<<endl;
if(e1<=0){
cout<<playerName1<<" is win."<<endl;
break;
}
cout<<"\n【"<<playerName2<<"】出招"<<endl<<"1.普攻 2.技能 3.治疗"<<endl;
cin>>j;
if(j==1){
g1+=10;
e=e-f1;
}
else if(j==3)
e1+=10;
else if(j==2){
g1-=20;
e=e-i;
if(g1<20){
e1+=i;
cout<<"没蓝了!"<<endl;
}
if(LOVE1==1){
int w = 1 + rand() % 10;
if(www%5==w){
cout<<playerName1<<"被灼烧"<<endl;
e -= 25;
}
}
if(LOVE1==2){
if(www%5==0){
cout<<playerName1<<"虚弱了"<<endl;
f-=25;
if(f<=0) f=10;
}
}
}
cout<<playerName1<<"还剩"<<e<<"滴血"<<endl;
if(e<=0){
cout<<playerName2<<" is win."<<endl;
break;
}
}
// ====================================== 你的原版商店(强化无限买,机甲永久存) ======================================
cout<<"\n====================="<<endl;
cout << "当前钱币:" << o << endl;
cout<<"1.买东西 2.不买 3.背包 4.P1存档 5.P2存档"<<endl;
int mai;
cin >> mai;
if(mai == 4) { saveP1(); continue; }
if(mai == 5) { saveP2(); continue; }
// 背包:已买机甲可用
if (mai == 3) {
cout << "======= 机甲背包 =======" << endl;
cout << "0.保留当前 1.苍雷星甲 2.幽夜魔铠 3.辉光圣骑 4.深渊行者 5.风焰战王" << endl;
int bag; cin >> bag;
if (bag == 1 && have_mecha1[1]) { e=2600;f=50;g=170;h=140;cout<<"已装备:苍雷星甲"<<endl; }
if (bag == 2 && have_mecha1[2]) { e=2700;f=45;g=190;h=135;cout<<"已装备:幽夜魔铠"<<endl; }
if (bag == 3 && have_mecha1[3]) { e=4800;f=32;g=140;h=140;cout<<"已装备:辉光圣骑"<<endl; }
if (bag == 4 && have_mecha1[4]) { e=2600;f=42;g=270;h=135;cout<<"已装备:深渊行者"<<endl; }
if (bag == 5 && have_mecha1[5]) { e=2700;f=48;g=260;h=138;cout<<"已装备:风焰战王"<<endl; }
init_e = e; init_g = g;
}
// 商店:强化无限买
if (mai == 1) {
int luck = rand() % 36;
if (luck == 0) {
cout << "星空商店!1.苍雷 2.幽夜 3.辉光 4.深渊 5.风焰 6.取消" << endl;
int xk; cin >> xk;
if(xk>=1&&xk<=5 && o>=500){
have_mecha1[xk] = true; o-=500; cout<<"购买成功!"<<endl;
}
} else {
cout << "1.力量+20 2.生命+200 3.能量+50 4.攻击+15 5.生命+300 6.攻击+18" << endl;
int sb; cin >> sb;
if (sb == 1 && o>=100) { o-=100;f+=20;cout<<"力量+20!"<<endl; }
if (sb == 2 && o>=150) { o-=150;e+=200;init_e=e;cout<<"生命+200!"<<endl; }
if (sb == 3 && o>=80) { o-=80;g+=50;cout<<"能量+50!"<<endl; }
if (sb == 4 && o>=120) { o-=120;f+=15;cout<<"攻击+15!"<<endl; }
if (sb == 5 && o>=200) { o-=200;e+=300;init_e=e;cout<<"生命+300!"<<endl; }
if (sb == 6 && o>=130) { o-=130;f+=18;cout<<"攻击+18!"<<endl; }
}
}
cout<<"\n再来一局?1.是 2.否"<<endl;
int ai; cin>>ai;
if(ai != 1) break;
// 重置血量
e = init_e; g = init_g; e1 = init_e1; g1 = init_g1;
}
cout<<endl;
cout<<"总制作者:范泽群"<<endl<<"辅助制作:马**,范**。"<<endl<<"格式矫正:王**。"<<endl;
cout<<"热心试玩:赵**"<<endl<<"出版社:fzq带我飞~出版。"<<endl<<"感谢支持!"<<endl;
cout<<"还得有2.1版本出呢,别着急别着急想复制就复制,不想复制。"<<endl;
cout<<"做的一些功劳都是豆包整的(懒&&不会)"<<endl;
int caidan;
cin>>caidan;
if(caidan==4)
cout<<"我朋友很少,交个朋友~";
return 0;
}
2 comments
-
ALT_wangshuoran LV 9 @ 2026-4-11 12:30:54无含金量,纯不好玩
-
@ 2026-3-30 21:47:50
6不6~
- 1