Exemple #1
0
        public string Heal(string[] args)
        {
            string    healerName          = args[0];
            string    healingReceiverName = args[1];
            Character healer   = party.FirstOrDefault(c => c.Name == healerName);
            Character receiver = party.FirstOrDefault(c => c.Name == healingReceiverName);

            if (healer == null)
            {
                throw new ArgumentException(string.Format(ExceptionMessages.CharacterNotInParty, healerName));
            }
            if (receiver == null)
            {
                throw new ArgumentException(string.Format(ExceptionMessages.CharacterNotInParty, healingReceiverName));
            }
            if (healer.AbilityPoints == 0)
            {
                throw new ArgumentException(string.Format(ExceptionMessages.HealerCannotHeal, healerName));
            }
            Priest priest = (Priest)healer;

            priest.Heal(receiver);
            return(string.Format(SuccessMessages.HealCharacter,
                                 healer.Name,
                                 receiver.Name,
                                 healer.AbilityPoints,
                                 receiver.Name,
                                 receiver.Health));
        }
Exemple #2
0
        public string Heal(string[] args)
        {
            string healerName          = args[0];
            string healingReceiverName = args[1];

            if (this.characterParty.Any(x => x.Name == healerName) == false)
            {
                throw new ArgumentException($"Character {healerName} not found!");
            }
            if (this.characterParty.Any(x => x.Name == healingReceiverName) == false)
            {
                throw new ArgumentException($"Character {healingReceiverName} not found!");
            }

            var healer   = this.characterParty.FirstOrDefault(x => x.Name == healerName);
            var receiver = this.characterParty.FirstOrDefault(x => x.Name == healingReceiverName);

            if (healer.GetType().Name != "Priest")
            {
                throw new ArgumentException($"{healer.Name} cannot heal!");
            }

            Priest priest = (Priest)healer;

            priest.Heal(receiver);

            return($"{healer.Name} heals {receiver.Name} for {healer.AbilityPoints}! {receiver.Name} has received {receiver.Health} health now.!");
        }
Exemple #3
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));
        }
        public string Heal(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            string healerName          = args[0];
            string healingReceiverName = args[1];

            if (!this.characterRepo.Any(x => x.Name == healerName))
            {
                throw new ArgumentException(string.Format(ExceptionMessages.CharacterNotInParty), healerName);
            }
            if (!this.characterRepo.Any(x => x.Name == healingReceiverName))
            {
                throw new ArgumentException(string.Format(ExceptionMessages.CharacterNotInParty), healingReceiverName);
            }

            if (this.characterRepo.FirstOrDefault(x => x.Name == healerName).GetType().Name != "Priest")
            {
                throw new ArgumentException(string.Format(ExceptionMessages.HealerCannotHeal, healerName));
            }

            Priest    healer   = (Priest)this.characterRepo.FirstOrDefault(x => x.Name == healerName);
            Character reciever = this.characterRepo.FirstOrDefault(x => x.Name == healingReceiverName);

            healer.Heal(reciever);

            sb.AppendLine(String.Format
                              (SuccessMessages.HealCharacter, healer.Name, reciever.Name, healer.AbilityPoints, reciever.Name, reciever.Health));

            return(sb.ToString().TrimEnd());
        }
Exemple #5
0
        public string Heal(string[] args)
        {
            string healerName   = args[0];
            string receiverName = args[1];

            Character healer   = charactersParty.FirstOrDefault(p => p.Name == healerName);
            Character receiver = charactersParty.FirstOrDefault(p => p.Name == receiverName);

            if (healer == null)
            {
                throw new ArgumentException(string.Format(ExceptionMessages.CharacterNotInParty, healerName));
            }

            if (receiver == null)
            {
                throw new ArgumentException(string.Format(ExceptionMessages.CharacterNotInParty, receiverName));
            }

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

            Priest healerToHeal = (Priest)healer;

            healerToHeal.Heal(receiver);


            StringBuilder sb = new StringBuilder();

            sb.AppendLine($"{healer.Name} heals {receiver.Name} for {healer.AbilityPoints}!" +
                          $" {receiver.Name} has {receiver.Health} health now!");

            return(sb.ToString().TrimEnd());
        }
Exemple #6
0
        public string Heal(string[] args)
        {
            string    healerName          = args[0];
            string    healingReceiverName = args[1];
            Character healer          = party.FirstOrDefault(x => x.Name == healerName);
            Character healingReceiver = party.FirstOrDefault(x => x.Name == healingReceiverName);

            if (healer == null)
            {
                throw new ArgumentException($"Character {healerName} not found!");
            }
            if (healingReceiver == null)
            {
                throw new ArgumentException($"Character {healingReceiverName} not found!");
            }
            Priest priest = (Priest)healer;

            priest.Heal(healingReceiver);

            StringBuilder sb = new StringBuilder();

            sb.AppendLine($"{healerName} heals {healingReceiverName} for {healer.AbilityPoints}! {healingReceiverName} has {healingReceiver.Health} health now!");

            return(sb.ToString().TrimEnd());
        }
Exemple #7
0
        public string Heal(string[] args)
        {
            string healerName   = args[0];
            string receiverName = args[1];

            if (party.Any(x => x.Name == healerName) == false)
            {
                throw new ArgumentException(string.Format(ExceptionMessages.CharacterNotInParty, healerName));
            }
            if (party.Any(x => x.Name == receiverName) == false)
            {
                throw new ArgumentException(string.Format(ExceptionMessages.CharacterNotInParty, receiverName));
            }
            Character healer   = party.First(x => x.Name == healerName);
            Character receiver = party.First(x => x.Name == receiverName);

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

            priest.Heal(receiver);
            return($"{healer.Name} heals {receiver.Name} for {healer.AbilityPoints}! {receiver.Name} has {receiver.Health} health now!");
        }
Exemple #8
0
        public string Heal(string[] args)
        {
            string healerName          = args[0];
            string healingReceiverName = args[1];

            Character healer = this.characters.FirstOrDefault(c => c.Name == healerName);

            if (healer == null)
            {
                throw new ArgumentException($"Character {healerName} not found!");
            }

            Character receiver = this.characters.FirstOrDefault(c => c.Name == healingReceiverName);

            if (receiver == null)
            {
                throw new ArgumentException($"Character {healingReceiverName} not found!");
            }

            if (healer.GetType().Name == "Warrior")
            {
                throw new ArgumentException($"{healer.Name} cannot heal!");
            }

            Priest priest = (Priest)healer;

            priest.Heal(receiver);

            return($"{healer.Name} heals {receiver.Name} for {healer.AbilityPoints}! " +
                   $"{receiver.Name} has {receiver.Health} health now!");
        }
Exemple #9
0
        public string Heal(string[] args)
        {
            //healerName – args[0]
            //healingReceiverName – args[1]

            if (characters.Any(x => x.Name == args[0]) == false)
            {
                throw new ArgumentException($"Character {args[0]} not found!");
            }

            if (characters.Any(x => x.Name == args[1]) == false)
            {
                throw new ArgumentException($"Character {args[1]} not found!");
            }

            if (characters.FirstOrDefault(n => n.Name == args[0]).GetType().Name != "Priest")
            {
                throw new ArgumentException($"{args[0]} cannot heal!");
            }

            Priest    healer   = (Priest)characters.FirstOrDefault(x => x.Name == args[0]);
            Character receiver = characters.FirstOrDefault(x => x.Name == args[1]);

            if (healer.IsAlive == false)
            {
                throw new ArgumentException($"{args[0]} cannot heal!");
            }

            healer.Heal(receiver);

            return($"{healer.Name} heals {receiver.Name} for {healer.AbilityPoints}! {receiver.Name} has {receiver.Health} health now!");
        }
Exemple #10
0
        public string Heal(string[] args)
        {
            string healerName          = args[0];
            string healingReceiverName = args[1];

            if (!characters.Any(x => x.Name == healerName))
            {
                throw new ArgumentException(ExceptionMessages.CharacterNotInParty, healerName);
            }
            if (!characters.Any(x => x.Name == healingReceiverName))
            {
                throw new ArgumentException(ExceptionMessages.CharacterNotInParty, healingReceiverName);
            }
            Character healer   = characters.FirstOrDefault(x => x.Name == healerName);
            Character receiver = characters.FirstOrDefault(x => x.Name == healingReceiverName);

            if (healer.GetType().Name != "Priest")
            {
                throw new ArgumentException($"{healer.Name} cannot heal!");
            }

            Priest priest = (Priest)healer;

            priest.Heal(receiver);

            return(string.Format(SuccessMessages.HealCharacter, healer.Name, receiver.Name, healer.AbilityPoints, receiver.Name));
        }
Exemple #11
0
        public string Heal(string[] args)
        {
            string healerName          = args[0];
            string healingReceiverName = args[1];

            if (!this.characterParty.Any(x => x.Name == healerName))
            {
                throw new ArgumentException(string.Format(ExceptionMessages.CharacterNotInParty, healerName));
            }

            if (!this.characterParty.Any(x => x.Name == healingReceiverName))
            {
                throw new ArgumentException(string.Format(ExceptionMessages.CharacterNotInParty, healingReceiverName));
            }

            var character = this.characterParty.FirstOrDefault(x => x.Name == healerName);


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

            Priest healer   = (Priest)character;
            var    receiver = this.characterParty.FirstOrDefault(x => x.Name == healingReceiverName);

            healer.Heal(receiver);

            return($"{healer.Name} heals {receiver.Name} for {healer.AbilityPoints}!" +
                   $" {receiver.Name} has {receiver.Health} health now!");
        }
Exemple #12
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());
        }
Exemple #13
0
        public string Heal(string[] args)
        {
            string healerName   = args[0];
            string receiverName = args[1];

            Priest priest = new Priest(healerName);

            if (party.Contains(priest))
            {
                Character healReciever = party.Find(ch => ch.Name == receiverName);

                if (party.Contains(healReciever))
                {
                    if (priest.IsAlive && !healReciever.IsAlive)
                    {
                        return($"{healerName} cannot heal!");
                    }

                    priest.Heal(healReciever);
                    StringBuilder heal = new StringBuilder();
                    heal.Append($"{healerName} heals {receiverName} for {priest.AbilityPoints}! {healReciever.Name} has {healReciever.Health} health now!");

                    return(heal.ToString());
                }
                else
                {
                    throw new ArgumentException($"Character {receiverName} not found!");
                }
            }
            else
            {
                throw new ArgumentException($"Character {healerName} not found!");
            }
        }
Exemple #14
0
        public string Heal(string[] args)
        {
            var healerName          = args[0];
            var healingReceiverName = args[1];

            if (!party.Any(p => p.Name == healerName))
            {
                throw new ArgumentException($"Character {healerName} not found!");
            }

            if (!party.Any(p => p.Name == healingReceiverName))
            {
                throw new ArgumentException($"Character {healingReceiverName} not found!");
            }

            var healer   = party.FirstOrDefault(h => h.Name == healerName);
            var receiver = party.FirstOrDefault(r => r.Name == healingReceiverName);

            if (healer.GetType().Name != "Priest")
            {
                throw new ArgumentException($"{healer.Name} cannot heal!");
            }

            Priest priest = (Priest)healer;

            priest.Heal(receiver);


            return($"{healer.Name} heals {receiver.Name} for {healer.AbilityPoints}! {receiver.Name} has {receiver.Health} health now!");
        }
Exemple #15
0
        public static void Main()
        {
            Priest  p = new Priest();
            Warrior w = new Warrior();

            w.Attack(p);
            p.Heal(p);
        }
        static void Main()
        {
            Character mage    = new Mage(); // The punisher
            Character warrior = new Warrior();
            Priest    priest  = new Priest();

            PrintInfo(mage, warrior, priest);
            Console.WriteLine("Mage attacks the Warrior; Priest heals the Mage.");

            mage.Attack(warrior);
            priest.Heal(mage);
            PrintInfo(mage, warrior, priest);
            Console.WriteLine("Warrior attacks the Mage");

            warrior.Attack(mage);
            PrintInfo(mage, warrior, priest);
            Console.WriteLine("Priest heals the Warrior (he betrays the Mage).");

            priest.Heal(warrior);
            PrintInfo(mage, warrior, priest);
            Console.WriteLine("Mage attacks the Warrior; Priest heals the Warrior.");

            mage.Attack(warrior);
            priest.Heal(warrior);
            PrintInfo(mage, warrior, priest);
            Console.WriteLine("Mage attacks the Warrior; Warrior attacks the Mage.");

            mage.Attack(warrior);
            warrior.Attack(mage);
            PrintInfo(mage, warrior, priest);
            Console.WriteLine("Mage punishes the Warrior and the Priest by one-shoting them.");

            mage.Attack(warrior);
            mage.Attack(priest);
            PrintInfo(mage, warrior, priest);
        }
Exemple #17
0
        static void Main(string[] args)
        {
            Warrior petyr  = new Warrior();
            Mage    goshu  = new Mage();
            Priest  dancho = new Priest();

            Console.WriteLine(goshu.Health);
            petyr.Attack(goshu);
            Console.WriteLine(goshu.Health);
            dancho.Heal(goshu);
            Console.WriteLine(goshu.Health);
            petyr.Attack(goshu);
            Console.WriteLine(goshu.Health);
            petyr.Attack(goshu);
            Console.WriteLine(goshu.Health);
        }
Exemple #18
0
        public string Heal(string[] args)
        {
            string healerName          = args[0];
            string healingReceiverName = args[1];

            Character healer   = charactersParty.FirstOrDefault(c => c.Name == healerName);
            Character receiver = charactersParty.FirstOrDefault(c => c.Name == healingReceiverName);

            if (healer is null)
            {
                throw new ArgumentException(string.Format(ExceptionMessages.CharacterNotInParty, healerName));
            }
            else if (receiver is null)
            {
                throw new ArgumentException(string.Format(ExceptionMessages.CharacterNotInParty, healingReceiverName));
            }


            //if (healer is IAttacker)
            //{
            //	throw new ArgumentException(string.Format(ExceptionMessages.HealerCannotHeal, healer.Name));
            //}

            //(healer as IHealer).Heal(receiver);

            Priest priest = healer as Priest;

            if (priest is null)
            {
                throw new ArgumentException(string.Format(ExceptionMessages.HealerCannotHeal, healer.Name));
            }

            priest.Heal(receiver);

            return($"{healer.Name} heals {receiver.Name} for {healer.AbilityPoints}! {receiver.Name} has {receiver.Health} health now!");
        }