我最近开始尝试用 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;
}
提前感谢所有帮助,并为我犯的任何愚蠢的错误道歉。