/// <summary>
        /// Checks if all characters in a word can be removed by charcters in the players' hand.
        /// </summary>
        /// <param name="wordtocheck"></param>
        /// <returns> Returns true if the word can be played with the current tiles.</returns>
        private int checkWord(string wordtocheck)
        {
            string word = wordtocheck.ToUpper();///ensures playerhand and the word's cases match.
            int    numberRemovedByWild = 0;
            int    points = 0;

            for (int i = 0; i < 7; i++)
            {
                if (word.Length == 0)
                {
                    break;
                }
                else if (word.Contains(playerHand[i]))
                {
                    word    = word.Remove(word.IndexOf(playerHand[i]), 1);
                    points += ScrabbleLetter.HowManyPoints(playerHand[i]);
                }
                else if (playerHand[i] == ' ')
                {
                    numberRemovedByWild++;
                }
            }
            if (word == "")
            {
                return(points);
            }
            else if (word.Length <= numberRemovedByWild)
            {
                return(points);
            }
            else
            {
                return(0);
            }
        }
示例#2
0
        /// <summary>
        /// Set the tiles based on the Scrabble Game
        /// </summary>
        public ScrabbleGame()
        {
            int startingLetter = (char)'A';
            int total          = 0;

            //Loop through the letters and determine how many tiles per letter
            for (int i = startingLetter; i < (startingLetter + 26); i++)
            {
                total += ScrabbleLetter.HowManyTiles((char)i);
            }
            //Set variable values and instantiate the array
            m_totalTiles      = total + 2;
            m_tilesLeft       = m_totalTiles;
            m_scrabbleLetters = new ScrabbleLetter[total + 2]; //2 blank tiles!
            int counter = 0;                                   //use to control the index of the array

            //Loop through the letters to create the tiles
            for (int i = startingLetter; i < (startingLetter + 26); i++)
            {
                //Loop through the number of tiles for that letter
                for (int j = 0; j < ScrabbleLetter.HowManyTiles((char)i); j++)
                {
                    m_scrabbleLetters[counter] = new ScrabbleLetter((char)i);
                    counter++;//always increase the counter!
                }
            }
            //add the two blanks
            m_scrabbleLetters[counter] = new ScrabbleLetter(' ');
            counter++;
            m_scrabbleLetters[counter] = new ScrabbleLetter(' ');
        }
示例#3
0
        public static int HowManyPoints(char L)
        {
            ScrabbleLetter s = new ScrabbleLetter(L);

            return(s.Points);
        }
示例#4
0
        /// <summary>
        /// Returns how many tiles in scrabble have the letter.
        /// </summary>
        /// <param name="L">The letter.</param>
        /// <returns></returns>
        public static int HowManyTiles(char L)
        {
            ScrabbleLetter s = new ScrabbleLetter(L);

            return(s.NumberOfLetters);
        }