Ejemplo n.º 1
0
    public override void OnClick()
    {
        List <BoardElement> toRemove = new List <BoardElement>();
        List <AlphaAnimatedVisibleBoardElement> toFadeOut = new List <AlphaAnimatedVisibleBoardElement>();

        toFadeOut.Add(this);
        foreach (string uid in dissapearUIDs)
        {
            BoardElement found = Board.Instance().FindByUID(uid);
            if (found != null)
            {
                if (found is AlphaAnimatedVisibleBoardElement)
                {
                    toFadeOut.Add((AlphaAnimatedVisibleBoardElement)found);
                }
                else
                {
                    toRemove.Add(found);
                }
            }
        }

        CommandQueue.Queue(new RemoveFromBoardCommand(toRemove.ToArray()));

        foreach (AlphaAnimatedVisibleBoardElement fadingElement in toFadeOut)
        {
            fadingElement.Fade(0f, RemoveFromBoard);
        }
    }
Ejemplo n.º 2
0
        public void BoardElementAddComentaryTest()
        {
            BoardElement element = new BoardElement(originPointX, originPointY, height, width, comentarysBoardElement);

            element.AddCommentary(commentary);
            Assert.IsTrue(element.GetComentarys().Contains(commentary));
        }
Ejemplo n.º 3
0
 public static bool IsEnemyNotDeadHead(this BoardElement boardElement) =>
 boardElement == BoardElement.EnemyHeadDown ||
 boardElement == BoardElement.EnemyHeadLeft ||
 boardElement == BoardElement.EnemyHeadRight ||
 boardElement == BoardElement.EnemyHeadUp ||
 boardElement == BoardElement.EnemyHeadEvil ||
 boardElement == BoardElement.EnemyHeadSleep;
Ejemplo n.º 4
0
    private bool PlayEffectsStep()
    {
        BoardElement lastElementProcessed   = secondElement;
        bool         areThereChangesOnBoard = false;

        for (int row = 0; row < elementsPositions.GetLength(1); row++)
        {
            for (int collum = 0; collum < elementsPositions.GetLength(0); collum++)
            {
                if (matchedElemPositions[collum, row] == true)
                {
                    BoardFunctions.PlayMatchEffectAnimations(collum, row, this);
                    if (BoardFunctions.DestroyBoardElement(collum, row, this, lastElementProcessed))
                    {
                        areThereChangesOnBoard = true;
                    }
                }
                lastElementProcessed = elementsPositions[collum, row];
                BoardFunctions.ToggleHighlightCell(collum, row, this, false);
            }
        }

        if (!areThereChangesOnBoard)
        {
            AlexDebugger.GetInstance().AddMessage("Step2 finished: -play effects for matched elements-, go to Step3: -reorient elements- " + messagesToClient.Count, AlexDebugger.tags.Step2);
            return(true);
        }
        else
        {
            AlexDebugger.GetInstance().AddMessage("Step2 finished: -play effects for matched elements-, new elements has been destroyed, repeating step ", AlexDebugger.tags.Step2);
            return(false);
        }
    }
Ejemplo n.º 5
0
        public GameBoard(GameBoard board)
        {
            Size = board.Size;

            Board = new BoardElement[Size, Size];
            for (int y = 0; y < Size; y++)
            {
                for (int x = 0; x < Size; x++)
                {
                    Board[x, y] = board.Board[x, y];
                }
            }

            Head = board.Head;

            HeadType = board.HeadType;

            Tail = board.Tail;

            TailType = board.TailType;

            EvilTicks = board.EvilTicks;

            HasStone = board.HasStone;

            MyLength = board.MyLength;

            Nyamka = board.Nyamka;
        }
Ejemplo n.º 6
0
 public static bool IsEnemyBody(this BoardElement boardElement) =>
 boardElement == BoardElement.EnemyBodyHorizontal ||
 boardElement == BoardElement.EnemyBodyLeftDown ||
 boardElement == BoardElement.EnemyBodyLeftUp ||
 boardElement == BoardElement.EnemyBodyRightDown ||
 boardElement == BoardElement.EnemyBodyRightUp ||
 boardElement == BoardElement.EnemyBodyVertical;
        public static bool IsEnemy(this BoardElement element)
        {
            switch (element)
            {
            case BoardElement.EnemyHeadDown:
            case BoardElement.EnemyHeadLeft:
            case BoardElement.EnemyHeadRight:
            case BoardElement.EnemyHeadUp:
            case BoardElement.EnemyHeadEvil:
            case BoardElement.EnemyTailEndDown:
            case BoardElement.EnemyTailEndLeft:
            case BoardElement.EnemyTailEndUp:
            case BoardElement.EnemyTailEndRight:
            case BoardElement.EnemyTailInactive:
            case BoardElement.EnemyBodyHorizontal:
            case BoardElement.EnemyBodyVertical:
            case BoardElement.EnemyBodyLeftDown:
            case BoardElement.EnemyBodyLeftUp:
            case BoardElement.EnemyBodyRightDown:
            case BoardElement.EnemyBodyRightUp:
                return(true);

            default:
                return(false);
            }
        }
Ejemplo n.º 8
0
    // Processes the input on the given element
    private void ProcessBoardElement(BoardElement element)
    {
        //No element selected yet? Select element!
        if (SelectedElements.Count == 0)
        {
            //Cache selected color
            connectionLine.Color = element.Color;

            //Add element to selection
            AddElementToSelection(element);
        }
        else
        {
            //Is the element already selected?
            if (SelectedElements.Contains(element))
            {
                //Did the player moved back? Deselect element!
                if (IsSecondLast(element))
                {
                    DeselectLast();
                }
            }
            //Not selected, correct color and in distance? Select element!
            else if (IsSelectable(element))
            {
                AddElementToSelection(element);
            }
        }
    }
Ejemplo n.º 9
0
    /// <summary>
    /// Returns true if an element is touched by the mouse, false otherwise.
    /// Outs the touched element, null otherwise
    /// </summary>
    private bool InputRaycast(out BoardElement element)
    {
        element = null;

        //Get mouse position
        Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        //Shoot a raycast on z-level
        RaycastHit2D hitInfo = Physics2D.Raycast(mousePos, Vector2.zero);

        if (hitInfo)
        {
            //Try to get the BoardElement element
            element = hitInfo.transform.GetComponent <BoardElement>();

            //Return true if the hit object is GameGridElement
            if (element != null)
            {
                return(true);
            }
        }

        //Return false if nothing is hit or if the object is not BoardElement
        return(false);
    }
Ejemplo n.º 10
0
        public void BoardElementRemoveComentarysNotExistTest()
        {
            BoardElement element = new BoardElement(originPointX, originPointY, height, width, comentarysBoardElement);

            element.RemoveComentary(commentary);
            Assert.IsFalse(element.GetComentarys().Contains(commentary));
        }
Ejemplo n.º 11
0
    /// <summary>Receives input from client and handles it</summary>
    public void TakeInput(int firstElementIndexAtParent, int secondElementIndexAtParent)
    {
        // find first element based on gamePanel's child index
        firstElement = BoardFunctions.GetElementBasedOnParentIndex(elementsPositions, firstElementIndexAtParent);
        // find second element based on gamePanel's child index
        secondElement = BoardFunctions.GetElementBasedOnParentIndex(elementsPositions, secondElementIndexAtParent);
        currentStep   = GameStep.CheckingInput;

        #region  Debug
        //  To use for cheats
        // if (BoardFunctions.GetIfNeighbours(firstElement, secondElement, elementsPositions)) {
        //     AlexDebugger.GetInstance().AddMessage("Correct input: " + BoardFunctions.GetTransformByIndex(firstElement.GetTransformIndex()) + ", with " + BoardFunctions.GetTransformByIndex(secondElement.GetTransformIndex()), AlexDebugger.tags.Input);
        //     // Remove tokens
        //     MoneyManager.ChangeBalanceBy(-MoneyManager.GetSwapCost());
        //     // Swap the elements on the board
        //     BoardFunctions.SwapElements(firstElement, secondElement, this, rewire : false, FixedElementData.swappingSpeed / 2);
        //     // Allow Update() to check if matches are created

        // }
        // else {
        //     // Swap elements, on rewire mode
        //     BoardFunctions.SwapElements(firstElement, secondElement, this, rewire : true);
        //     AddWaitMessage();
        //     SendMessagesToClient();
        //     currentMessageID += 1;
        //     Server.GetServerInstance().SendMessageToClient(new Messages.ServerStatusMessage(currentMessageID, -1, true));

        // }
        #endregion
    }
Ejemplo n.º 12
0
        public static Graph Create(GameBoard gameBoard)
        {
            Graph graph = new Graph();
            var   size  = gameBoard.Size;

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    BoardElement element = gameBoard.Board[i, j];
                    if (ElementHelper.IsWall(element))
                    {
                        continue;
                    }
                    BoardPoint point = new BoardPoint(i, j);

                    graph.AddNode(point, element);
                }
            }



            //for (var i = 0; i < objects.Count; ++i)
            //{
            //    if (objects[i].IsOutOfBoard(gameBoard.Size)) continue;
            //    graph.AddNode(objects[i], gameBoard.Board[]);
            //    ++t;
            //}
            //AddNeighborhood(graph, gameBoard);
            return(graph);
        }
Ejemplo n.º 13
0
        private void CreateStep(BoardElement boardElement, Step element)
        {
            Transform transform = null;

            var stepGameObject = _cacheManager.GetAvailableStep();

            if (stepGameObject != null)
            {
                transform = stepGameObject.transform;
            }
            else
            {
                var stepObject = (GameObject)Resources.Load(StepElementPath, typeof(GameObject));
                transform        = GameObject.Instantiate(stepObject).transform;
                transform.parent = _gameElements.transform;
            }

            element.Active    = true;
            element.Transform = transform;

            var animator = element.Transform.GetChild(1).GetComponent <Animator>();

            animator.enabled = !element.DontUseSound;

            element.Transform.position = GetPositionVector(boardElement.Row, boardElement.Column);

            var textElement = element.Transform.GetChild(0).GetComponent <TextMesh>();

            textElement.text = GetStepText(element.Number);

            element.Transform.gameObject.SetActive(true);
        }
Ejemplo n.º 14
0
        internal static List <Element> FindAllNear(GameBoard board, int x, int y, BoardElement element)
        {
            var result = new List <Element>();

            if (x != 0 && board.Board[x - 1, y] == element)
            {
                result.Add(new Element(x - 1, y));
            }

            if (x != board.Size - 1 && board.Board[x + 1, y] == element)
            {
                result.Add(new Element(x + 1, y));
            }

            if (y != 0 && board.Board[x, y - 1] == element)
            {
                result.Add(new Element(x, y - 1));
            }

            if (y != board.Size - 1 && board.Board[x, y + 1] == element)
            {
                result.Add(new Element(x, y + 1));
            }

            return(result);
        }
Ejemplo n.º 15
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));
        }
    }
Ejemplo n.º 16
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);
    }
Ejemplo n.º 17
0
 public static bool DestroyBoardElement(int collum, int row, BoardManager board, BoardElement lastElementProccesed)
 {
     //AlexDebugger.GetInstance().AddMessage("Element: " + GetTransformByIndex(board.elementsPositions[collum, row].GetTransformIndex()) + "  was a match of color: " + board.elementsPositions[collum, row].GetElementValue().ToString() + ", de-activating highlight.", AlexDebugger.tags.Step2);
     if (board.elementsPositions[collum, row].GetElementClassType() == typeof(BombBoardElement) || board.elementsPositions[collum, row].GetElementClassType() == typeof(CrossBoardElement))
     {
         if (board.elementsPositions[collum, row].OnElementDestruction(board))
         {
             return(true);
         }
     }
     else if (board.elementsPositions[collum, row].GetElementClassType() == typeof(BellBoardElement))
     {
         if (board.elementsPositions[collum, row].OnElementDestruction(board, lastElementProccesed))
         {
             return(true);
         }
     }
     else if (board.elementsPositions[collum, row].GetElementClassType() == typeof(CashBoardElement))
     {
         board.currentMessageID += 1;
         board.messagesToClient.Add(new Messages.AnimationMessage.ScrollWinHistoryMessage(board.currentMessageID, board.currentMessageID - 1, board.elementsPositions[collum, row].GetTransformIndex(), board.elementsPositions[collum, row].GetElementSpriteIndex(), ((CashBoardElement)board.elementsPositions[collum, row]).GetCashValue().ToString()));
         if (board.elementsPositions[collum, row].OnElementDestruction(board))
         {
             return(true);
         }
     }
     else
     {
         if (board.elementsPositions[collum, row].OnElementDestruction(board))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 18
0
        public void BoardElementSetHeighTest()
        {
            BoardElement element   = new BoardElement(originPointX, originPointY, height, width, comentarysBoardElement);
            int          newHeight = 5;

            element.SetHeigh(newHeight);
            Assert.AreEqual(element.GetHeigh(), newHeight);
        }
Ejemplo n.º 19
0
 public void dataForBoardElementTest()
 {
     comentarysElement = new List <Commentary>();
     originPointX      = 10;
     originPointY      = 9;
     heightElement     = 8;
     widthElement      = 7;
     element           = new BoardElement(originPointX, originPointY, heightElement, widthElement, comentarysElement);
 }
Ejemplo n.º 20
0
 public void RpcUpdateBoard(BoardElement element, int index)
 {
     if (!isServer)
     {
         board [index] = element;
         Debug.Log("Client received index = " + index);
     }
     //		this.board = board;
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Returns True if BoardElement is at x,y coordinates.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="element"></param>
        /// <returns></returns>
        public bool HasElementAt(int x, int y, BoardElement element)
        {
            if (IsOutOfBoard(x, y))
            {
                return(false);
            }

            return(GetAt(x, y) == element);
        }
        public bool HasElementAt(BoardPoint point, BoardElement element)
        {
            if (point.IsOutOfBoard(Size))
            {
                return(false);
            }

            return(GetElementAt(point) == element);
        }
Ejemplo n.º 23
0
        public Route(IReadOnlyList <BoardPoint> path, BoardElement goalElement, bool isFurry)
        {
            Path        = path;
            GoalElement = goalElement;
            GoalPoint   = path.Last();

            decimal cost = GoalElement.GetCost(isFurry);

            Income = cost / Length;
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Counts the number of occurrences of element nearby.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="element"></param>
        /// <returns></returns>
        public int GetCountElementsNearToPoint(int x, int y, BoardElement element)
        {
            if (IsOutOfBoard(x, y))
            {
                return(0);
            }

            return(EnumerateNeighbors(new BoardPoint(x, y))
                   .Count(neighbor => HasElementAt(neighbor, element)));
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Check if near exists element of chosen type.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="element"></param>
        /// <returns></returns>
        public bool IsNearToElement(int x, int y, BoardElement element)
        {
            if (IsOutOfBoard(x, y))
            {
                return(false);
            }

            return(EnumerateNeighbors(new BoardPoint(x, y))
                   .Any(neighbor => HasElementAt(neighbor, element)));
        }
        public bool IsNearToElement(BoardPoint point, BoardElement element)
        {
            if (point.IsOutOfBoard(Size))
                return false;

            return HasElementAt(point.ShiftBottom(), element)
                   || HasElementAt(point.ShiftTop(), element)
                   || HasElementAt(point.ShiftLeft(), element)
                   || HasElementAt(point.ShiftRight(), element);
        }
Ejemplo n.º 27
0
    public void SelectElement(string elementID)
    {
        placeholderText.SetActive(false);
        selectedElementID = elementID;
        BoardElement boardElement = GetSelectedElement();

        boardImage.sprite = boardElement.image;
        boardTitle.text   = elementID;
        detailsTab.SetActive(true);
    }
Ejemplo n.º 28
0
        private void CreateFirstTarget(BoardElement boardElement)
        {
            var entity = _world.CreateEntityWith <Target>(out Target target);

            target.Row    = boardElement.Row;
            target.Column = boardElement.Column;
            target.Round  = AppConstants.FirstRound;
            target.Value  = TargetValueEnum.AddWall;
            target.Silent = false;
        }
Ejemplo n.º 29
0
    void CmdCheckOmnomnom()
    {
        Vector2      currentField = new Vector2(Mathf.RoundToInt(transform.position.x), Mathf.RoundToInt(transform.position.y));
        BoardElement elem         = board.elementForPosition(currentField);

        if (elem == BoardElement.bonus_flame || elem == BoardElement.bonus_bomb)
        {
            Debug.Log("WOŁAM = " + this.name);
            board.omnomnom(currentField, this.name);
        }
    }
        public int GetCountElementsNearToPoint(BoardPoint point, BoardElement element)
        {
            if (point.IsOutOfBoard(Size))
                return 0;

            //GetHashCode() in classic MS.NET for bool returns 1 for true and 0 for false;
            return HasElementAt(point.ShiftLeft(), element).GetHashCode() +
                   HasElementAt(point.ShiftRight(), element).GetHashCode() +
                   HasElementAt(point.ShiftTop(), element).GetHashCode() +
                   HasElementAt(point.ShiftBottom(), element).GetHashCode();
        }
Ejemplo n.º 31
0
        public List<BoardPoint> FindAllElements(BoardElement element)
        {
            List<BoardPoint> result = new List<BoardPoint>();

            for (int i = 0; i < Size * Size; i++)
            {
                BoardPoint pt = GetPointByShift(i);

                if (HasElementAt(pt, element))
                {
                    result.Add(pt);
                }
            }

            return result;
        }
Ejemplo n.º 32
0
        public int GetCountElementsNearToPoint(BoardPoint point, BoardElement element)
        {
            if (point.IsOutOfBoard(Size))
                return 0;

            //GetHashCode() in classic MS.NET for bool returns 1 for true and 0 for false;
            return HasElementAt(point.ShiftLeft(), element).GetHashCode() +
                   HasElementAt(point.ShiftRight(), element).GetHashCode() +
                   HasElementAt(point.ShiftTop(), element).GetHashCode() +
                   HasElementAt(point.ShiftBottom(), element).GetHashCode();
        }
Ejemplo n.º 33
0
        public bool HasElementAt(BoardPoint point, BoardElement element)
        {
            if (point.IsOutOfBoard(Size))
            {
                return false;
            }

            return GetElementAt(point) == element;
        }
Ejemplo n.º 34
0
        public bool IsNearToElement(BoardPoint point, BoardElement element)
        {
            if (point.IsOutOfBoard(Size))
                return false;

            return HasElementAt(point.ShiftBottom(), element)
                   || HasElementAt(point.ShiftTop(), element)
                   || HasElementAt(point.ShiftLeft(), element)
                   || HasElementAt(point.ShiftRight(), element);
        }