Beispiel #1
0
        public Character CreateCharacter(string factionName, string characterType, string name)
        {
            if (!Enum.TryParse(factionName, out Faction faction))
            {
                throw new ArgumentException($"Invalid faction \"{factionName}\"!");
            }

            Character character;

            switch (characterType)
            {
            case "Cleric":
                character = new Cleric(name, faction);
                break;

            case "Warrior":
                character = new Warrior(name, faction);
                break;

            default:
                throw new ArgumentException($"Invalid character type \"{characterType}\"!");
            }

            return(character);
        }
Beispiel #2
0
        //public static Character CreateCharacter(Faction faction, string type, string name)
        //{
        //    Character character = null;
        //    //    Faction faction = (Faction)Enum.Parse(typeof(Faction), args[0]);
        //    //   string characterType = args[1];
        //    string characterType = type;
        //    //    string characterName = args[2];
        //    string characterName = name;

        //    if (characterType == "Warrior")
        //    {
        //        character = new Warrior(characterName, faction);
        //    }
        //    else if(characterType != "Cleric")
        //    {
        //        character = new Cleric(characterName, faction);
        //    }
        //    else
        //    {
        //        throw new ArgumentException($"Invalid character type \"{characterType}\"!");
        //    }

        //    return character;
        //}

        public static Character CreateCharacter(string factionString, string type, string name)
        {
            Character character = null;

            if (!Enum.TryParse(factionString, out Faction faction))
            {
                throw new ArgumentException($"Invalid faction \"{factionString}\"!");
            }
            //   string characterType = args[1];
            string characterType = type;
            //    string characterName = args[2];
            string characterName = name;

            if (characterType == "Warrior")
            {
                character = new Warrior(characterName, faction);
            }
            else if (characterType == "Cleric")
            {
                character = new Cleric(characterName, faction);
            }
            else
            {
                throw new ArgumentException($"Invalid character type \"{characterType}\"!");
            }

            return(character);
        }
        public string JoinParty(string[] args)
        {
            string factionToString = args[0];

            this.faction = (Faction)Enum.Parse(typeof(Faction), factionToString);
            string characterType = args[1];
            string name          = args[2];

            if (factionToString != "CSharp" || factionToString != "Java")
            {
                throw new ArgumentException($"Invalid faction \"{factionToString}\"!");
            }
            switch (characterType)
            {
            case "Warrior":
                Warrior warrior = new Warrior(name, faction);
                party.Add(warrior);
                break;

            case "Cleric":
                Cleric cleric = new Cleric(name, faction);
                party.Add(cleric);
                break;

            default:
                throw new ArgumentException($"Invalid character type \"{characterType}\"!");
            }
            return($"{name} joined the party!");
        }
Beispiel #4
0
        public string Heal(string[] args)
        {
            string healerName          = args[0];
            string healingReceiverName = args[1];

            Character healer   = characterParty.Find(c => c.Name == healerName);
            Character receiver = characterParty.Find(c => c.Name == healingReceiverName);

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

            string type = healer.GetType().Name;

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

            Cleric cleric = (Cleric)healer;

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

            var healer       = characters.FirstOrDefault(c => c.Name.Equals(healerName));
            var healReceiver = characters.FirstOrDefault(c => c.Name.Equals(healingReceiverName));

            if (healer == null)
            {
                throw new ArgumentException($"Character {healerName} not found!");
            }
            else if (healReceiver == null)
            {
                throw new ArgumentException($"Character {healingReceiverName} not found!");
            }
            else if (healer.Type.Equals("Warrior"))
            {
                throw new ArgumentException($"{healerName} cannot heal!");
            }
            else
            {
                Cleric cleric = (Cleric)healer;
                cleric.Heal(healReceiver);

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

            Character healerCharacter          = this.characters.SingleOrDefault(ch => ch.Name == healerName);
            Character healingReceiverCharacter = this.characters.SingleOrDefault(ch => ch.Name == healingReceiverName);

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

            if (healerCharacter is Warrior)
            {
                throw new ArgumentException($"{healerName} cannot heal!");
            }

            Cleric cleric = (Cleric)healerCharacter;

            cleric.Heal(healingReceiverCharacter);

            return($"{healerName} heals {healingReceiverName} for {healerCharacter.AbilityPoints}! " +
                   $"{healingReceiverName} has {healingReceiverCharacter.Health} health now!");
        }
Beispiel #7
0
        public string JoinParty(string[] args)
        {
            var faction       = args[0];
            var characterType = args[1];
            var name          = args[2];

            if (faction != Faction.CSharp.ToString() && faction != Faction.Java.ToString())
            {
                throw new ArgumentException($"Invalid faction \"{faction}\"!");
            }
            else if (characterType != "Warrior" && characterType != "Cleric")
            {
                throw new ArgumentException($"Invalid character type \"{characterType}\"!");
            }
            else
            {
                Character obj;
                if (characterType.Equals("Warrior"))
                {
                    obj = new Warrior(name, Enum.Parse <Faction>(faction));
                }
                else
                {
                    obj = new Cleric(name, Enum.Parse <Faction>(faction));
                }
                characters.Add(obj);

                return($"{name} joined the party!");
            }
        }
Beispiel #8
0
        public string JoinParty(string[] args)
        {
            object factionParse;

            if (!Enum.TryParse(typeof(Faction), args[0], out factionParse))
            {
                throw new ArgumentException($"Invalid faction \"{args[0]}\"!");
            }

            Faction faction = (Faction)factionParse;

            if (args[1] != nameof(Cleric) && args[1] != nameof(Warrior))
            {
                throw new ArgumentException($"Invalid character type \"{ args[1] }\"!");
            }

            Character ch = null;

            switch (args[1])
            {
            case nameof(Warrior):
                ch = new Warrior(args[2], faction);
                break;

            case nameof(Cleric):
                ch = new Cleric(args[2], faction);
                break;
            }

            chars.Add(ch.Name, ch);

            return($"{ch.Name} joined the party!");
        }
        public string Heal(string[] args)
        {
            string giverName    = args[0];
            string receiverName = args[1];


            Character giver = party.FirstOrDefault(c => c.Name == giverName);

            if (giver == null)
            {
                throw new ArgumentException(string.Format(ErrorMessages.InvalidCharacter, giverName));
            }

            Character receiver = party.FirstOrDefault(c => c.Name == receiverName);

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

            if (giver.GetType().Name != "Cleric")
            {
                throw new ArgumentException(string.Format(ErrorMessages.CanNotHeal, giver.Name));
            }



            Cleric healer = (Cleric)giver;

            healer.Heal(receiver);


            StringBuilder result = new StringBuilder();

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

            if (!receiver.IsAlive)
            {
                result.AppendLine($"{receiver.Name} is dead!");
            }

            return(result.ToString().TrimEnd());
        }
        // Parameters
//•	healerName – a string
//•	healingReceiverName – string
//Functionality
//Makes the healer heal the healing receiver.
//If any of the characters don’t exist in the party, throw exceptions with messages just like the above commands.
//If the healer cannot heal, throw an ArgumentException with the message “{ healerName}
//        cannot heal!”
//The command output is in the following format:
//{healer.Name} heals {receiver.Name} for {healer.AbilityPoints}! {receiver.Name} has {receiver.Health} health now!
//Returns the formatted string
        public string Heal(string[] args)
        {
            string healerName   = args[0];
            string receiverName = args[1];

            Character healer   = this.GetCharacter(healerName);
            Character receiver = this.GetCharacter(receiverName);

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

            Cleric castHealer = (Cleric)healer;

            castHealer.Heal(receiver);

            return($"{healer.Name} heals {receiver.Name} for {healer.AbilityPoints}! {receiver.Name} has {receiver.Health} health now!");
        }
        public string JoinParty(string[] args)
        {
            string factionType = args[0];

            // var content = (ContentEnum)Enum.Parse(typeof(ContentEnum), fileContentMessage);
            Faction faction;

            switch (factionType)
            {
            case "CSharp":
                faction = Faction.CSharp;
                break;

            case "Java":
                faction = Faction.Java;
                break;

            default:
                throw new ArgumentException(string.Format(ErrorMessages.InvalidFaction, factionType));
            }

            string classType = args[1];
            string name      = args[2];

            Character character;

            switch (classType)
            {
            case "Warrior":
                character = new Warrior(name, faction);
                break;

            case "Cleric":
                character = new Cleric(name, faction);
                break;

            default:
                throw new ArgumentException(string.Format(ErrorMessages.InvalidCharacterType, classType));
            }
            allCharacters.Add(character);

            return($"{name} joined the party!");
        }
Beispiel #12
0
        public string JoinParty(string[] args)
        {
            string faction       = args[0];
            string characterType = args[1];
            string name          = args[2];

            if (faction != "CSharp" && faction != "Java")
            {
                throw new ArgumentException($@"Invalid faction ""{faction}""!");
            }
            if (characterType != "Cleric" && characterType != "Warrior")
            {
                throw new ArgumentException($@"Invalid character type ""{characterType}""!");
            }
            Character character = null;

            switch (characterType)
            {
            case "Cleric":
                if (faction == "CSharp")
                {
                    character = new Cleric(name, Faction.CSharp);
                }
                else if (faction == "Java")
                {
                    character = new Cleric(name, Faction.Java);
                }
                break;

            case "Warrior":
                if (faction == "CSharp")
                {
                    character = new Warrior(name, Faction.CSharp);
                }
                else if (faction == "Java")
                {
                    character = new Warrior(name, Faction.Java);
                }
                break;
            }
            this.characters.Add(character);
            return($"{name} joined the party!");
        }
        public string JoinParty(string[] args)
        {
            string factionStr    = args[0];
            string characterType = args[1];
            string name          = args[2];

            bool isFactionValid = Enum.TryParse(typeof(Faction), factionStr, out object factionResult);

            if (!isFactionValid)
            {
                throw new ArgumentException(string.Format(ErrorMessages.InvalidName, factionStr));
            }

            Faction faction = (Faction)factionResult;

            Character character = null;

            switch (characterType)
            {
            case "Warrior":
                character = new Warrior(name, faction);
                party.Add(character);
                return($"{character.Name} joined the party!");

                break;

            case "Cleric":
                character = new Cleric(name, faction);
                party.Add(character);
                return($"{character.Name} joined the party!");

                break;

            default:
                throw new ArgumentException(string.Format(ErrorMessages.InvalidCharacter, characterType));
            }


            throw new NotImplementedException();
        }
Beispiel #14
0
        public string Heal(string[] args)
        {
            string healerName   = args[0];
            string receiverName = args[1];

            Character healer   = charaters.FirstOrDefault(c => c.Name == healerName);
            Character receiver = charaters.FirstOrDefault(c => c.Name == receiverName);

            Validator.EnsureCharacterIsNotNull(healer, healerName);
            Validator.EnsureCharacterIsNotNull(receiver, receiverName);

            if (healer is IHealable == false)
            {
                throw new ArgumentException($"{healerName} cannot heal!");
            }

            Cleric cleric = (Cleric)healer;

            cleric.Heal(receiver);

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

            CheckIfCharacterIsPresent(healerName);
            Character healer = allCharacters.FirstOrDefault(x => x.Name == healerName);

            CheckIfCharacterIsPresent(healingReceiverName);
            Character healingReceiver = allCharacters.FirstOrDefault(x => x.Name == healingReceiverName);

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

            cleric.Heal(healingReceiver);

            return($"{cleric.Name} heals {healingReceiver.Name} for {cleric.AbilityPoints}! " +
                   $"{healingReceiver.Name} has {healingReceiver.Health} health now!");
        }
Beispiel #16
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($"Character {healerName} not found!");
            }

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

            var type = healer.GetType().Name;

            if (type != "Cleric")
            {
                throw new ArgumentException($"{healerName} cannot heal!");
            }

            Cleric healerParsed = (Cleric)healer;

            healerParsed.Heal(receiver);

            StringBuilder sb = new StringBuilder();

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

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