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

        Cleric    healer   = (Cleric)characterParty.FirstOrDefault(x => x.Name == healerName);
        Character receiver = characterParty.FirstOrDefault(x => x.Name == healingReceiverName);

        if (healer == null)
        {
            throw new ArgumentException($"Character {healerName} not found!");
        }
        if (receiver == null)
        {
            throw new ArgumentException($"Character {healingReceiverName} not found!");
        }
        if (healer.GetType().Name != "Cleric")
        {
            throw new ArgumentException($"{healerName} cannot heal!");
        }

        healer.Heal(receiver);

        return($"{healer.Name} heals {receiver.Name} for {healer.AbilityPoints}! {receiver.Name} has {receiver.Health} health now!");
    }
Beispiel #2
0
    public string Heal(string[] args)
    {
        Cleric healer          = (Cleric)CharacterExists(args[0]);
        var    healingReceiver = CharacterExists(args[1]);

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

        sb.Append($"{healer.Name} heals {healingReceiver.Name} for {healer.AbilityPoints}! {healingReceiver.Name} has {healingReceiver.Health} health now!");
        return(sb.ToString());
    }