Ejemplo n.º 1
0
    public List<GameObject> ParseWordFromRow(List<List<GameObject>> blockWord)
    {
        string wordString = "";
        List<string> validWords = new List<string>();
        Dictionary<string, int> wordScores = new Dictionary<string, int>();

        var words = WordStore.GetWords();
        foreach (List<GameObject> blockList in blockWord)
        {
            wordString = ParseWord(blockList);

            foreach (string validWord in words)
            {
                if (wordString.Contains(validWord))
                {
                    validWords.Add(validWord);
                }
            }
            if(validWords != null && validWords.Count > 0)
            {
                foreach (var validWord in validWords)
                {
                    var score = scoreHandler.CalculateScore(validWord);
                    wordScores.Add(validWord, score);
                }
                var highestScoringWord = wordScores.OrderByDescending(x => x.Value).First().Key;

                return FilterBlocks(blockList, highestScoringWord);
            }

            //Set the string back to empty if the word was not found.
            wordString = string.Empty;
        }
        return new List<GameObject>();
    }
Ejemplo n.º 2
0
    private void FixedUpdate()
    {
        if (activeBlock != null)
        {
            Block block = activeBlock.GetComponent <Block>();
            //Once you cannot keep moving down, you stop being the active block
            if (!block.GetFreeDirections()[1])
            {
                StoreBlock(activeBlock);
                List <GameObject> wordBlocks = wordHandler.ParseRow(activeBlock);
                string            wordString = wordHandler.ParseWord(wordBlocks);
                if (wordString != string.Empty)
                {
                    var score = scoreHandler.CalculateScore(wordString);
                    scoreHandler.AddToTotal(score);
                    if (floatingScorePrefab != null)
                    {
                        var transformAt = wordBlocks[0].transform;
                        ShowFloatingScoreText(score, transformAt.transform.TransformPoint(transformAt.position));
                        FindObjectOfType <AudioManager>().Play("Ding");
                    }
                }
                if (wordBlocks != null && wordBlocks.Count > 0)
                {
                    wordBlocks.ForEach(x => x.transform.position = new Vector3(100, 100, 0));
                    wordBlocks.ForEach(x => Destroy(x));
                    foreach (GameObject blockObject in blockStore.GetAllBlocks())
                    {
                        if (blockObject != null)
                        {
                            blockObject.layer = 2;
                            blockObject.GetComponent <Block>().CheckCollision();
                            blockObject.layer = 0;
                        }
                    }
                }

                activeBlock.layer = 0;
                ClearActiveBlock();
            }
        }
        if (activeBlock == null)
        {
            activeBlock = SpawnBlock();
            userInputHandler.SetActiveObject(activeBlock);
        }
    }