Example #1
0
        /// <summary>
        /// Checks whether a cell is adjacent
        /// </summary>
        /// <param name="grid">The game field</param>
        /// <param name="size">The size of the field</param>
        /// <param name="i">The row index of the cell</param>
        /// <param name="j">The column index of the cell</param>
        /// <returns></returns>
        private bool IsAdjacent(char[,] grid, int size, int i, int j)
        {
            if (grid[i, j] != EMPTY)
            {
                return(false);
            }

            bool res = false;

            if (i - 1 >= 0)
            {
                res = _lettSet.GetIndex(grid[i - 1, j]) != -1;
            }
            if (!res && i + 1 < size)
            {
                res = _lettSet.GetIndex(grid[i + 1, j]) != -1;
            }
            if (!res && j - 1 >= 0)
            {
                res = _lettSet.GetIndex(grid[i, j - 1]) != -1;
            }
            if (!res && j + 1 < size)
            {
                res = _lettSet.GetIndex(grid[i, j + 1]) != -1;
            }
            return(res);
        }
Example #2
0
 /// <summary>
 /// Checks whether a given word is correct
 /// </summary>
 /// <param name="word">The word it needs to check</param>
 /// <returns>true if the word is correct</returns>
 private bool CorrectWord(string word)
 {
     foreach (var ch in word)
     {
         if (_lettSet.GetIndex(ch) == -1)
         {
             return(false);
         }
     }
     return(true);
 }