private string ColorCode(WordLocation location)
        {
            string code;

            if (Colors.ContainsKey(location))
            {
                code = Colors[location];
            }
            else
            {
                code             = Cycler.NextColorCode();
                Colors[location] = code;
            }

            return(code);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the word in this <see cref="WordSearch"/> at the given <see cref="WordLocation"/>.
        /// </summary>
        /// <param name="location">A <see cref="WordLocation"/> instance representing the location of the word.</param>
        /// <returns>A <see cref="string"/> containing the requested word.</returns>
        public string GetWord(WordLocation location)
        {
            // Ensure that both the start and end locations of the word are in bounds.
            ValidateLocation(location.StartRow, location.StartCol);
            ValidateLocation(location.EndRow, location.EndCol);

            var result = new StringBuilder();

            // Iterate through each character in the requested word.
            for (var n = 0; n < location.Length; n++)
            {
                // For each character, calculate its row and column.
                var row = location.StartRow + location.DirectionY * n;
                var col = location.StartCol + location.DirectionX * n;

                // Append the calculated character to the result.
                result.Append(Chars[row, col]);
            }

            return(result.ToString());
        }