예제 #1
0
    /// <summary>Sets swapping animations and changes positions on the board if it is not gonna rewire </summary>
    /// <param name="firstElement"></param>
    /// <param name="secondElement"></param>
    /// <param name="positions">the board of elemetns</param>
    /// <param name="playingAnimations">list to add new animations</param>
    /// <param name="rewire">use if input is incorrect</param>
    /// <param name="shouldCheckMatches">should check for new matches after swap?</param>
    /// <param name="swappingSpeed">the speed of animation</param>
    /// <returns>Returns if should check</returns>
    public static void SwapElements(BoardElement firstElement, BoardElement secondElement, BoardManager board, bool rewire = false, float speed = -1)
    {
        if (speed == -1)
        {
            speed = ConstantValues.swappingSpeed;
        }
        KeyValuePair <int, int> firstElementPosOnBoard  = GetBoardPositionOfElement(firstElement, board.elementsPositions);
        KeyValuePair <int, int> secondElementPosOnBoard = GetBoardPositionOfElement(secondElement, board.elementsPositions);

        board.currentMessageID += 1;
        board.messagesToClient.Add(new Messages.AnimationMessage(board.currentMessageID, -1, Messages.AnimationMessage.AnimationMessageTypes.MoveTo, firstElement.GetTransformIndex(), speed, secondElementPosOnBoard.Key, secondElementPosOnBoard.Value));

        board.currentMessageID += 1;
        board.messagesToClient.Add(new Messages.AnimationMessage(board.currentMessageID, -1, Messages.AnimationMessage.AnimationMessageTypes.MoveTo, secondElement.GetTransformIndex(), speed, firstElementPosOnBoard.Key, firstElementPosOnBoard.Value));

        if (!rewire)
        {
            BoardFunctions.SwapBoardElementNeighbours(firstElement, secondElement, ref board.elementsPositions);
        }
        else
        {
            board.currentMessageID += 1;
            board.messagesToClient.Add(new Messages.AnimationMessage(board.currentMessageID, board.currentMessageID - 2, Messages.AnimationMessage.AnimationMessageTypes.MoveTo, firstElement.GetTransformIndex(), speed, firstElementPosOnBoard.Key, firstElementPosOnBoard.Value));
            board.currentMessageID += 1;
            board.messagesToClient.Add(new Messages.AnimationMessage(board.currentMessageID, board.currentMessageID - 2, Messages.AnimationMessage.AnimationMessageTypes.MoveTo, secondElement.GetTransformIndex(), speed, secondElementPosOnBoard.Key, secondElementPosOnBoard.Value));
        }
    }
예제 #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);
    }