Exemplo n.º 1
0
 private void RemoveFormations(DiscoveredFormations formations)
 {
     foreach (Block block in formations.AllClearedBlocks)
     {
         grid.RemoveBlock(block.GridPosition);
     }
 }
Exemplo n.º 2
0
 private IEnumerator UpdateFormation(DiscoveredFormations formations, Block.State toState)
 {
     foreach (Block block in formations.AllClearedBlocks)
     {
         if (UpdateFormationBlock(block, toState) == true)
         {
             yield return(animationDelays.WaitForStaggerFormation);
         }
     }
 }
Exemplo n.º 3
0
 private void UpdateScore(DiscoveredFormations formations, ref int comboCounter)
 {
     // Go through each formation
     foreach (Block[] formation in formations.AllFormations)
     {
         // Increment score
         Score += scoreCalculator.GetScore(formation, BlocksInARow, comboCounter);
         ++comboCounter;
     }
 }
Exemplo n.º 4
0
        private Block GetLastBlock(DiscoveredFormations formation)
        {
            Block returnBlock = null;

            if (formation.ColumnFormations.Count > 0)
            {
                Block[] column = formation.ColumnFormations[formation.ColumnFormations.Count - 1];
                returnBlock = column[column.Length - 1];
            }
            else if (formation.RowFormations.Count > 0)
            {
                Block[] row = formation.RowFormations[formation.RowFormations.Count - 1];
                returnBlock = row[row.Length - 1];
            }
            return(returnBlock);
        }
Exemplo n.º 5
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);
        }