33,311
社区成员
发帖
与我相关
我的任务
分享
比如
switch(a)
case 1:
switch(b)
case 2:####
case 2:....
####那里怎样写才可以跳出所有switch语句
void Role::fight(Role *other)
{
int a,b,c,d,m1,m2;
static int times=0;
cout<<"输入编号: 1.普通攻击 2.使用魔法 3.使用必杀技 4.逃跑 5.离开"<<endl;
do
{
cin>>a;
switch(a)
{
case 1:
hurt(other);
times++;
break;
case 2:
cout<<"输入要使用魔法的编号: 1.天神下凡(100 mana) 2.死亡凋零(200 mana) 3.致命一击(100 mana) 4.无敌(160 mana) 5.分身(80 mana) 6.返回"<<endl;
cin>>b;
if(b==1||b==2||b==3||b==4||b==5)
times++;
switch(b)
{
case 1:
attack*=1.2;
defense*=1.2;
cout<<"攻击力与防御力提升20%"<<endl;
hurt(other);
attack*=5.0/6.0;
defense*=5.0/6.0;
break;
case 2:
other->hp*=0.7;
cout<<"消耗对手30%生命"<<endl;
break;
case 3:
attack+=attack/2;
cout<<"攻击提高50%"<<endl;
hurt(other);
attack*=2.0/3.0;
break;
case 4:
defense+=10000;
cout<<"无敌状态"<<endl;
hurt(other);
defense-=10000;
break;
case 5:
m1=rand()%2;
if(m1)
defense+=10000;
cout<<"产生1个幻象,迷惑对手,对手有50%概率打中幻象"<<endl;
hurt(other);
if(m1)
defense-=10000;
break;
case 6:
break;
}
break;
case 3:
if(times>=8)
{
cout<<"使用必杀技<剑刃风暴>"<<endl;
other->hp*=40%;
times-=7;
}
else
cout<<"怒气到达一定值时才能使用"<<endl;
break;
case 4:
m2=rand()%3;
if(m2)
{
cout<<"逃跑成功"<<endl;这里可以实现吗?
a=6;
break;
}
else
{
cout<<"逃跑失败"<<endl;
hurt(other);
}
break;
case 5:
if(other->hp>0)
cout<<"战斗还没有结束,不能离开,但你可以选择逃跑"<<endl;
break;
}
}while (a==6);
}