Exemple #1
0
        private bool IsHeightValid()
        {
            if (!string.IsNullOrWhiteSpace(Height))
            {
                if (Height.Contains("cm"))
                {
                    return(Height.Substring(0, Height.Length - 2).ToInt().IsWithin(150, 193));
                }

                if (Height.Contains("in"))
                {
                    return(Height.Substring(0, Height.Length - 2).ToInt().IsWithin(59, 76));
                }
            }

            return(false);
        }
Exemple #2
0
        public WPos CenterOfCell(CPos cell)
        {
            if (Grid.Type == MapGridType.Rectangular)
            {
                return(new WPos(1024 * cell.X + 512, 1024 * cell.Y + 512, 0));
            }

            // Convert from isometric cell position (x, y) to world position (u, v):
            // (a) Consider the relationships:
            //  - Center of origin cell is (512, 512)
            //  - +x adds (512, 512) to world pos
            //  - +y adds (-512, 512) to world pos
            // (b) Therefore:
            //  - ax + by adds (a - b) * 512 + 512 to u
            //  - ax + by adds (a + b) * 512 + 512 to v
            var z = Height.Contains(cell) ? 512 * Height[cell] : 0;

            return(new WPos(512 * (cell.X - cell.Y + 1), 512 * (cell.X + cell.Y + 1), z));
        }
Exemple #3
0
        public bool isValidPassport()
        {
            bool byrValid = BirthYear >= 1920 && BirthYear <= 2002;
            bool iyrValid = IssueYear >= 2010 && IssueYear <= 2020;
            bool eyrValid = ExpirationYear >= 2020 && ExpirationYear <= 2030;

            bool hgtValid = false;

            if (Height.Contains("cm"))
            {
                int num = 0;
                hgtValid = int.TryParse(Height.Replace("cm", ""), out num);
                if (num < 150 || num > 193)
                {
                    hgtValid = false;
                }
            }
            else if (Height.Contains("in"))
            {
                int num = 0;
                hgtValid = int.TryParse(Height.Replace("in", ""), out num);
                if (num < 59 || num > 76)
                {
                    hgtValid = false;
                }
            }

            bool hclValid = false;

            if (HairColor.IndexOf('#') == 0)
            {
                int num;
                hclValid = int.TryParse(HairColor.Remove(0, 1), System.Globalization.NumberStyles.HexNumber, null, out num);
            }

            bool eclValid = EYE_COLOR_VALUES.Contains(EyeColor);

            long useless;
            bool pidValid = (PassportID.Length == 9) && (long.TryParse(PassportID, out useless));

            return(areRequiredFieldsPresent() && byrValid && iyrValid && eyrValid && hgtValid && hclValid && eclValid && pidValid);
        }
Exemple #4
0
        private bool IsHeightValid()
        {
            if (string.IsNullOrEmpty(Height))
            {
                return(false);
            }

            bool ValidateHeight(string unit, int min, int max)
            {
                var removed         = Height.Replace(unit, string.Empty);
                var parsedCorrectly = int.TryParse(removed, out var height);

                return(parsedCorrectly &&
                       height >= min &&
                       height <= max);
            }

            return(Height.Contains("cm")
                ? ValidateHeight("cm", 150, 193)
                : Height.Contains("in") &&
                   ValidateHeight("in", 59, 76));
        }
Exemple #5
0
        /// <summary>
        /// Convert from isometric cell position to world position;
        /// </summary>
        /// <param name="cell"></param>
        /// <returns></returns>
        public WPos CenterOfCell(CPos cell)
        {
            if (Grid.Type == MapGridT.Rectangular)
            {
                return(new WPos(1024 * cell.X + 512, 1024 * cell.Y + 512, 0));
            }

            //Convert from isometric cell position (x,y) to world position (u,v):
            //(a) Consider the relationships:
            //  - Center of origin cell is (512,512)
            //  - +x adds (512,512) to world pos
            //  - +y adds (-512,512) to world pos
            //(b) Therefore:
            // - ax+by adds (a-b)*512 + 512 to u
            // - ax+by adds (a+b)*512 + 512 to v
            //(c) u,v coordinates run diagonally to the cell axes, and we define 1024 as the length projected onto the primary cell axis
            //u,v坐标以单元轴对角线方式运行,我们将1024定义为投影到主单元轴上的长度
            // - 512*sqrt(2) = 724;
            var z = Height.Contains(cell) ? 724 * Height[cell] : 0;

            return(new WPos(724 * (cell.X - cell.Y + 1), 724 * (cell.X + cell.Y + 1), z));
        }