コード例 #1
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_tilesLeft       = total + 2;
            m_totalTiles      = total + 2;
            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(' ');
        }
コード例 #2
0
        /// <summary>
        /// Generates the dictionaries needed to calculate the words.
        ///
        /// charCodes assigns one prime number to each letter in the tileset.
        /// charPoints associates each letter with its number of points (obtained from ScrabbleLetter)
        /// </summary>
        private void GenerateDictionaries()
        {
            // Clear previous values.
            for (int i = 0; i < charCodes.Length; i++)
            {
                charCodes[i]  = 0;
                charPoints[i] = 0;
            }
            blanks = 0;

            // First seven prime numbers. No more than these will ever be needed.
            int[] primes = { 2, 3, 5, 7, 11, 13, 17 };
            for (int i = 0; i < letters.Length; i++)
            {
                // If the letter is a blank, ignore it and simply add to the blanks counter.
                if (letters[i] == ' ')
                {
                    blanks++;
                }
                else
                {
                    charCodes[letters[i] - 65]  = primes[i];
                    charPoints[letters[i] - 65] = new ScrabbleLetter(letters[i]).Points;
                }
            }
        }
コード例 #3
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);
        }