public static InformationUnit Decode(string[] data)
        {
            string damage    = data[0];
            string armor     = data[1];
            string hitPoints = data[2];
            string sight     = data[3];
            string spawn     = data[4];
            string precision = data[5];
            string type      = data[6];

            int _damage    = BinaryToInt(damage);
            int _armor     = BinaryToInt(armor);
            int _sight     = BinaryToInt(sight);
            int _precision = BinaryToInt(precision);

            int _spawn = BinaryToInt(spawn);
            int _type  = BinaryToInt(type);

            float _hitPoints = BinaryToInt(hitPoints);

            InformationUnit info = null;

            if (_type < 3)
            {
                info = new InformationUnit("Grunt", Race.ORC, Faction.HORDE, _hitPoints, _armor, _sight, 10, 600, 1, Buildings.NONE, 60, _damage, _precision, 1, _spawn, Units.GRUNT);
            }
            else if (_type >= 3)
            {
                info = new InformationUnit("Troll Axethrower", Race.ORC, Faction.HORDE, _hitPoints, _armor, _sight, 10, 600, 1, Buildings.NONE, 60, _damage, _precision, 1, _spawn, Units.TROLL_AXETHROWER);
            }

            return(info);
        }
示例#2
0
        public string ToString(InformationUnit unit, [CanBeNull] string cultureName, int significantDigitsAfterRadix)
        {
            double value  = As(unit);
            string format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);

            return(ToString(unit, cultureName, format));
        }
        public static string GetAbbreviation(InformationUnit unit, [CanBeNull] string cultureName)
        {
            // Windows Runtime Component does not support CultureInfo and IFormatProvider types, so we use culture name for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx
            IFormatProvider provider = cultureName == null ? UnitSystem.DefaultCulture : new CultureInfo(cultureName);

            return(UnitSystem.GetCached(provider).GetDefaultAbbreviation(unit));
        }
示例#4
0
        public ManagerEnemies(ManagerMouse managerMouse, ManagerMap managerMap, ManagerBuildings managerBuildings)
        {
            this.managerMap       = managerMap;
            this.managerMouse     = managerMouse;
            this.managerBuildings = managerBuildings;

            for (int i = 0; i < wavesEnemies; i++)
            {
                int spawn     = random.Next(0, 4);
                int armor     = random.Next(0, 20);
                int sight     = random.Next(1, 360);
                int damage    = random.Next(1, 20);
                int precision = random.Next(1, 100);
                int hitPoints = random.Next(1, 200);

                if (random.Next(0, 100) >= 50)
                {
                    InformationUnit info = new InformationUnit("Grunt", Race.ORC, Faction.HORDE, hitPoints, armor, sight, 10, 600, 1, Util.Buildings.NONE, 60, damage, precision, 1, spawn, Util.Units.GRUNT);
                    enemies.Add(new Grunt(info, managerMouse, managerMap, managerBuildings));
                }
                else
                {
                    InformationUnit info = new InformationUnit("Troll Axethrower", Race.ORC, Faction.HORDE, hitPoints, armor, sight, 10, 600, 1, Util.Buildings.NONE, 60, damage, precision, 5, spawn, Util.Units.TROLL_AXETHROWER);
                    enemies.Add(new TrollAxethrower(info, managerMouse, managerMap, managerBuildings));
                }
            }
        }
示例#5
0
        public string ToString(InformationUnit unit, [CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix)
        {
            double value  = As(unit);
            string format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);

            return(ToString(unit, provider, format));
        }
示例#6
0
        public BuilderUnits(Util.Units type, ManagerUnits managerUnits, InformationUnit informationUnit)
        {
            this.informationUnit = informationUnit;
            this.type            = type;

            this.managerUnits = managerUnits;
        }
示例#7
0
// ReSharper restore VirtualMemberNeverOverriden.Global

        protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(InformationUnit unit)
        {
            return(unit switch
            {
                InformationUnit.Bit => (BitsInOneBit, BitsTolerance),
                InformationUnit.Byte => (BytesInOneBit, BytesTolerance),
                InformationUnit.Exabit => (ExabitsInOneBit, ExabitsTolerance),
                InformationUnit.Exabyte => (ExabytesInOneBit, ExabytesTolerance),
                InformationUnit.Exbibit => (ExbibitsInOneBit, ExbibitsTolerance),
                InformationUnit.Exbibyte => (ExbibytesInOneBit, ExbibytesTolerance),
                InformationUnit.Gibibit => (GibibitsInOneBit, GibibitsTolerance),
                InformationUnit.Gibibyte => (GibibytesInOneBit, GibibytesTolerance),
                InformationUnit.Gigabit => (GigabitsInOneBit, GigabitsTolerance),
                InformationUnit.Gigabyte => (GigabytesInOneBit, GigabytesTolerance),
                InformationUnit.Kibibit => (KibibitsInOneBit, KibibitsTolerance),
                InformationUnit.Kibibyte => (KibibytesInOneBit, KibibytesTolerance),
                InformationUnit.Kilobit => (KilobitsInOneBit, KilobitsTolerance),
                InformationUnit.Kilobyte => (KilobytesInOneBit, KilobytesTolerance),
                InformationUnit.Mebibit => (MebibitsInOneBit, MebibitsTolerance),
                InformationUnit.Mebibyte => (MebibytesInOneBit, MebibytesTolerance),
                InformationUnit.Megabit => (MegabitsInOneBit, MegabitsTolerance),
                InformationUnit.Megabyte => (MegabytesInOneBit, MegabytesTolerance),
                InformationUnit.Pebibit => (PebibitsInOneBit, PebibitsTolerance),
                InformationUnit.Pebibyte => (PebibytesInOneBit, PebibytesTolerance),
                InformationUnit.Petabit => (PetabitsInOneBit, PetabitsTolerance),
                InformationUnit.Petabyte => (PetabytesInOneBit, PetabytesTolerance),
                InformationUnit.Tebibit => (TebibitsInOneBit, TebibitsTolerance),
                InformationUnit.Tebibyte => (TebibytesInOneBit, TebibytesTolerance),
                InformationUnit.Terabit => (TerabitsInOneBit, TerabitsTolerance),
                InformationUnit.Terabyte => (TerabytesInOneBit, TerabytesTolerance),
                _ => throw new NotSupportedException()
            });
示例#8
0
        public string ToString(InformationUnit unit, CultureInfo culture, string format, params object[] args)
        {
            string abbreviation = UnitSystem.GetCached(culture).GetDefaultAbbreviation(unit);

            object[] finalArgs = new object[] { As(unit), abbreviation }
            .Concat(args)
            .ToArray();

            return(string.Format(culture, format, finalArgs));
        }
示例#9
0
        /// <summary>
        ///     Creates the quantity with the given numeric value and unit.
        /// </summary>
        /// <param name="numericValue">The numeric value  to contruct this quantity with.</param>
        /// <param name="unit">The unit representation to contruct this quantity with.</param>
        /// <remarks>Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.</remarks>
        /// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
        private Information(decimal numericValue, InformationUnit unit)
        {
            if (unit == InformationUnit.Undefined)
            {
                throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
            }

            _value = numericValue;
            _unit  = unit;
        }
示例#10
0
        /// <summary>
        ///     Convert to the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>Value converted to the specified unit.</returns>
        public double As(InformationUnit unit)
        {
            if (Unit == unit)
            {
                return(Convert.ToDouble(Value));
            }

            var converted = AsBaseNumericType(unit);

            return(Convert.ToDouble(converted));
        }
示例#11
0
        /// <summary>
        ///     Parse a string of the format "&lt;quantity&gt; &lt;unit&gt;".
        /// </summary>
        /// <example>
        ///     Length.Parse("5.5 m", new CultureInfo("en-US"));
        /// </example>
        /// <exception cref="ArgumentNullException">The value of 'str' cannot be null. </exception>
        /// <exception cref="ArgumentException">
        ///     Expected 2 words. Input string needs to be in the format "&lt;quantity&gt; &lt;unit
        ///     &gt;".
        /// </exception>
        /// <exception cref="UnitsNetException">Error parsing string.</exception>
        public static Information Parse(string str, IFormatProvider formatProvider = null)
        {
            if (str == null)
            {
                throw new ArgumentNullException("str");
            }

            var numFormat = formatProvider != null ?
                            (NumberFormatInfo)formatProvider.GetFormat(typeof(NumberFormatInfo)) :
                            NumberFormatInfo.CurrentInfo;

            var numRegex = string.Format(@"[\d., {0}{1}]*\d",               // allows digits, dots, commas, and spaces in the quantity (must end in digit)
                                         numFormat.NumberGroupSeparator,    // adds provided (or current) culture's group separator
                                         numFormat.NumberDecimalSeparator); // adds provided (or current) culture's decimal separator
            var regexString = string.Format("(?<value>[-+]?{0}{1}{2}{3}",
                                            numRegex,                       // capture base (integral) Quantity value
                                            @"(?:[eE][-+]?\d+)?)",          // capture exponential (if any), end of Quantity capturing
                                            @"\s?",                         // ignore whitespace (allows both "1kg", "1 kg")
                                            @"(?<unit>\S+)");               // capture Unit (non-whitespace) input

            var             regex  = new Regex(regexString);
            GroupCollection groups = regex.Match(str.Trim()).Groups;

            var valueString = groups["value"].Value;
            var unitString  = groups["unit"].Value;

            if (valueString == "" || unitString == "")
            {
                var ex = new ArgumentException(
                    "Expected valid quantity and unit. Input string needs to be in the format \"<quantity><unit> or <quantity> <unit>\".", "str");
                ex.Data["input"]          = str;
                ex.Data["formatprovider"] = formatProvider == null ? null : formatProvider.ToString();
                throw ex;
            }

            try
            {
                InformationUnit unit  = ParseUnit(unitString, formatProvider);
                double          value = double.Parse(valueString, formatProvider);

                return(From(value, unit));
            }
            catch (Exception e)
            {
                var newEx = new UnitsNetException("Error parsing string.", e);
                newEx.Data["input"]          = str;
                newEx.Data["formatprovider"] = formatProvider == null ? null : formatProvider.ToString();
                throw newEx;
            }
        }
示例#12
0
        /// <summary>
        ///     Parse a string given a particular regular expression.
        /// </summary>
        /// <exception cref="UnitsNetException">Error parsing string.</exception>
        private static List <Information> ParseWithRegex(string regexString, string str, IFormatProvider formatProvider = null)
        {
            var             regex     = new Regex(regexString);
            MatchCollection matches   = regex.Matches(str.Trim());
            var             converted = new List <Information>();

            foreach (Match match in matches)
            {
                GroupCollection groups = match.Groups;

                var valueString = groups["value"].Value;
                var unitString  = groups["unit"].Value;
                if (groups["invalid"].Value != "")
                {
                    var newEx = new UnitsNetException("Invalid string detected: " + groups["invalid"].Value);
                    newEx.Data["input"]          = str;
                    newEx.Data["matched value"]  = valueString;
                    newEx.Data["matched unit"]   = unitString;
                    newEx.Data["formatprovider"] = formatProvider == null ? null : formatProvider.ToString();
                    throw newEx;
                }
                if (valueString == "" && unitString == "")
                {
                    continue;
                }

                try
                {
                    InformationUnit unit  = ParseUnit(unitString, formatProvider);
                    double          value = double.Parse(valueString, formatProvider);

                    converted.Add(From(value, unit));
                }
                catch (AmbiguousUnitParseException ambiguousException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    var newEx = new UnitsNetException("Error parsing string.", ex);
                    newEx.Data["input"]          = str;
                    newEx.Data["matched value"]  = valueString;
                    newEx.Data["matched unit"]   = unitString;
                    newEx.Data["formatprovider"] = formatProvider == null ? null : formatProvider.ToString();
                    throw newEx;
                }
            }
            return(converted);
        }
示例#13
0
        /// <summary>
        ///     Parse a string with one or two quantities of the format "&lt;quantity&gt; &lt;unit&gt;".
        /// </summary>
        /// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
        /// <param name="provider">Format to use when parsing number and unit. Defaults to <see cref="UnitSystem.DefaultCulture" />.</param>
        /// <example>
        ///     Length.Parse("5.5 m", new CultureInfo("en-US"));
        /// </example>
        /// <exception cref="ArgumentNullException">The value of 'str' cannot be null. </exception>
        /// <exception cref="ArgumentException">
        ///     Expected string to have one or two pairs of quantity and unit in the format
        ///     "&lt;quantity&gt; &lt;unit&gt;". Eg. "5.5 m" or "1ft 2in"
        /// </exception>
        /// <exception cref="AmbiguousUnitParseException">
        ///     More than one unit is represented by the specified unit abbreviation.
        ///     Example: Volume.Parse("1 cup") will throw, because it can refer to any of
        ///     <see cref="VolumeUnit.MetricCup" />, <see cref="VolumeUnit.UsLegalCup" /> and <see cref="VolumeUnit.UsCustomaryCup" />.
        /// </exception>
        /// <exception cref="UnitsNetException">
        ///     If anything else goes wrong, typically due to a bug or unhandled case.
        ///     We wrap exceptions in <see cref="UnitsNetException" /> to allow you to distinguish
        ///     Units.NET exceptions from other exceptions.
        /// </exception>
        public static Information Parse(string str, [CanBeNull] IFormatProvider provider)
        {
            if (str == null)
            {
                throw new ArgumentNullException(nameof(str));
            }

            provider = provider ?? UnitSystem.DefaultCulture;

            return(QuantityParser.Parse <Information, InformationUnit>(str, provider,
                                                                       delegate(string value, string unit, IFormatProvider formatProvider2)
            {
                double parsedValue = double.Parse(value, formatProvider2);
                InformationUnit parsedUnit = ParseUnit(unit, formatProvider2);
                return From(parsedValue, parsedUnit);
            }, (x, y) => FromBits(x.Bits + y.Bits)));
        }
示例#14
0
        public string ToString(InformationUnit unit, [CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args)
        {
            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            provider = provider ?? UnitSystem.DefaultCulture;

            double value = As(unit);

            object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, provider, args);
            return(string.Format(provider, format, formatArgs));
        }
示例#15
0
        /// <summary>
        ///     Parse a string with one or two quantities of the format "&lt;quantity&gt; &lt;unit&gt;".
        /// </summary>
        /// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
        /// <param name="cultureName">Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to <see cref="UnitSystem" />'s default culture.</param>
        /// <example>
        ///     Length.Parse("5.5 m", new CultureInfo("en-US"));
        /// </example>
        /// <exception cref="ArgumentNullException">The value of 'str' cannot be null. </exception>
        /// <exception cref="ArgumentException">
        ///     Expected string to have one or two pairs of quantity and unit in the format
        ///     "&lt;quantity&gt; &lt;unit&gt;". Eg. "5.5 m" or "1ft 2in"
        /// </exception>
        /// <exception cref="AmbiguousUnitParseException">
        ///     More than one unit is represented by the specified unit abbreviation.
        ///     Example: Volume.Parse("1 cup") will throw, because it can refer to any of
        ///     <see cref="VolumeUnit.MetricCup" />, <see cref="VolumeUnit.UsLegalCup" /> and <see cref="VolumeUnit.UsCustomaryCup" />.
        /// </exception>
        /// <exception cref="UnitsNetException">
        ///     If anything else goes wrong, typically due to a bug or unhandled case.
        ///     We wrap exceptions in <see cref="UnitsNetException" /> to allow you to distinguish
        ///     Units.NET exceptions from other exceptions.
        /// </exception>
        public static Information Parse(string str, [CanBeNull] string cultureName)
        {
            if (str == null)
            {
                throw new ArgumentNullException(nameof(str));
            }

            // Windows Runtime Component does not support CultureInfo and IFormatProvider types, so we use culture name for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx
            IFormatProvider provider = cultureName == null ? UnitSystem.DefaultCulture : new CultureInfo(cultureName);

            return(QuantityParser.Parse <Information, InformationUnit>(str, provider,
                                                                       delegate(string value, string unit, IFormatProvider formatProvider2)
            {
                double parsedValue = double.Parse(value, formatProvider2);
                InformationUnit parsedUnit = ParseUnit(unit, formatProvider2);
                return From(parsedValue, parsedUnit);
            }, (x, y) => FromBits(x.Bits + y.Bits)));
        }
示例#16
0
        public string ToString(InformationUnit unit, [CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
        {
            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            // Windows Runtime Component does not support CultureInfo and IFormatProvider types, so we use culture name for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx
            IFormatProvider provider = cultureName == null ? UnitSystem.DefaultCulture : new CultureInfo(cultureName);

            double value = As(unit);

            object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, provider, args);
            return(string.Format(provider, format, formatArgs));
        }
示例#17
0
        /// <summary>
        ///     Parse a string with one or two quantities of the format "&lt;quantity&gt; &lt;unit&gt;".
        /// </summary>
        /// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
        /// <param name="culture">Format to use when parsing number and unit. If it is null, it defaults to <see cref="NumberFormatInfo.CurrentInfo"/> for parsing the number and <see cref="CultureInfo.CurrentUICulture"/> for parsing the unit abbreviation by culture/language.</param>
        /// <example>
        ///     Length.Parse("5.5 m", new CultureInfo("en-US"));
        /// </example>
        /// <exception cref="ArgumentNullException">The value of 'str' cannot be null. </exception>
        /// <exception cref="ArgumentException">
        ///     Expected string to have one or two pairs of quantity and unit in the format
        ///     "&lt;quantity&gt; &lt;unit&gt;". Eg. "5.5 m" or "1ft 2in"
        /// </exception>
        /// <exception cref="AmbiguousUnitParseException">
        ///     More than one unit is represented by the specified unit abbreviation.
        ///     Example: Volume.Parse("1 cup") will throw, because it can refer to any of
        ///     <see cref="VolumeUnit.MetricCup" />, <see cref="VolumeUnit.UsLegalCup" /> and <see cref="VolumeUnit.UsCustomaryCup" />.
        /// </exception>
        /// <exception cref="UnitsNetException">
        ///     If anything else goes wrong, typically due to a bug or unhandled case.
        ///     We wrap exceptions in <see cref="UnitsNetException" /> to allow you to distinguish
        ///     Units.NET exceptions from other exceptions.
        /// </exception>
        public static Information Parse(string str, [CanBeNull] Culture culture)
        {
            if (str == null)
            {
                throw new ArgumentNullException("str");
            }

#if WINDOWS_UWP
            IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
#else
            IFormatProvider formatProvider = culture;
#endif
            return(UnitParser.ParseUnit <Information>(str, formatProvider,
                                                      delegate(string value, string unit, IFormatProvider formatProvider2)
            {
                double parsedValue = double.Parse(value, formatProvider2);
                InformationUnit parsedUnit = ParseUnit(unit, formatProvider2);
                return From(parsedValue, parsedUnit);
            }, (x, y) => FromBits(x.Bits + y.Bits)));
        }
示例#18
0
        public string ToString(InformationUnit unit, [CanBeNull] Culture culture, [NotNull] string format,
                               [NotNull] params object[] args)
        {
            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

#if WINDOWS_UWP
            IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture);
#else
            IFormatProvider formatProvider = culture;
#endif
            double   value      = As(unit);
            object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, formatProvider, args);
            return(string.Format(formatProvider, format, formatArgs));
        }
示例#19
0
 public static bool TryParseUnit(string str, out InformationUnit unit)
 {
     return(TryParseUnit(str, null, out unit));
 }
示例#20
0
        /// <summary>
        ///     Get unit abbreviation string.
        /// </summary>
        /// <param name="unit">Unit to get abbreviation for.</param>
        /// <returns>Unit abbreviation string.</returns>
        /// <param name="cultureName">Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" /> if null.</param>
        public static string GetAbbreviation(InformationUnit unit, [CanBeNull] string cultureName)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider));
        }
示例#21
0
 public static Information From(double value, InformationUnit fromUnit)
 {
     return(new Information((decimal)value, fromUnit));
 }
示例#22
0
 /// <summary>
 ///     Get unit abbreviation string.
 /// </summary>
 /// <param name="unit">Unit to get abbreviation for.</param>
 /// <returns>Unit abbreviation string.</returns>
 public static string GetAbbreviation(InformationUnit unit)
 {
     return(GetAbbreviation(unit, null));
 }
示例#23
0
        private decimal AsBaseNumericType(InformationUnit unit)
        {
            if (Unit == unit)
            {
                return(_value);
            }

            var baseUnitValue = AsBaseUnit();

            switch (unit)
            {
            case InformationUnit.Bit: return(baseUnitValue);

            case InformationUnit.Byte: return(baseUnitValue / 8m);

            case InformationUnit.Exabit: return((baseUnitValue) / 1e18m);

            case InformationUnit.Exabyte: return((baseUnitValue / 8m) / 1e18m);

            case InformationUnit.Exbibit: return((baseUnitValue) / (1024m * 1024 * 1024 * 1024 * 1024 * 1024));

            case InformationUnit.Exbibyte: return((baseUnitValue / 8m) / (1024m * 1024 * 1024 * 1024 * 1024 * 1024));

            case InformationUnit.Gibibit: return((baseUnitValue) / (1024m * 1024 * 1024));

            case InformationUnit.Gibibyte: return((baseUnitValue / 8m) / (1024m * 1024 * 1024));

            case InformationUnit.Gigabit: return((baseUnitValue) / 1e9m);

            case InformationUnit.Gigabyte: return((baseUnitValue / 8m) / 1e9m);

            case InformationUnit.Kibibit: return((baseUnitValue) / 1024m);

            case InformationUnit.Kibibyte: return((baseUnitValue / 8m) / 1024m);

            case InformationUnit.Kilobit: return((baseUnitValue) / 1e3m);

            case InformationUnit.Kilobyte: return((baseUnitValue / 8m) / 1e3m);

            case InformationUnit.Mebibit: return((baseUnitValue) / (1024m * 1024));

            case InformationUnit.Mebibyte: return((baseUnitValue / 8m) / (1024m * 1024));

            case InformationUnit.Megabit: return((baseUnitValue) / 1e6m);

            case InformationUnit.Megabyte: return((baseUnitValue / 8m) / 1e6m);

            case InformationUnit.Pebibit: return((baseUnitValue) / (1024m * 1024 * 1024 * 1024 * 1024));

            case InformationUnit.Pebibyte: return((baseUnitValue / 8m) / (1024m * 1024 * 1024 * 1024 * 1024));

            case InformationUnit.Petabit: return((baseUnitValue) / 1e15m);

            case InformationUnit.Petabyte: return((baseUnitValue / 8m) / 1e15m);

            case InformationUnit.Tebibit: return((baseUnitValue) / (1024m * 1024 * 1024 * 1024));

            case InformationUnit.Tebibyte: return((baseUnitValue / 8m) / (1024m * 1024 * 1024 * 1024));

            case InformationUnit.Terabit: return((baseUnitValue) / 1e12m);

            case InformationUnit.Terabyte: return((baseUnitValue / 8m) / 1e12m);

            default:
                throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
            }
        }
示例#24
0
        public Skeleton(int tileX, int tileY, ManagerMouse managerMouse, ManagerMap managerMap, ManagerUnits managerUnits)
            : base(tileX, tileY, 40, 40, 1, managerMouse, managerMap, managerUnits)
        {
            Dictionary <AnimationType, List <Sprite> > sprites = new Dictionary <AnimationType, List <Sprite> >();
            List <Sprite> spriteWalking = new List <Sprite>();

            // UP
            spriteWalking.Add(new Sprite(14, 10, 28, 30));
            spriteWalking.Add(new Sprite(13, 52, 30, 42));
            spriteWalking.Add(new Sprite(11, 112, 33, 27));
            spriteWalking.Add(new Sprite(14, 152, 32, 57));
            // DOWN
            spriteWalking.Add(new Sprite(257, 11, 29, 29));
            spriteWalking.Add(new Sprite(257, 52, 28, 40));
            spriteWalking.Add(new Sprite(256, 106, 34, 36));
            spriteWalking.Add(new Sprite(259, 152, 32, 36));
            // LEFT
            spriteWalking.Add(new Sprite(143, 10, 14, 33));
            spriteWalking.Add(new Sprite(134, 54, 33, 30));
            spriteWalking.Add(new Sprite(138, 99, 30, 46));
            spriteWalking.Add(new Sprite(137, 152, 28, 31));
            // UP-RIGHT
            spriteWalking.Add(new Sprite(80, 10, 18, 32));
            spriteWalking.Add(new Sprite(74, 48, 25, 39));
            spriteWalking.Add(new Sprite(68, 99, 34, 39));
            spriteWalking.Add(new Sprite(76, 150, 24, 34));
            // DOWN-RIGHT
            spriteWalking.Add(new Sprite(198, 11, 28, 31));
            spriteWalking.Add(new Sprite(196, 55, 36, 35));
            spriteWalking.Add(new Sprite(205, 104, 20, 40));
            spriteWalking.Add(new Sprite(198, 155, 35, 33));
            sprites.Add(AnimationType.WALKING, spriteWalking);

            List <Sprite> spriteAttacking = new List <Sprite>();

            // UP
            spriteAttacking.Add(new Sprite(13, 197, 32, 37));
            spriteAttacking.Add(new Sprite(14, 248, 28, 40));
            spriteAttacking.Add(new Sprite(10, 293, 28, 40));
            spriteAttacking.Add(new Sprite(14, 349, 29, 38));
            spriteAttacking.Add(new Sprite(5, 391, 32, 32));
            // DOWN
            spriteAttacking.Add(new Sprite(260, 212, 35, 29));
            spriteAttacking.Add(new Sprite(263, 250, 27, 37));
            spriteAttacking.Add(new Sprite(269, 306, 26, 35));
            spriteAttacking.Add(new Sprite(260, 350, 30, 32));
            spriteAttacking.Add(new Sprite(269, 394, 29, 33));
            // LEFT
            spriteAttacking.Add(new Sprite(143, 194, 21, 47));
            spriteAttacking.Add(new Sprite(134, 247, 34, 30));
            spriteAttacking.Add(new Sprite(139, 306, 39, 35));
            spriteAttacking.Add(new Sprite(136, 348, 31, 31));
            spriteAttacking.Add(new Sprite(133, 397, 28, 32));
            // UP-RIGHT
            spriteAttacking.Add(new Sprite(78, 194, 30, 40));
            spriteAttacking.Add(new Sprite(75, 247, 33, 39));
            spriteAttacking.Add(new Sprite(78, 300, 37, 36));
            spriteAttacking.Add(new Sprite(75, 347, 34, 39));
            spriteAttacking.Add(new Sprite(78, 397, 33, 31));
            // DOWN-RIGHT
            spriteAttacking.Add(new Sprite(200, 198, 28, 44));
            spriteAttacking.Add(new Sprite(200, 248, 27, 34));
            spriteAttacking.Add(new Sprite(194, 310, 34, 31));
            spriteAttacking.Add(new Sprite(200, 348, 23, 34));
            spriteAttacking.Add(new Sprite(190, 397, 30, 32));
            sprites.Add(AnimationType.ATTACKING, spriteAttacking);

            List <Sprite> spriteDiying = new List <Sprite>();

            spriteDiying.Add(new Sprite(187, 447, 39, 34));
            sprites.Add(AnimationType.DYING, spriteDiying);

            Dictionary <string, Frame> animations = new Dictionary <string, Frame>();

            Dictionary <AnimationType, int> framesCount = new Dictionary <AnimationType, int>();

            framesCount.Add(AnimationType.WALKING, 4);
            framesCount.Add(AnimationType.ATTACKING, 5);
            framesCount.Add(AnimationType.DYING, 1);

            animations.Add("up", new Frame(framesCount));
            animations.Add("down", new Frame(framesCount));
            animations.Add("right", new Frame(framesCount));
            animations.Add("left", new Frame(framesCount, true));
            animations.Add("upRight", new Frame(framesCount));
            animations.Add("downRight", new Frame(framesCount));
            animations.Add("upLeft", new Frame(framesCount, true));
            animations.Add("downLeft", new Frame(framesCount, true));
            animations.Add("dying", new Frame(0, 1));

            this.animations = new Animation(sprites, animations, "down", width, height);

            textureName.Add(AnimationType.WALKING, "Skeleton");

            information = new InformationUnit("Skeleton", Race.NEUTRAL, Faction.NEUTRAL, 40, 0, 360, 10, 0, 0, Util.Buildings.NONE, 300, 6, 1, Util.Units.SKELETON, 3);
            Information = information;
        }
示例#25
0
 /// <summary>
 ///     Dynamically convert from value and unit enum <see cref="InformationUnit" /> to <see cref="Information" />.
 /// </summary>
 /// <param name="value">Value to convert from.</param>
 /// <param name="fromUnit">Unit to convert from.</param>
 /// <returns>Information unit value.</returns>
 public static Information?From(QuantityValue?value, InformationUnit fromUnit)
 {
     return(value.HasValue ? new Information((decimal)value.Value, fromUnit) : default(Information?));
 }
示例#26
0
        /// <summary>
        ///     Parse a unit string.
        /// </summary>
        /// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
        /// <param name="unit">The parsed unit if successful.</param>
        /// <returns>True if successful, otherwise false.</returns>
        /// <example>
        ///     Length.TryParseUnit("m", new CultureInfo("en-US"));
        /// </example>
        /// <param name="cultureName">Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" /> if null.</param>
        public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out InformationUnit unit)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitParser.Default.TryParse <InformationUnit>(str, provider, out unit));
        }
示例#27
0
        public Footman(int tileX, int tileY, ManagerMouse managerMouse, ManagerMap managerMap, ManagerUnits managerUnits)
            : base(tileX, tileY, 52, 52, 2, managerMouse, managerMap, managerUnits)
        {
            Dictionary <AnimationType, List <Sprite> > sprites = new Dictionary <AnimationType, List <Sprite> >();
            List <Sprite> spriteWalking = new List <Sprite>();

            // UP
            spriteWalking.Add(new Sprite(22, 10, 31, 40));
            spriteWalking.Add(new Sprite(22, 62, 30, 52));
            spriteWalking.Add(new Sprite(22, 119, 30, 49));
            spriteWalking.Add(new Sprite(23, 182, 29, 37));
            spriteWalking.Add(new Sprite(22, 230, 31, 37));
            // DOWN
            spriteWalking.Add(new Sprite(316, 12, 32, 46));
            spriteWalking.Add(new Sprite(315, 72, 29, 42));
            spriteWalking.Add(new Sprite(316, 128, 30, 44));
            spriteWalking.Add(new Sprite(318, 178, 31, 42));
            spriteWalking.Add(new Sprite(316, 226, 32, 45));
            // LEFT
            spriteWalking.Add(new Sprite(176, 12, 32, 37));
            spriteWalking.Add(new Sprite(168, 73, 45, 37));
            spriteWalking.Add(new Sprite(170, 127, 39, 38));
            spriteWalking.Add(new Sprite(170, 179, 32, 33));
            spriteWalking.Add(new Sprite(169, 226, 35, 34));
            // UP-RIGHT
            spriteWalking.Add(new Sprite(99, 10, 25, 39));
            spriteWalking.Add(new Sprite(94, 65, 39, 41));
            spriteWalking.Add(new Sprite(95, 123, 32, 40));
            spriteWalking.Add(new Sprite(97, 179, 33, 38));
            spriteWalking.Add(new Sprite(99, 225, 31, 39));
            // DOWN-RIGHT
            spriteWalking.Add(new Sprite(244, 13, 40, 35));
            spriteWalking.Add(new Sprite(240, 74, 43, 40));
            spriteWalking.Add(new Sprite(242, 129, 41, 37));
            spriteWalking.Add(new Sprite(244, 177, 36, 35));
            spriteWalking.Add(new Sprite(244, 227, 38, 31));
            sprites.Add(AnimationType.WALKING, spriteWalking);

            List <Sprite> spriteAttacking = new List <Sprite>();

            // UP
            spriteAttacking.Add(new Sprite(2, 287, 48, 37));
            spriteAttacking.Add(new Sprite(15, 335, 32, 58));
            spriteAttacking.Add(new Sprite(2, 409, 56, 37));
            spriteAttacking.Add(new Sprite(27, 452, 28, 50));
            // DOWN
            spriteAttacking.Add(new Sprite(319, 285, 46, 38));
            spriteAttacking.Add(new Sprite(321, 329, 31, 47));
            spriteAttacking.Add(new Sprite(313, 398, 51, 47));
            spriteAttacking.Add(new Sprite(312, 466, 32, 54));
            // LEFT
            spriteAttacking.Add(new Sprite(172, 275, 33, 49));
            spriteAttacking.Add(new Sprite(151, 336, 58, 42));
            spriteAttacking.Add(new Sprite(164, 396, 40, 49));
            spriteAttacking.Add(new Sprite(173, 466, 47, 35));
            // UP-RIGHT
            spriteAttacking.Add(new Sprite(77, 286, 52, 38));
            spriteAttacking.Add(new Sprite(77, 338, 50, 40));
            spriteAttacking.Add(new Sprite(78, 396, 55, 49));
            spriteAttacking.Add(new Sprite(101, 453, 45, 48));
            // DOWN-RIGHT
            spriteAttacking.Add(new Sprite(248, 275, 22, 48));
            spriteAttacking.Add(new Sprite(241, 329, 35, 48));
            spriteAttacking.Add(new Sprite(246, 396, 35, 52));
            spriteAttacking.Add(new Sprite(233, 467, 61, 33));
            sprites.Add(AnimationType.ATTACKING, spriteAttacking);

            List <Sprite> spriteDie = new List <Sprite>();

            spriteDie.Add(new Sprite(236, 533, 47, 40));
            sprites.Add(AnimationType.DYING, spriteDie);

            Dictionary <string, Frame> animations = new Dictionary <string, Frame>();

            Dictionary <AnimationType, int> framesCount = new Dictionary <AnimationType, int>();

            framesCount.Add(AnimationType.WALKING, 5);
            framesCount.Add(AnimationType.ATTACKING, 4);
            framesCount.Add(AnimationType.DYING, 1);

            animations.Add("up", new Frame(framesCount));
            animations.Add("down", new Frame(framesCount));
            animations.Add("right", new Frame(framesCount));
            animations.Add("left", new Frame(framesCount, true));
            animations.Add("upRight", new Frame(framesCount));
            animations.Add("downRight", new Frame(framesCount));
            animations.Add("upLeft", new Frame(framesCount, true));
            animations.Add("downLeft", new Frame(framesCount, true));
            animations.Add("dying", new Frame(0, 1));

            this.animations = new Animation(sprites, animations, "down", width, height);

            ui = new UI.Units.Footman(managerMouse, this);
            textureName.Add(AnimationType.WALKING, "Footman");

            information = new InformationUnit("Footman", Race.HUMAN, Faction.ALLIANCE, 60, 6, 360, 10, 600, 1, Util.Buildings.BARRACKS, 60 * Warcraft.FPS, 6, 1, Util.Units.FOOTMAN, 3);
            Information = information;
        }
示例#28
0
 /// <summary>
 ///     Get string representation of value and unit. Using two significant digits after radix.
 /// </summary>
 /// <param name="unit">Unit representation to use.</param>
 /// <param name="provider">Format to use for localization and number formatting. Defaults to <see cref="UnitSystem.DefaultCulture" />.</param>
 /// <returns>String representation.</returns>
 public string ToString(InformationUnit unit, [CanBeNull] IFormatProvider provider)
 {
     return(ToString(unit, provider, 2));
 }
示例#29
0
        /// <summary>
        ///     Converts this Information to another Information with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A Information with the specified unit.</returns>
        public Information ToUnit(InformationUnit unit)
        {
            var convertedValue = AsBaseNumericType(unit);

            return(new Information(convertedValue, unit));
        }
        public ElvenArcher(int tileX, int tileY, ManagerMouse managerMouse, ManagerMap managerMap, ManagerBuildings managerBuildings, ManagerUnits managerUnits)
            : base(tileX, tileY, 48, 48, 2, managerMouse, managerMap, managerBuildings)
        {
            Dictionary <AnimationType, List <Sprite> > sprites = new Dictionary <AnimationType, List <Sprite> >();
            List <Sprite> spriteWalking = new List <Sprite>();

            // UP
            spriteWalking.Add(new Sprite(6, 11, 40, 47));
            spriteWalking.Add(new Sprite(5, 85, 42, 49));
            spriteWalking.Add(new Sprite(5, 159, 41, 47));
            spriteWalking.Add(new Sprite(8, 234, 36, 47));
            spriteWalking.Add(new Sprite(5, 308, 41, 46));
            // DOWN
            spriteWalking.Add(new Sprite(241, 17, 44, 42));
            spriteWalking.Add(new Sprite(239, 92, 43, 41));
            spriteWalking.Add(new Sprite(241, 165, 43, 42));
            spriteWalking.Add(new Sprite(247, 238, 38, 41));
            spriteWalking.Add(new Sprite(244, 312, 41, 41));
            // LEFT
            spriteWalking.Add(new Sprite(128, 16, 38, 40));
            spriteWalking.Add(new Sprite(128, 92, 40, 41));
            spriteWalking.Add(new Sprite(129, 164, 39, 41));
            spriteWalking.Add(new Sprite(129, 240, 35, 38));
            spriteWalking.Add(new Sprite(130, 312, 35, 41));
            // UP-RIGHT
            spriteWalking.Add(new Sprite(67, 12, 42, 45));
            spriteWalking.Add(new Sprite(70, 88, 38, 41));
            spriteWalking.Add(new Sprite(68, 161, 40, 44));
            spriteWalking.Add(new Sprite(65, 230, 41, 46));
            spriteWalking.Add(new Sprite(67, 306, 40, 43));
            // DOWN-RIGHT
            spriteWalking.Add(new Sprite(186, 17, 42, 37));
            spriteWalking.Add(new Sprite(183, 92, 38, 37));
            spriteWalking.Add(new Sprite(184, 165, 40, 38));
            spriteWalking.Add(new Sprite(187, 237, 43, 36));
            spriteWalking.Add(new Sprite(187, 312, 42, 37));
            sprites.Add(AnimationType.WALKING, spriteWalking);

            List <Sprite> spriteAttacking = new List <Sprite>();

            // UP
            spriteAttacking.Add(new Sprite(10, 373, 45, 52));
            spriteAttacking.Add(new Sprite(10, 452, 44, 48));
            // DOWN
            spriteAttacking.Add(new Sprite(238, 388, 45, 36));
            spriteAttacking.Add(new Sprite(237, 460, 45, 39));
            // LEFT
            spriteAttacking.Add(new Sprite(128, 380, 46, 42));
            spriteAttacking.Add(new Sprite(130, 455, 39, 40));
            // UP-RIGHT
            spriteAttacking.Add(new Sprite(67, 382, 43, 47));
            spriteAttacking.Add(new Sprite(71, 457, 38, 46));
            // DOWN-RIGHT
            spriteAttacking.Add(new Sprite(189, 389, 36, 36));
            spriteAttacking.Add(new Sprite(184, 463, 41, 37));
            sprites.Add(AnimationType.ATTACKING, spriteAttacking);

            List <Sprite> spriteDie = new List <Sprite>();

            spriteDie.Add(new Sprite(181, 530, 44, 43));
            sprites.Add(AnimationType.DYING, spriteDie);

            Dictionary <string, Frame> animations = new Dictionary <string, Frame>();

            Dictionary <AnimationType, int> framesCount = new Dictionary <AnimationType, int>();

            framesCount.Add(AnimationType.WALKING, 5);
            framesCount.Add(AnimationType.ATTACKING, 2);
            framesCount.Add(AnimationType.DYING, 1);

            animations.Add("up", new Frame(framesCount));
            animations.Add("down", new Frame(framesCount));
            animations.Add("right", new Frame(framesCount));
            animations.Add("left", new Frame(framesCount, true));
            animations.Add("upRight", new Frame(framesCount));
            animations.Add("downRight", new Frame(framesCount));
            animations.Add("upLeft", new Frame(framesCount, true));
            animations.Add("downLeft", new Frame(framesCount, true));
            animations.Add("dying", new Frame(0, 1));

            this.animations = new Animation(sprites, animations, "down", width, height);

            ui = new UI.Units.ElvenArcher(managerMouse, this);
            textureName.Add(AnimationType.WALKING, "Elven Archer");

            information = new InformationUnit("Elven Archer", Race.HIGH_ELF, Faction.ALLIANCE, 150, 20, 360, 10, 500, 1, Util.Buildings.BARRACKS, 400, 20, 100, 4, 0, Util.Units.ELVEN_ARCHER);
            Information = information;
        }