Exemple #1
0
    public void Push(GameController script)
    {
        script.PushTimeReset();
        print("PUSH!");

        if (heldBlock != null)
        {
            //This is probably annoying, but it will at least correct make sur eit doesnt mess things up further
            heldBlock.PutDownBlock();
        }

        foreach (KeyValuePair <int, BlockScript> kvp in fieldBlocks)
        {
            if (kvp.Value.state != BlockState.Match)
            {
                kvp.Value.MoveBlock();
            }
            kvp.Value.ChangeBlock(kvp.Value.x, kvp.Value.y + 1);
        }
        foreach (KeyValuePair <int, BlockScript> kvp in fieldBlocks)
        {
            if (kvp.Value.y == 0)
            {
                CheckForMatchesAtBlock(kvp.Value);
            }
        }

        CreateBlocksAtY(-1);
    }
Exemple #2
0
    public bool CheckForMatchesAtBlock(BlockScript matchBlock, bool autoResolve = true, bool isCombo = false)
    {
        if (IsBlockEligibleForMatch(matchBlock) == true && CheckForHolesAtBlock(matchBlock) == 0)
        {
            BlockScript potentialMatchBlock;
            int         potentialMatchXi = 1;
            int         potentialMatchYi = 101;
            Dictionary <int, BlockScript> fieldMatches = new Dictionary <int, BlockScript>();

            //matchBlock.PrintBlock("CheckforMatchesAtBlock", "------------------------------------------------------------------------");

            //Check X+1
            potentialMatchBlock = GetMatchForBlockAtXY(matchBlock, matchBlock.x + 1, matchBlock.y);
            if (potentialMatchBlock != null)
            {
                fieldMatches.Add(potentialMatchXi, potentialMatchBlock);
                potentialMatchXi++;

                //Check X+2
                potentialMatchBlock = GetMatchForBlockAtXY(matchBlock, matchBlock.x + 2, matchBlock.y);
                if (potentialMatchBlock != null)
                {
                    fieldMatches.Add(potentialMatchXi, potentialMatchBlock);
                    potentialMatchXi++;

                    //Check X+3
                    potentialMatchBlock = GetMatchForBlockAtXY(matchBlock, matchBlock.x + 3, matchBlock.y);
                    if (potentialMatchBlock != null)
                    {
                        fieldMatches.Add(potentialMatchXi, potentialMatchBlock);
                        potentialMatchXi++;
                    }
                }
            }

            //Check X-1
            potentialMatchBlock = GetMatchForBlockAtXY(matchBlock, matchBlock.x - 1, matchBlock.y);
            if (potentialMatchBlock != null)
            {
                fieldMatches.Add(potentialMatchXi, potentialMatchBlock);
                potentialMatchXi++;

                //Check X-2
                potentialMatchBlock = GetMatchForBlockAtXY(matchBlock, matchBlock.x - 2, matchBlock.y);
                if (potentialMatchBlock != null)
                {
                    fieldMatches.Add(potentialMatchXi, potentialMatchBlock);
                    potentialMatchXi++;

                    //Check X-3
                    potentialMatchBlock = GetMatchForBlockAtXY(matchBlock, matchBlock.x - 3, matchBlock.y);
                    if (potentialMatchBlock != null)
                    {
                        fieldMatches.Add(potentialMatchXi, potentialMatchBlock);
                        potentialMatchXi++;
                    }
                }
            }

            //Check Y+1
            potentialMatchBlock = GetMatchForBlockAtXY(matchBlock, matchBlock.x, matchBlock.y + 1);
            if (potentialMatchBlock != null)
            {
                fieldMatches.Add(potentialMatchYi, potentialMatchBlock);
                potentialMatchYi++;

                //Check Y+2
                potentialMatchBlock = GetMatchForBlockAtXY(matchBlock, matchBlock.x, matchBlock.y + 2);
                if (potentialMatchBlock != null)
                {
                    fieldMatches.Add(potentialMatchYi, potentialMatchBlock);
                    potentialMatchYi++;

                    //Check Y+3
                    potentialMatchBlock = GetMatchForBlockAtXY(matchBlock, matchBlock.x, matchBlock.y + 3);
                    if (potentialMatchBlock != null)
                    {
                        fieldMatches.Add(potentialMatchYi, potentialMatchBlock);
                        potentialMatchYi++;
                    }
                }
            }

            //Check Y-1
            potentialMatchBlock = GetMatchForBlockAtXY(matchBlock, matchBlock.x, matchBlock.y - 1);
            if (potentialMatchBlock != null)
            {
                if (potentialMatchBlock.y >= 0)
                {
                    fieldMatches.Add(potentialMatchYi, potentialMatchBlock);
                    potentialMatchYi++;

                    //Check y-2
                    potentialMatchBlock = GetMatchForBlockAtXY(matchBlock, matchBlock.x, matchBlock.y - 2);
                    if (potentialMatchBlock != null)
                    {
                        if (potentialMatchBlock.y >= 0)
                        {
                            fieldMatches.Add(potentialMatchYi, potentialMatchBlock);
                            potentialMatchYi++;

                            //Check y-3
                            potentialMatchBlock = GetMatchForBlockAtXY(matchBlock, matchBlock.x, matchBlock.y - 3);
                            if (potentialMatchBlock != null)
                            {
                                fieldMatches.Add(potentialMatchYi, potentialMatchBlock);
                                potentialMatchYi++;
                            }
                        }
                    }
                }
            }

            if (potentialMatchXi >= 3 && autoResolve == false || potentialMatchYi >= 103 && autoResolve == false)
            {
                return(true);
            }

            //If enough matches, drop it and clear them
            if (potentialMatchXi >= 3 || potentialMatchYi >= 103)
            {
                Dictionary <int, BlockScript> fieldMatchesFinal = new Dictionary <int, BlockScript>();

                foreach (KeyValuePair <int, BlockScript> kvp in fieldMatches)
                {
                    if (potentialMatchXi >= 3 && kvp.Key < 100)
                    {
                        fieldMatchesFinal.Add(kvp.Value.key, kvp.Value);
                    }
                    else if (potentialMatchYi >= 103 && kvp.Key > 100)
                    {
                        fieldMatchesFinal.Add(kvp.Value.key, kvp.Value);
                    }
                }
                matchBlock.state = BlockState.Match;
                matchBlock.PutDownBlock();
                fieldMatchesFinal.Add(0, matchBlock);

                if (isCombo == true)
                {
                    MatchComboBlocks(fieldMatchesFinal);
                }
                else
                {
                    MatchBlocks(fieldMatchesFinal);
                }
            }
        }


        return(false);
    }