我有一个船体和盾牌,我想在受损时承受伤害并首先从盾牌中扣除它,然后当它是空的时从船体中扣除。但是,如果盾牌还剩 100,伤害为 400,那么如果从 1000 开始,船体将是 700。
在这里,我设法做到了,盾牌部分有效,但船体算法对我来说太难掌握了。
Player.prototype.deductHealth = function(damage)
{
var shield = (this.PlayerShield - damage);
var remainder = (damage - this.PlayerShield);
var hull = this.PlayerHull;
if(this.PlayerShield < 0)
{
hull = (this.PlayerHull - remainder);
}
if(hull <=0)
{
hull = 0;
shield = 0;
}
this.PlayerHull = hull;
this.PlayerShield = shield;
}