示例#1
0
        private void writeWordToGrid(String word, KoordinateKata coordinate)
        {
            int k = 0;

            for (int i = (coordinate.getDirection() == 0) ? coordinate.getY() : coordinate.getX();
                 i < word.Length + ((coordinate.getDirection() == 0) ? coordinate.getY() : coordinate.getX());
                 i++)
            {
                grid.setValue(coordinate.getDirection() == 0 ? coordinate.getX() : i,
                              coordinate.getDirection() == 0 ? i : coordinate.getY(), word.ElementAt(k++));
            }
        }
示例#2
0
 private void addToPertanyaan(String word, KoordinateKata coordinate)
 {
     if (coordinate.getDirection() == 0)
     {
         //List<String> l = (List<String>)Horizontal[coordinate.getX()];
         //if (l == null) l = new List<String>();
         //l.Add(word);
         Horizontal.Add(coordinate.getX(), word);
     }
     else
     {
         //List<String> l = (List<String>)Vertical[coordinate.getY()];
         //if (l == null) l = new List<String>();
         //l.Add(word);
         Vertical.Add(coordinate.getY(), word);
     }
 }
示例#3
0
        private int checkScore(String word, KoordinateKata coordinate)
        {
            int row = coordinate.getX();
            int col = coordinate.getY();

            if (col < 0 || row < 0)
            {
                return(0);
            }

            int count = 1;
            int score = 1;

            foreach (char letter in word.ToCharArray())
            {
                if (!isEmpty(row, col) && grid.getValue(row, col) != letter)
                {
                    return(0);
                }

                if (grid.getValue(row, col) == letter)
                {
                    score++;
                }

                if (coordinate.getDirection() == 1)
                {
                    //vertical
                    if (grid.getValue(row, col) != letter && (!isEmpty(row, col + 1) || !isEmpty(row, col - 1)))
                    {
                        return(0);
                    }

                    if (count == 1 && !isEmpty(row - 1, col))
                    {
                        return(0);
                    }

                    if (count == word.Length && !isEmpty(row + 1, col))
                    {
                        return(0);
                    }

                    row++;
                }
                else
                {
                    //Horizontal

                    if (grid.getValue(row, col) != letter && (!isEmpty(row - 1, col) || !isEmpty(row + 1, col)))
                    {
                        return(0);
                    }

                    if (count == 1 && !isEmpty(row, col - 1))
                    {
                        return(0);
                    }

                    if (count == word.Length && !isEmpty(row, col + 1))
                    {
                        return(0);
                    }

                    col++;
                }

                count++;
            }

            return(score);
        }