菜鸟在编码(文本战斗系统)方面存在问题
Noob has problems in coding (text combat system)
我最近开始尝试用C++编程。我正在为我的文字冒险创建一个战斗系统,但我遇到了一些问题。例如,我希望战斗在你或对手死亡时结束。目前,只有当两个人都死了,它才会结束。另一个是,如果你的防御大于攻击,你可以通过攻击来治愈。你能在这里帮助菜鸟吗?:D这是代码:
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <iso646.h>
int main()
{
int att, def, hp, eatt, edef, ehp, pinput, einput;
cout<<"Your damgae"<<endl;
cin>>att;
cout<<"Your defence"<<endl;
cin>>def;
cout<<"Your hp"<<endl;
cin>>hp;
cout<<"Enemy attack"<<endl;
cin>>eatt;
cout<<"Enemy defence"<<endl;
cin>>edef;
cout<<"Enemy hp"<<endl;
cin>>ehp;
do {
srand (time(NULL));
einput=rand()%2+1;
cout<<"1) attack 2) defend"<<endl;
cin>>pinput;
if (pinput==1) {
if (einput==1) {
cout<<"enemy defends"<<endl;
att=att-edef;
ehp=ehp-att;
cout<<"Enemy hp now is:"<<ehp<<endl;
att=att+edef;
}
if (einput==2) {
cout<<"enemy doesn't defend but attacks you too"<<endl;
hp=hp-eatt;
ehp=ehp-att;
cout<<"Your hp is:"<<hp<<endl;
cout<<"Enemy hp now is:"<<ehp<<endl;
}
}
if (pinput==2) {
if (einput==1) cout<<"enemy stands in defence aswell"<<endl;
if (einput==2) {
cout<<"enemy attacks you"<<endl;
eatt=eatt-def;
hp=hp-eatt;
eatt=eatt+def;
cout<<"Your hp is:"<<hp<<endl;
}
}
}
while (ehp>0||hp>0);
if (ehp<1) cout<<"You win"<<endl;
if (hp<1) cout<<"You die"<<endl;
system("PAUSE");
return 0;
}
提前感谢所有的帮助,并为我犯的任何愚蠢错误感到抱歉。
第一个问题很容易解决,使用&&
不||
,你想在你的生命值>0,敌人命中点>0的情况下继续前进。
while (ehp>0 && hp>0);
相关文章:
- C++,系统无法执行指定的程序
- 在UNIX系统中使用DIR查找文件的字节大小
- 错误处理.将系统错误代码映射到泛型
- 当系统的卷被修改时,如何修改WASAPI环回捕获卷
- 有什么好的方法可以让系统调用代理允许在单元测试中进行模拟
- 在C++游戏中与库存系统作斗争
- 文件系统:复制功能的速度秘诀是什么
- c++17文件系统::recursive_directory迭代器()在mac上没有给出这样的目录,但在windows上
- 在gtest.中使用fff.h模拟系统API
- GCC和Clang在与__builtin_constant_p相关的static_assert方面有所不同
- 如何制作无限制照明系统
- 系统.将数组移交给c#中动态加载的c++DLL时发生AccessViolationException
- 如何传递多个 std::文件系统选项?
- 遍历顺序由 std::文件系统directory_iterator给出
- C++系统找不到指定的文件错误
- 系统参数信息A 与 SPI_GETMOUSE 返回 0
- libstdc++ 文件系统中未初始化的用法?
- 如何在ECS框架中更新组件数据和通知系统
- boost::文件系统::recursive_directory_iterator多线程安全
- 菜鸟在编码(文本战斗系统)方面存在问题