C++/C策略打怪小游戏 (修复并优化了的版本)

emm,作者的游戏没有退出功能,并且还有许多的BUG特性 ,所以我优化了一下

https://blog.csdn.net/qq_30323637/article/details/108243122
原文在这里?

优化后的第一版:添加了退出功能

#include <iostream>
using namespace std;
int main()
{
int shengming = 30, gongji = 10, jinbi = 10, smsx = 30, duobi1 = 3;
int a = 0, b = 0, c = 0;
cout << "国难当道,你被选为了战士保护人民。因此您拥有以下技能:";
for (int i = 0; i < 1; i--)
{
cout << endl
<< "1.购买装备和恢复生命。" << endl;
cout << "2.打怪专区。" << endl;
cout << "3.个人信息。" << endl;
cout << "4.退出游戏。" << endl
<< "输入:";
cin >> a;
if (a == 1)
{
while (1)
{
cout << endl
<< "你的信息:(生命" << shengming << "),(攻击" << gongji << "),(金币" << jinbi << ")" << endl;
cout << "1.武器 金币>=10" << endl;
cout << "2.生命 10金币+满。" << endl;
cout << "3.生命上线 金币>=40" << endl;
cout << "4.躲避次数+1 15金币" << endl;
cout << "按0退出。" << endl
<< "输入:";
cin >> b;
if (b == 1 && jinbi >= 10)
{
while (1)
{
cout << endl
<< "1.石剑——10金币+5" << endl;
cout << "2.铁剑——50金币+25" << endl;
cout << "3.钻石剑——200金币+100" << endl;
cout << "4.神灵剑——1000金币+500" << endl;
cout << "0退出。" << endl
<< "输入:";
cin >> c;
if (c == 1 && jinbi >= 10)
{
gongji += 5;
jinbi -= 10;
cout << "攻击:" << gongji - 5 << "+5=" << gongji << endl;
}
else if (c == 2 && jinbi >= 50)
{
gongji += 25;
jinbi -= 50;
cout << "攻击:" << gongji - 25 << "+25=" << gongji << endl;
}
else if (c == 3 && jinbi >= 200)
{
gongji += 100;
jinbi -= 200;
cout << "攻击:" << gongji - 100 << "+100=" << gongji << endl;
}
else if (c == 4 && jinbi >= 1000)
{
gongji += 500;
jinbi -= 1000;
cout << "攻击:" << gongji - 500 << "+500=" << gongji << endl;
}
else if (c == 0)
{
break;
}
else if (c > 3)
{
cout << "没有这个按键。" << endl;
}
else
{
cout << "金币不够。" << endl
<< endl;
}
}
}
else if (b == 2 && jinbi >= 10)
{
shengming = smsx;
jinbi -= 10;
cout << "生命=" << smsx << endl;
}
else if (b == 3 && jinbi >= 40)
{
while (1)
{
cout << endl
<< "1.生命上线四等——40金币+10" << endl;
cout << "2.生命上线三等——100金币+25" << endl;
cout << "3.生命上线二等——400金币+100" << endl;
cout << "4.生命上线一等——2000金币+500" << endl;
cout << "0退出。" << endl
<< "输入:";
cin >> c;
if (c == 1)
{
smsx += 10;
shengming += 10;
jinbi -= 40;
cout << "生命上线:" << smsx - 10 << "+10=" << smsx << endl;
}
else if (c == 2 && jinbi >= 100)
{
smsx += 25;
shengming += 25;
jinbi -= 100;
cout << "生命上线:" << smsx - 25 << "+25=" << smsx << endl;
}
else if (c == 3 && jinbi >= 400)
{
smsx += 100;
shengming += 100;
jinbi -= 400;
cout << "生命上线:" << smsx - 100 << "+100=" << smsx << endl;
}
else if (c == 4 && jinbi >= 2000)
{
smsx += 500;
shengming += 500;
jinbi -= 2000;
cout << "生命上线:" << smsx - 500 << "+500=" << smsx << endl;
}
else if (c == 0)
{
break;
}
else
{
cout << "金币不够。" << endl
<< endl;
}
}
}
else if (b == 4 && jinbi >= 20)
{
duobi1 += 1;
jinbi -= 15;
cout << "躲避次数+1=" << duobi1 << endl;
}
else if (b == 0)
{
break;
}
else
{
cout << "金币不够。" << endl;
}
}
}
else if (a == 2)
{
while (1)
{
cout << endl
<< "1.地方小怪——生命20,攻击10,可获得金币10" << endl;
cout << "2.地方大怪——生命100,攻击25,可获得金币25" << endl;
cout << "3.小怪——生命400,攻击100,可获得金币100" << endl;
cout << "4.大怪——生命1000,攻击500,可获得金币500" << endl;
cout << "0退出。" << endl
<< "输入:";
cin >> b;
if (b == 1)
{
int sm = 20, gj = 10;
int duobi = duobi1;
cout << endl
<< "地方小怪——生命20,攻击10,可获得金币10" << endl
<< "你的攻击力:" << gongji << " "
<< "生命力:" << shengming << endl
<< endl
<< "开始 你VS怪物" << endl;
while (sm > 0)
{
cout << endl
<< "1.攻击 2.躲避(" << duobi << ")可让怪物生命-5" << endl
<< "输入:";
cin >> c;
if (c == 1)
{
shengming -= gj;
sm -= gongji;
cout << endl
<< "我的生命:" << shengming << endl;
cout << "敌方生命:" << sm << endl;
}
else if (duobi > 0)
{
cout << "躲避成功。" << endl;
duobi--;
sm -= 5;
cout << "敌人生命:" << sm + 5 << "-5=" << sm << endl;
}
if (shengming <= 0)
{
cout << "你死了。" << endl;
return 0;
}
}
jinbi += 10;
cout << "恭喜您获得金币10" << endl;
}
else if (b == 2)
{
cout << endl
<< "地方大怪——生命100,攻击25,可获得金币25" << endl
<< "你的攻击力:" << gongji << " "
<< "生命力:" << shengming << endl
<< endl
<< "开始 你VS怪物" << endl;
int sm = 100, gj = 25;
int duobi = duobi1;
while (sm > 0)
{
cout << endl
<< "1.攻击 2.躲避(" << duobi << ")" << endl
<< "输入:";
cin >> c;
if (c == 1)
{
shengming -= gj;
sm -= gongji;
cout << endl
<< "我的生命:" << shengming << endl;
cout << "敌方生命:" << sm << endl;
}
else if (duobi > 0)
{
cout << "躲避成功。" << endl;
duobi--;
sm -= 5;
cout << "敌人生命:" << sm + 5 << "-5=" << sm << endl;
}
if (shengming <= 0)
{
cout << "你死了。" << endl;
return 0;
}
}
jinbi += 25;
cout << "恭喜您获得金币25" << endl;
}
else if (b == 3)
{
cout << endl
<< "小怪——生命400,攻击100,可获得金币100" << endl
<< "你的攻击力:" << gongji << " "
<< "生命力:" << shengming << endl
<< endl
<< "开始 你VS怪物" << endl;
int sm = 400, gj = 100;
int duobi = duobi1;
while (sm > 0)
{
cout << endl
<< "1.攻击 2.躲避(" << duobi << ")" << endl
<< "输入:";
cin >> c;
if (c == 1)
{
shengming -= gj;
sm -= gongji;
cout << endl
<< "我的生命:" << shengming << endl;
cout << "敌方生命:" << sm << endl;
}
else if (duobi > 0)
{
cout << "躲避成功。" << endl;
duobi--;
sm -= 5;
cout << "敌人生命:" << sm + 5 << "-5=" << sm << endl;
}
if (shengming <= 0)
{
cout << "你死了。" << endl;
return 0;
}
}
jinbi += 100;
cout << "恭喜您获得金币100" << endl;
}
else if (b == 4)
{
cout << endl
<< "大怪——生命1000,攻击500,可获得金币500" << endl
<< "你的攻击力:" << gongji << " "
<< "生命力:" << shengming << endl
<< endl
<< "开始 你VS怪物" << endl;
int sm = 1000, gj = 500;
int duobi = duobi1;
while (sm > 0)
{
cout << endl
<< "1.攻击 2.躲避(" << duobi << ")" << endl
<< "输入:";
cin >> c;
if (c == 1)
{
shengming -= gj;
sm -= gongji;
cout << endl
<< "我的生命:" << shengming << endl;
cout << "敌方生命:" << sm << endl;
}
else if (duobi > 0)
{
cout << "躲避成功。" << endl;
duobi--;
sm -= 5;
cout << "敌人生命:" << sm + 5 << "-5=" << sm << endl;
}
if (shengming <= 0)
{
cout << "你死了。" << endl;
return 0;
}
}
jinbi += 100;
cout << "恭喜您获得金币500" << endl;
}
else if (b == 0)
{
break;
}
}
}
else if (a == 3)
{
cout << endl
<< "你的生命:" << shengming << endl;
cout << "你的攻击:" << gongji << endl;
cout << "你的金币:" << jinbi << endl;
cout << "防御次数:" << duobi1 << endl;
cout << "生命上限:" << smsx << endl;
}
else if (a == 4)
{
cout << "游戏已退出。" << endl;
system("pause");
return 0;
}
}
return 0;
}

优化后的第二版:修复了几个BUG 特性,分别为:

1.修改了不合理的文字和错别字
2.优化了战斗,不会再出现死循环或者无限躲避
3.添加了魔王,战胜后即可通关
4.修正了战胜获得金币的数量
5.更加银杏化的购买界面
6.死亡后不会立即退出游戏,会在按下按键后退出
7.修改了剧情(就四个字 ㄟ( ▔, ▔ )ㄏ)

#include <iostream>
using namespace std;
int main()
{
int shengming = 30, gongji = 10, jinbi = 10, smsx = 30, duobi1 = 3;
int a = 0, b = 0, c = 0, d = 0;
cout << "魔王出世,国难当道,你被选为了战士保护人民。因此您拥有以下技能:";
for (int i = 0; i < 1; i--)
{
cout << endl
<< "1.购买装备和恢复生命。" << endl;
cout << "2.打怪专区。" << endl;
cout << "3.个人信息。" << endl;
cout << "4.退出游戏。" << endl
<< "输入:";
cin >> a;
if (a == 1)
{
while (1)
{
cout << endl
<< "你的信息:(生命" << shengming << "),(攻击" << gongji << "),(金币" << jinbi << ")" << endl;
cout << "1.武器 金币>=10" << endl;
cout << "2.生命 10金币+满" << endl;
cout << "3.生命上限 金币>=40" << endl;
cout << "4.躲避 金币>=15" << endl;
cout << "0.退出。" << endl
<< "输入:";
cin >> b;
if (b == 1 && jinbi >= 10)
{
while (1)
{
cout << endl
<< "1.石剑——10金币+5" << endl;
cout << "2.铁剑——50金币+25" << endl;
cout << "3.钻石剑——200金币+100" << endl;
cout << "4.神灵剑——1000金币+500" << endl;
cout << "0.退出。" << endl
<< "输入:";
cin >> c;
if (c == 1 && jinbi >= 10)
{
gongji += 5;
jinbi -= 10;
cout << "攻击:" << gongji - 5 << "+5=" << gongji << endl;
}
else if (c == 2 && jinbi >= 50)
{
gongji += 25;
jinbi -= 50;
cout << "攻击:" << gongji - 25 << "+25=" << gongji << endl;
}
else if (c == 3 && jinbi >= 200)
{
gongji += 100;
jinbi -= 200;
cout << "攻击:" << gongji - 100 << "+100=" << gongji << endl;
}
else if (c == 4 && jinbi >= 1000)
{
gongji += 500;
jinbi -= 1000;
cout << "攻击:" << gongji - 500 << "+500=" << gongji << endl;
}
else if (c == 0)
{
break;
}
else if (c > 3)
{
cout << "没有这个按键。" << endl;
}
else
{
cout << "金币不够。" << endl
<< endl;
}
}
}
else if (b == 2 && jinbi >= 10)
{
shengming = smsx;
jinbi -= 10;
cout << "生命=" << smsx << endl;
}
else if (b == 3 && jinbi >= 40)
{
while (1)
{
cout << endl
<< "1.一级生命上限——40金币+10" << endl;
cout << "2.二级生命上限——100金币+25" << endl;
cout << "3.三级生命上限——400金币+100" << endl;
cout << "4.四级生命上限——2000金币+500" << endl;
cout << "0.退出。" << endl
<< "输入:";
cin >> c;
if (c == 1)
{
smsx += 10;
shengming += 10;
jinbi -= 40;
cout << "生命上限:" << smsx - 10 << "+10=" << smsx << endl;
}
else if (c == 2 && jinbi >= 100)
{
smsx += 25;
shengming += 25;
jinbi -= 100;
cout << "生命上限:" << smsx - 25 << "+25=" << smsx << endl;
}
else if (c == 3 && jinbi >= 400)
{
smsx += 100;
shengming += 100;
jinbi -= 400;
cout << "生命上限:" << smsx - 100 << "+100=" << smsx << endl;
}
else if (c == 4 && jinbi >= 2000)
{
smsx += 500;
shengming += 500;
jinbi -= 2000;
cout << "生命上限:" << smsx - 500 << "+500=" << smsx << endl;
}
else if (c == 0)
{
break;
}
else
{
cout << "金币不够。" << endl
<< endl;
}
}
}
else if (b == 4 && jinbi >= 15)
{
while (1)
{
cout << endl
<< "1.一级躲避——15金币+1" << endl;
cout << "2.二级躲避——150金币+10" << endl;
cout << "3.三级躲避——300金币+20" << endl;
cout << "4.四级躲避——1500金币+100" << endl;
cout << "0.退出。" << endl
<< "输入:";
cin >> c;
if (c == 1)
{
duobi1 += 1;
jinbi -= 15;
cout << "躲避次数:" << duobi1 - 1 << "+1=" << duobi1 << endl;
}
else if (c == 2 && jinbi >= 100)
{
duobi1 += 10;
jinbi -= 150;
cout << "躲避次数:" << duobi1 - 10 << "+10=" << duobi1 << endl;
}
else if (c == 3 && jinbi >= 400)
{
duobi1 += 20;
jinbi -= 300;
cout << "躲避次数:" << duobi1 - 20 << "+20=" << duobi1 << endl;
}
else if (c == 4 && jinbi >= 2000)
{
duobi1 += 100;
jinbi -= 1500;
cout << "躲避次数:" << duobi1 - 100 << "+100=" << duobi1 << endl;
}
else if (c == 0)
{
break;
}
else
{
cout << "金币不够。" << endl
<< endl;
}
}
}
else if (b == 0)
{
break;
}
else
{
cout << "金币不够。" << endl;
}
}
}
else if (a == 2)
{
while (1)
{
cout << endl
<< "1.地方小怪——生命20,攻击10,可获得金币10" << endl;
cout << "2.地方大怪——生命100,攻击25,可获得金币25" << endl;
cout << "3.小怪——生命400,攻击100,可获得金币100" << endl;
cout << "4.大怪——生命1000,攻击500,可获得金币500" << endl;
cout << "5.魔王——生命5000,攻击1000,可获得金币1000,并通关游戏" << endl;
cout << "0.退出。" << endl
<< "输入:";
cin >> b;
if (b == 1)
{
int sm = 20, gj = 10;
int duobi = duobi1;
cout << endl
<< "地方小怪——生命20,攻击10,可获得金币10" << endl
<< "你的攻击力:" << gongji << " "
<< "生命力:" << shengming << endl
<< endl
<< "开始 你VS怪物" << endl;
while (sm > 0)
{
cout << endl
<< "1.攻击 2.躲避(" << duobi << ")可让怪物生命-5" << endl
<< "输入:";
cin >> c;
if (c == 1)
{
shengming -= gj;
sm -= gongji;
cout << endl
<< "我的生命:" << shengming << endl;
cout << "敌方生命:" << sm << endl;
}
else if (c == 2)
{
if (duobi > 0)
{
cout << "躲避成功。" << endl;
duobi--;
sm -= 5;
cout << "敌人生命:" << sm + 5 << "-5=" << sm << endl;
}
else if (duobi == 0)
{
cout << "躲避失败。 受到攻击" << endl;
shengming -= gj;
cout << endl
<< "我的生命:" << shengming << endl;
cout << "敌方生命:" << sm << endl;
}
}
else
{
cout << "没有这个按键。" << endl;
}

if (shengming <= 0)
{
cout << "你死了。" << endl;
system("pause");
return 0;
}
}
jinbi += 10;
cout << "恭喜您获得金币10" << endl;
}
else if (b == 2)
{
cout << endl
<< "地方大怪——生命100,攻击25,可获得金币25" << endl
<< "你的攻击力:" << gongji << " "
<< "生命力:" << shengming << endl
<< endl
<< "开始 你VS怪物" << endl;
int sm = 100, gj = 25;
int duobi = duobi1;
while (sm > 0)
{
cout << endl
<< "1.攻击 2.躲避(" << duobi << ")可让怪物生命-5" << endl
<< "输入:";
cin >> c;
if (c == 1)
{
shengming -= gj;
sm -= gongji;
cout << endl
<< "我的生命:" << shengming << endl;
cout << "敌方生命:" << sm << endl;
}
else if (c == 2)
{
if (duobi > 0)
{
cout << "躲避成功。" << endl;
duobi--;
sm -= 5;
cout << "敌人生命:" << sm + 5 << "-5=" << sm << endl;
}
else if (duobi == 0)
{
cout << "躲避失败。 受到攻击" << endl;
shengming -= gj;
cout << endl
<< "我的生命:" << shengming << endl;
cout << "敌方生命:" << sm << endl;
}
}
else
{
cout << "没有这个按键。" << endl;
}

if (shengming <= 0)
{
cout << "你死了。" << endl;
system("pause");
return 0;
}
}
jinbi += 100;
cout << "恭喜您获得金币100" << endl;
}
else if (b == 4)
{
cout << endl
<< "大怪——生命1000,攻击500,可获得金币500" << endl
<< "你的攻击力:" << gongji << " "
<< "生命力:" << shengming << endl
<< endl
<< "开始 你VS怪物" << endl;
int sm = 1000, gj = 500;
int duobi = duobi1;
while (sm > 0)
{
cout << endl
<< "1.攻击 2.躲避(" << duobi << ")可让怪物生命-5" << endl
<< "输入:";
cin >> c;
if (c == 1)
{
shengming -= gj;
sm -= gongji;
cout << endl
<< "我的生命:" << shengming << endl;
cout << "敌方生命:" << sm << endl;
}
else if (c == 2)
{
if (duobi > 0)
{
cout << "躲避成功。" << endl;
duobi--;
sm -= 5;
cout << "敌人生命:" << sm + 5 << "-5=" << sm << endl;
}
else if (duobi == 0)
{
cout << "躲避失败。 受到攻击" << endl;
shengming -= gj;
cout << endl
<< "我的生命:" << shengming << endl;
cout << "敌方生命:" << sm << endl;
}
}
else
{
cout << "没有这个按键。" << endl;
}

if (shengming <= 0)
{
cout << "你死了。" << endl;
system("pause");
return 0;
}
}
jinbi += 500;
cout << "恭喜您获得金币500" << endl;
}
else if (b == 5)
{
cout << endl
<< "魔王——生命5000,攻击1000,可获得金币1000,并通关游戏" << endl
<< "你的攻击力:" << gongji << " "
<< "生命力:" << shengming << endl
<< endl
<< "开始 你VS魔王" << endl;
int sm = 5000, gj = 1000;
int duobi = duobi1;
while (sm > 0)
{
cout << endl
<< "1.攻击 2.躲避(" << duobi << ")可让魔王生命-5" << endl
<< "输入:";
cin >> c;
if (c == 1)
{
shengming -= gj;
sm -= gongji;
cout << endl
<< "我的生命:" << shengming << endl;
cout << "魔王生命:" << sm << endl;
}
else if (c == 2)
{
if (duobi > 0)
{
cout << "躲避成功。" << endl;
duobi--;
sm -= 5;
cout << "魔王生命:" << sm + 5 << "-5=" << sm << endl;
}
else if (duobi == 0)
{
cout << "躲避失败。 受到攻击" << endl;
shengming -= gj;
cout << endl
<< "我的生命:" << shengming << endl;
cout << "敌方生命:" << sm << endl;
}
}
else
{
cout << "没有这个按键。" << endl;
}

if (shengming <= 0)
{
cout << "你死了。" << endl;
system("pause");
return 0;
}
}
jinbi += 1000;
cout << "恭喜您打败魔王,通关了游戏!" << endl;
system("pause");
return 0;
}
else if (b == 0)
{
break;
}
}
}
else if (a == 3)
{
cout << endl
<< "你的生命:" << shengming << endl;
cout << "你的攻击:" << gongji << endl;
cout << "你的金币:" << jinbi << endl;
cout << "防御次数:" << duobi1 << endl;
cout << "生命上限:" << smsx << endl;
}
else if (a == 4)
{
cout << "游戏已退出。" << endl;
system("pause");
return 0;
}
}
return 0;
}

话说这BUG稍微一修就修出这么多
肯定是我太厉害了
(不知道算不算侵权,侵权就删了吧。)

原创:https://www.panoramacn.com
源码网提供WordPress源码,帝国CMS源码discuz源码,微信小程序,小说源码,杰奇源码,thinkphp源码,ecshop模板源码,微擎模板源码,dede源码,织梦源码等。

专业搭建小说网站,小说程序,杰奇系列,微信小说系列,app系列小说

C++/C策略打怪小游戏 (修复并优化了的版本)

免责声明,若由于商用引起版权纠纷,一切责任均由使用者承担。

您必须遵守我们的协议,如果您下载了该资源行为将被视为对《免责声明》全部内容的认可-> 联系客服 投诉资源
www.panoramacn.com资源全部来自互联网收集,仅供用于学习和交流,请勿用于商业用途。如有侵权、不妥之处,请联系站长并出示版权证明以便删除。 敬请谅解! 侵权删帖/违法举报/投稿等事物联系邮箱:2640602276@qq.com
未经允许不得转载:书荒源码源码网每日更新网站源码模板! » C++/C策略打怪小游戏 (修复并优化了的版本)
关注我们小说电影免费看
关注我们,获取更多的全网素材资源,有趣有料!
120000+人已关注
分享到:
赞(0) 打赏

评论抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

您的打赏就是我分享的动力!

支付宝扫一扫打赏

微信扫一扫打赏