Example #1
0
    /// <summary>Checks each element on the board for matches and flags them</summary>
    public int CheckBoardForMatches()
    {
        AlexDebugger.GetInstance().AddMessage("Checking board for new matches...", AlexDebugger.tags.Aftermatch);
        int totalMatches = 0;

        // Search for matches and flag them
        for (int row = 0; row < elementsPositions.GetLength(1); row++)
        {
            for (int collum = 0; collum < elementsPositions.GetLength(0); collum++)
            {
                // case of cash element has reached bottom
                if (row == elementsPositions.GetLength(1) - 1 && elementsPositions[collum, row].GetElementClassType() == typeof(CashBoardElement))
                {
                    matchedElemPositions[collum, row] = true;
                    AlexDebugger.GetInstance().AddMessage("A cash element has reached bottom at position: " + collum + ", " + row, AlexDebugger.tags.Aftermatch);
                    totalMatches++;
                }
                else if (matchedElemPositions[collum, row] == true || !changedPotitions[collum, row])
                {
                    continue;
                }
                else
                {
                    totalMatches += BoardFunctions.CheckElementForMatches(collum, row, elementsPositions, ref matchedElemPositions, ConstantValues.totalCollums, ConstantValues.totalRows, true);
                }
            }
        }
        return(totalMatches);
    }
Example #2
0
    /// <summary>Check if with input it can create matches. Returns best score found </summary>
    public static int IsPotentialInput(int collum, int row, BoardElement[, ] positions, bool[, ] matchedElemPositions, int totalCollums, int totalRows)
    {
        int possibleScore = 0;

        if (row - 1 > -1 && positions[collum, row - 1].GetElementClassType() != typeof(CashBoardElement))
        {
            BoardFunctions.SwapBoardElementNeighbours(positions[collum, row], positions[collum, row - 1], ref positions);
            int matches = BoardFunctions.CheckElementForMatches(collum, row - 1, positions, ref matchedElemPositions, totalCollums, totalRows, false);
            if (matches > 0)
            {
                possibleScore = matches;
            }
            BoardFunctions.SwapBoardElementNeighbours(positions[collum, row], positions[collum, row - 1], ref positions);
        }
        if (row + 1 < totalRows && positions[collum, row + 1].GetElementClassType() != typeof(CashBoardElement))
        {
            BoardFunctions.SwapBoardElementNeighbours(positions[collum, row], positions[collum, row + 1], ref positions);
            int matches = BoardFunctions.CheckElementForMatches(collum, row + 1, positions, ref matchedElemPositions, totalCollums, totalRows, false);
            if (matches > 0 && possibleScore < matches)
            {
                possibleScore = matches;
            }
            BoardFunctions.SwapBoardElementNeighbours(positions[collum, row], positions[collum, row + 1], ref positions);
        }
        if (collum - 1 > -1 && positions[collum - 1, row].GetElementClassType() != typeof(CashBoardElement))
        {
            BoardFunctions.SwapBoardElementNeighbours(positions[collum, row], positions[collum - 1, row], ref positions);
            int matches = BoardFunctions.CheckElementForMatches(collum - 1, row, positions, ref matchedElemPositions, totalCollums, totalRows, false);
            if (matches > 0 && possibleScore < matches)
            {
                possibleScore = matches;
            }
            BoardFunctions.SwapBoardElementNeighbours(positions[collum, row], positions[collum - 1, row], ref positions);
        }
        if (collum + 1 < totalCollums && positions[collum + 1, row].GetElementClassType() != typeof(CashBoardElement))
        {
            BoardFunctions.SwapBoardElementNeighbours(positions[collum, row], positions[collum + 1, row], ref positions);
            int matches = BoardFunctions.CheckElementForMatches(collum + 1, row, positions, ref matchedElemPositions, totalCollums, totalRows, false);
            if (matches > 0 && possibleScore < matches)
            {
                possibleScore = matches;
            }
            BoardFunctions.SwapBoardElementNeighbours(positions[collum, row], positions[collum + 1, row], ref positions);
        }
        return(possibleScore);
    }
Example #3
0
    public bool HandleInputForElement(BoardElement element, BoardElement otherElement)
    {
        bool areThereMatches = false;

        if (element.GetElementClassType() == typeof(CashBoardElement) || otherElement.GetElementClassType() == typeof(CashBoardElement))
        {
            return(false);
        }
        else if (element.GetElementClassType() == typeof(BombBoardElement))
        {
            if (otherElement.GetElementClassType() == typeof(CrossBoardElement))
            {
                //AlexDebugger.GetInstance().AddMessage(BoardFunctions.GetTransformByIndex(element.GetTransformIndex()) + " bomb style set to cross", AlexDebugger.tags.Step1);
                ((BombBoardElement)element).SetExplosionStyleTo(BombBoardElement.BombExplosionStyle.CrossStyle);
            }
            else if (otherElement.GetElementClassType() == typeof(BombBoardElement))
            {
                //AlexDebugger.GetInstance().AddMessage(BoardFunctions.GetTransformByIndex(element.GetTransformIndex()) + " bomb style set to double bomb", AlexDebugger.tags.Step1);
                ((BombBoardElement)element).SetExplosionStyleTo(BombBoardElement.BombExplosionStyle.DoubleBombStyle);
            }
            element.OnElementDestruction(this);
            AlexDebugger.GetInstance().AddMessage("first element was a bomb, go to step2: -play effects for matched elements-", AlexDebugger.tags.Step1);
            areThereMatches = true;
        }
        else if (element.GetElementClassType() == typeof(BellBoardElement))
        {
            AlexDebugger.GetInstance().AddMessage("first element was a bell, go to step2: -play effects for matched elements-", AlexDebugger.tags.Step1);
            element.OnElementDestruction(this, otherElement);
            areThereMatches = true;
        }
        else
        {
            KeyValuePair <int, int> firstPosition = BoardFunctions.GetBoardPositionOfElement(element, elementsPositions);
            int numberOfMatchesForFirst           = BoardFunctions.CheckElementForMatches(firstPosition.Key, firstPosition.Value, elementsPositions, ref matchedElemPositions, ConstantValues.totalCollums, ConstantValues.totalRows, true);
            // if there are matches
            if (numberOfMatchesForFirst > 0)
            {
                AlexDebugger.GetInstance().AddMessage("Matches found for first element " + numberOfMatchesForFirst + ", go to step2: -play effects for matched elements-", AlexDebugger.tags.Step1);
                // allow Update() to play effects
                areThereMatches = true;
            }
        }
        return(areThereMatches);
    }