public static string CheckHorizontal(Button[,] btns, int tileIndex, InternalBoard ib, ref List <int> positions)
        {
            StringBuilder sb = new StringBuilder();

            int[] indicies = BoardHandler.getRowCol(tileIndex);
            int   row = indicies[0];
            int   col = indicies[1];
            int   max = 14, min = 0;

            //Right
            for (int i = col; i < max; i++)
            {
                if (string.IsNullOrEmpty(btns[row, i].Text) || btns[row, i].Text.Length > 1)
                {
                    break;
                }
                else
                {
                    positions.Add((row * 15) + i);
                    sb.Append(btns[row, i].Text);
                }
            }
            //Left
            for (int i = col - 1; i >= min; i--)
            {
                if (string.IsNullOrEmpty(btns[row, i].Text) || btns[row, i].Text.Length > 1)
                {
                    break;
                }
                else
                {
                    positions.Add((row * 15) + i);
                    sb.Insert(0, btns[row, i].Text);
                }
            }

            if (sb.ToString().Length > 1)
            {
                return(sb.ToString());
            }
            else
            {
                return("");
            }
        }
Exemple #2
0
        public static bool CheckForTurnPlacement(int pos, InternalBoard ib)
        {
            LetterTile lt = (LetterTile)ib.Board[pos];

            return(lt.PlacedThisTurn);
        }
Exemple #3
0
        public static string VerifyBoard(Button[,] board, List <int> placements, WordChecker wc, InternalBoard ib)
        {
            StringBuilder    sb    = new StringBuilder();
            HashSet <string> words = new HashSet <string>();

            foreach (int tileIndex in placements)
            {
                bool   wordCreatedThisTurn = false;
                string horizontalWord;
                string verticalWord;
                //Horizontal Word
                List <int> positions = new List <int>(15);
                horizontalWord = (BoardCheckerHorizontal.CheckHorizontal(board, tileIndex, ib, ref positions));

                foreach (int pos in positions)
                {
                    if (wordCreatedThisTurn == true)
                    {
                        break;
                    }

                    if (TilePlacement.CheckForTurnPlacement(pos, ib))
                    {
                        words.Add(horizontalWord);
                        wordCreatedThisTurn = true;
                    }
                }
                //Vertical Word
                positions    = new List <int>(15);
                verticalWord = (BoardCheckerVertical.CheckVertical(board, tileIndex, ib, ref positions));

                foreach (int pos in positions)
                {
                    if (wordCreatedThisTurn == true)
                    {
                        break;
                    }

                    if (TilePlacement.CheckForTurnPlacement(pos, ib))
                    {
                        words.Add(verticalWord);
                        wordCreatedThisTurn = true;
                    }
                }
            }

            foreach (string word in words)
            {
                if (word.Length < 2)
                {
                    continue;
                }
                if (wc.CheckWord(word))
                {
                    sb.Append(word + " ");
                }
                else
                {
                    sb.Append(word + "! ");
                }
            }
            return(sb.ToString());
        }