public void Damage(int da) // damage amount { for (int i = heartList.Count - 1; i >= 0; i--) { HeartB heart = heartList[i]; if (da > heart.GetFragmentAmount()) // Test if this heart can absorb damageAmount { da -= heart.GetFragmentAmount(); // Heart cannot absorb full damageAmount, damage heart and keep going to next heart heart.Damage(heart.GetFragmentAmount()); } else { heart.Damage(da); break; } } OnDamaged(this, EventArgs.Empty); if (IsDead()) { OnDead(this, EventArgs.Empty); } }
public void addHealth(int healAmount) { for (int i = 0; i < heartList.Count; i++) { HeartB heart = heartList[i]; //check current health int emptyHeart = max_Heart - heart.GetFragmentAmount(); if (healAmount > emptyHeart) { healAmount -= emptyHeart; heart.addHealth(emptyHeart); } else { heart.addHealth(healAmount); } } OnHeal(this, EventArgs.Empty); }