Ejemplo n.º 1
0
        /// <summary>
        /// Checks if the input string is a TW coordinate
        /// </summary>
        public Point?GetCoordinates(string input)
        {
            Match match = VillagePattern.Match(input.Trim());

            if (match.Success)
            {
                int x;
                int y;
                if (int.TryParse(match.Groups[1].Value, out x) && int.TryParse(match.Groups[2].Value, out y) &&
                    x > 0 && x < 1000 && y > 0 && y < 1000)
                {
                    return(new Point(x, y));
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks if the input string is a village
        /// </summary>
        public Village GetVillage(string input)
        {
            Match match = VillagePattern.Match(input.Trim());

            if (match.Success)
            {
                int x;
                int y;
                if (int.TryParse(match.Groups[1].Value, out x) && int.TryParse(match.Groups[2].Value, out y))
                {
                    var loc = new Point(x, y);
                    if (Default.Villages.ContainsKey(loc))
                    {
                        return(Default.Villages[loc]);
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets all villages in the input string
        /// </summary>
        public IEnumerable <Village> GetVillages(string input)
        {
            MatchCollection matches = VillagePattern.Matches(input.Trim());

            foreach (var match in matches.OfType <Match>())
            {
                if (match.Success)
                {
                    int x;
                    int y;
                    if (int.TryParse(match.Groups[1].Value, out x) && int.TryParse(match.Groups[2].Value, out y))
                    {
                        var loc = new Point(x, y);
                        if (Default.Villages.ContainsKey(loc))
                        {
                            yield return(Default.Villages[loc]);
                        }
                    }
                }
            }
        }