Example #1
0
    public static BoardElement CreateNewElement(BoardElement previousElement, BoardElement.BoardElementTypes type)
    {
        int     randomNum = random.Next(0, ConstantValues.GetAvailableColors().Length);
        Vector4 newColor  = ConstantValues.GetAvailableColors() [randomNum];

        switch (type)
        {
        case BoardElement.BoardElementTypes.Cross:
            previousElement = new CrossBoardElement(previousElement.GetTransformIndex(), previousElement.GetElementValue());
            break;

        case BoardElement.BoardElementTypes.Bomb:
            previousElement = new BombBoardElement(previousElement.GetTransformIndex());
            break;

        case BoardElement.BoardElementTypes.Bell:
            previousElement = new BellBoardElement(previousElement.GetTransformIndex());
            break;

        case BoardElement.BoardElementTypes.Default:
            if (previousElement.GetElementClassType() != typeof(BoardElement))
            {
                previousElement = new BoardElement(previousElement.GetTransformIndex(), newColor);
            }
            else
            {
                previousElement.OnElementAppearance(newColor);
            }
            break;
        }

        return(previousElement);
    }
Example #2
0
 public static BoardElement CreateNewCashElement(BoardElement previousElement, int cashTypeIndex)
 {
     previousElement = new CashBoardElement(previousElement.GetTransformIndex(), cashTypeIndex);
     return(previousElement);
 }
Example #3
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));
        }
    }