Пример #1
0
        public void Click()
        {
            if (m_game.Active == false)
            {
                return;
            }
            if (checkedElement != null)
            {
                if (checkedElement == this)                                     // clicking on element we already selected
                {
                    m_backColor    = Color.Transparent;
                    checkedElement = null;
                }
                else
                {
                    bool near = false;

                    if ((checkedElement.m_index.X == m_index.X - 1 && checkedElement.m_index.Y == m_index.Y) ||                 // checking if elements are next to eachother (not diagonal)
                        (checkedElement.m_index.X == m_index.X + 1 && checkedElement.m_index.Y == m_index.Y) ||
                        (checkedElement.m_index.X == m_index.X && checkedElement.m_index.Y == m_index.Y - 1) ||
                        (checkedElement.m_index.X == m_index.X && checkedElement.m_index.Y == m_index.Y + 1))
                    {
                        near = true;
                    }

                    if (!near)                                                  // 2nd element is not near 1st -> keep 2nd selected
                    {
                        checkedElement.m_backColor = Color.Transparent;
                        m_backColor    = Color.DarkSlateBlue;
                        checkedElement = this;
                    }
                    else                                                        // 1st and 2nd are near -> do animation
                    {
                        checkedElement.m_backColor = Color.Transparent;
                        m_game.Active = false;
                        VisualElement el = checkedElement;
                        checkedElement = null;
                        SwapAnimation swap = new SwapAnimation(m_game);
                        swap.AnimationEnd += delegate
                        {
                            m_game.MoveElements(el, this);
                        };
                        swap.Start(el, this);
                    }
                }
            }
            else
            {
                m_backColor    = Color.DarkSlateBlue;
                checkedElement = this;
            }
            m_game.Refresh();
        }
Пример #2
0
        public void MoveElements(VisualElement a, VisualElement b)
        {
            Index aInd = new Index(a.Index);
            Index bInd = new Index(b.Index);

            m_game.Swap(aInd, bInd);
            swapElements(aInd, bInd);

            bool result = m_game.RemoveMatches();

            if (result == false)
            {
                SwapAnimation swap = new SwapAnimation(this);
                swap.AnimationEnd += delegate
                {
                    aInd = new Index(a.Index);
                    bInd = new Index(b.Index);
                    m_game.Swap(aInd, bInd);
                    swapElements(aInd, bInd);
                    Active = true;
                };
                swap.Start(b, a);
            }
        }