Untitled
unknown
csharp
a year ago
1.9 kB
2
Indexable
Never
using System; class Character { private int health; private int damage; private int shield; //constructor public Character(int health, int damage, int shield) { this.health = health; this.damage = damage; this.shield = shield; }//End of Constructor //Getters public int GetHealth() { return health; } public int GetDamage() { return damage; } public int GetShield() { return shield; } //Setters public void SetHealth(int newHealth) { health = newHealth; } //RecieveDamage Method public virtual void ReceiveDamage(int damage) { int currentDamage = damage - shield; health -= currentDamage; if (health <= 0) { Console.WriteLine("Character has died"); } }//End of Method }//End of Class class Swordsman : Character { public Swordsman() : base(100, 10, 10) { }//End of Constructor }//End of Class class Paladin : Character { private bool hasResurrected; public Paladin() : base(100, 10, 10) { this.hasResurrected = false; }//End of Constructor public override void ReceiveDamage(int damage) { int currentDamage = 0; if (damage % 2 == 0) { currentDamage = (damage / 2) - GetShield(); SetHealth(GetHealth() - currentDamage); } else { currentDamage = damage - GetShield(); SetHealth(GetHealth() - currentDamage); } if (GetHealth() <= 0) { Resurrect(); } }//End of Method public void Resurrect() { if (!hasResurrected) { hasResurrected = true; SetHealth(100); } else { Console.WriteLine("Paladin has died"); } }//End of Method }//End of Class