Example #1
0
 /// <summary>
 /// After placing a word get new letters
 /// </summary>
 /// <param name="word"></param>
 /// <param name="firstLetterIndex"></param>
 /// <param name="secondLetterIndex"></param>
 private void ChangeLetters(string word, int firstLetterIndex, int secondLetterIndex)
 {
     for (int i = 0; i < word.Length; i++)
     {
         if (i == firstLetterIndex || i == secondLetterIndex)
         {
             continue;
         }
         Letters.Remove(word[i]);
     }
     Letters.AddRange(TheLetterManager.GetLetters(word.Length));
 }
Example #2
0
        /// <summary>
        /// Find and choose a word
        /// </summary>
        private void FindWord()
        {
            List <string> possibleWords = new List <string>();
            int           prefferedMaxWordLength;

            if (difficulty == Difficulty.Easy)
            {
                prefferedMaxWordLength = Random.Range(4, 5);
            }
            else if (difficulty == Difficulty.Medium)
            {
                prefferedMaxWordLength = Random.Range(4, 7);
            }
            else
            {
                prefferedMaxWordLength = Random.Range(6, 12);
            }
            foreach (var word in TheLetterManager.AllWords)
            {
                if (word.Length <= prefferedMaxWordLength && CheckWord(word))
                {
                    possibleWords.Add(word);
                }
            }

            string foundWord = "";

            if (possibleWords.Any())
            {
                foundWord = possibleWords[Random.Range(0, possibleWords.Count())];
            }

            float timeRemaining;

            if (difficulty == Difficulty.Easy)
            {
                timeRemaining = TheLetterManager.CalculatePoints(foundWord) + 5;
            }
            else if (difficulty == Difficulty.Medium)
            {
                timeRemaining = TheLetterManager.CalculatePoints(foundWord);
            }
            else
            {
                timeRemaining = TheLetterManager.CalculatePoints(foundWord);
            }
            StartCoroutine(WaitToPlaceWord(timeRemaining, foundWord));
        }
Example #3
0
        /// <summary>
        /// All logic for placing a word
        /// </summary>
        /// <param name="foundWord"></param>
        private void PlaceWord(string foundWord)
        {
            hasFoundWord = false;
            if (foundWord == "")
            {
                Letters = TheLetterManager.GetLetters(TheLetterManager.FirstPlayerLetters.Count()).ToList();
                return;
            }
            playerManager.NextTurn();
            ChangeLetters(foundWord, foundWord.IndexOf(FirstLetter), foundWord.LastIndexOf(SecondLetter));
            long points = TheLetterManager.CalculatePoints(foundWord);

            EarnedPoints += points;
            PlacedInBoard(foundWord, foundWord.IndexOf(FirstLetter), foundWord.LastIndexOf(SecondLetter));
            LetterManager.ChangeFixedLetters(foundWord, true);
            TheLetterManager.PlacedWords.Add(foundWord);
            LetterManager.GameBoardWordContainer.transform.parent.transform.parent.GetComponent <GameboardScroll>().ScrollDownBar();
            int bestWordIndex = BestWordsThisGame.Count(word => word.points > points);

            BestWordsThisGame.Insert(bestWordIndex, new Word(foundWord, points));
        }