我想我需要转换这段代码。我需要返回一个 int 但我必须乘以百分比并且不希望它们被切断。
我应该像这样投射它还brains = (double)brains - (this.getBrains() * 0.01);
应该在最后投射return语句吗?我在选角方面很弱,我一直在努力寻找帮助的例子,但他们没有帮助。
if(attacker >= attackee)
{
switch (weapon)
{
case 't':
brains = brains + (other.getBrains() * 0.01);
attack = other.getBrains() * -0.01;
other.addBrains(attack);
break;
case 's':
brains = brains + (other.getBrains() * 0.05);
attack = other.getBrains() * -0.05;
other.addBrains(attack);
break;
case 'c':
brains = brains + (other.getBrains() * 0.10);
attack = other.getBrains() * -0.10;
other.addBrains(attack);
break;
case 'k':
brains = brains + (other.getBrains() * 0.20);
attack = other.getBrains() * -0.20;
other.addBrains(attack);
break;
}
}
else
{
switch (weapon)
{
case 't':
brains = brains - (this.getBrains() * 0.01);
attack = this.getBrains() * 0.01;
other.addBrains(attack);
break;
case 's':
brains = brains - (this.getBrains() * 0.01);
attack = this.getBrains() * 0.01;
other.addBrains(attack);
break;
case 'c':
brains = brains - (this.getBrains() * 0.01);
attack = this.getBrains() * 0.01;
other.addBrains(attack);
break;
case 'k':
brains = brains - (this.getBrains() * 0.01);
attack = this.getBrains() * 0.01;
other.addBrains(attack);
break;
}
}
return attack;
}