Beispiel #1
0
        public string Heal(string[] args)
        {
            string healerName          = args[0];
            string healingReceiverName = args[1];

            if (!this.characterParty.ContainsKey(healerName))
            {
                throw new ArgumentException(string.Format(ExceptionMessages.CharacterNotInParty, healerName));
            }
            if (!this.characterParty.ContainsKey(healingReceiverName))
            {
                throw new ArgumentException(string.Format(ExceptionMessages.CharacterNotInParty, healingReceiverName));
            }

            Priest healer = (Priest)this.characterParty.FirstOrDefault(c => c.Key == healerName).Value;

            if (healer.GetType().Name != nameof(Priest))
            {
                throw new ArgumentException(string.Format(ExceptionMessages.HealerCannotHeal, healerName));
            }

            Character healingReceiver = this.characterParty.FirstOrDefault(c => c.Key == healingReceiverName).Value;

            healer.Heal(healingReceiver);

            return(string.Format(SuccessMessages.HealCharacter, healer.Name, healingReceiver.Name, healer.AbilityPoints, healingReceiver.Name, healingReceiver.Health));
        }
Beispiel #2
0
        public string Heal(string[] args)
        {
            string healerName   = args[0];
            string receiverName = args[1];

            Priest    healing   = (Priest)characters.FirstOrDefault(n => n.Name == healerName);
            Character receiving = characters.FirstOrDefault(n => n.Name == receiverName);

            if (healing == null)
            {
                throw new ArgumentException(string.Format(ExceptionMessages.CharacterNotInParty), healerName);
            }
            if (receiving == null)
            {
                throw new ArgumentException(string.Format(ExceptionMessages.CharacterNotInParty), receiverName);
            }
            if (healing.GetType().Name == nameof(Warrior))
            {
                throw new ArgumentException(string.Format(ExceptionMessages.AttackFail), healerName);
            }

            healing.Heal(receiving);

            StringBuilder sb = new StringBuilder();

            sb.AppendLine($"{healing.Name} heals {receiving.Name} for {healing.AbilityPoints}! {receiving.Name} has {receiving.Health} health now!");

            return(sb.ToString().TrimEnd());
        }