Esempio n. 1
0
        public IEnumerator AnimateScan(InventoryCollection enable)
        {
            // Setup variables
            int  comboCount       = 0;
            bool isFormationFound = false;

            // Disable inventory
            enable.IsAllEnabled = false;

            // Drop blocks first; let them contribute to the combos
            DropNewBlocks();
            yield return(StartCoroutine(AnimateBlocksDropping()));

            // Scan for any formations
            DiscoveredFormations formations = ScanFormations(comboCount, out isFormationFound);

            while (isFormationFound == true)
            {
                // Calculate the score
                formations.SortLists();
                UpdateScore(formations, ref comboCount);

                // Update blocks to indicate they're now in combo state
                yield return(StartCoroutine(UpdateFormation(formations, Block.State.Combo)));

                // Wait for the combo animation to finish
                float waitTime = animationDelays.GetDelayBetweenComboAndElimination(formations.NumBlocks);
                if (waitTime > 0)
                {
                    yield return(new WaitForSeconds(waitTime));
                }

                // Update blocks to indicate they're eliminated
                yield return(StartCoroutine(UpdateFormation(formations, Block.State.Eliminated)));

                // Wait until the last block is hidden
                Block lastBlock = GetLastBlock(formations);
                while (lastBlock.CurrentState != Block.State.Hidden)
                {
                    yield return(null);
                }

                // Remove all blocks
                RemoveFormations(formations);

                // Animate the blocks dropping
                yield return(StartCoroutine(AnimateBlocksDropping()));

                // Scan for the next formations
                isFormationFound = false;
                formations       = ScanFormations(comboCount, out isFormationFound);
            }

            // Check if the player should end the game or not.
            bool isGameOver = CheckGameOver();

            if (isGameOver == false)
            {
                // Re-enable inventory
                enable.IsAllEnabled = true;
                LastGameSettings.Instance.SaveSettings();
            }
            else
            {
                // Reset all stats
                LastGameSettings.Instance.Reset();
            }
            OnMove?.Invoke(this);
        }