Пример #1
0
        /// <summary>
        /// "Print" (=build) a card using their name, damage and logger.
        /// </summary>
        /// <param name="fullCardName">
        /// Name of the card to print, can be a fully qualified name like "FireDragon" or
        /// one that can be correctly interpreted like "Dragon"
        /// </param>
        /// <param name="damage">
        /// Base damage of the card
        /// </param>
        /// <param name="log">
        /// Player logger used to track card events.
        /// </param>
        /// <returns>
        /// Concrete battle ready card as <c>ICard</c> or null when a invalid or
        /// unsupported name was given.
        /// </returns>
        public static ICard?Print(string fullCardName, double damage, IPlayerLog log)
        {
            fullCardName = InferType(fullCardName);
            var processedName = Split(fullCardName);

            if (processedName == null)
            {
                return(null);
            }
            var procType = processedName.Value.Item1;
            var procName = processedName.Value.Item2;

            var type = DamageTypeMethods.GetType(procType);

            if (type == null)
            {
                return(null);
            }

            // Build Spell Card
            if (procName.EndsWith("Spell"))
            {
                return(PrintSpell(damage, (DamageType)type, log));
            }
            // Build Monster Card
            var monsterType = MonsterTypeMethods.GetType(procName);

            if (monsterType == null)
            {
                return(null);
            }
            return(PrintMonster(damage, (DamageType)type, (MonsterType)monsterType, log));
        }
Пример #2
0
        /// <summary>
        /// Check if the card name is a fully qualified name like "FireDragon", when not
        /// try to infer the default element type so "Dragon" becomes "FireDragon".
        /// </summary>
        /// <param name="fullCardName"></param>
        /// <returns>
        /// Fully qualified card name or same parameter value when name is not supported
        /// </returns>
        private static string InferType(string fullCardName)
        {
            if (fullCardName.StartsWith("Normal") || fullCardName.StartsWith("Regular") ||
                fullCardName.StartsWith("Fire") || fullCardName.StartsWith("Water"))
            {
                return(fullCardName);
            }
            if (fullCardName.EndsWith("Spell"))
            {
                fullCardName = "Regular" + fullCardName;
            }
            // Pattern matching
            // See: https://stackoverflow.com/a/51449576/12347616
            else if (MonsterTypeMethods.GetType(fullCardName) is { } type)
            {
                fullCardName = type.GetDefaultDamageType() + fullCardName;
            }

            return(fullCardName);
        }