예제 #1
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);
            }
        }
예제 #2
0
        public void Click()
        {
            if (m_game.Active == false)
            {
                return;
            }
            if (checkedElement != null)
            {
                if (checkedElement == this)
                {
                    //отмена выбора
                    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) ||
                        (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)
                    {
                        //Выбор другого элемента
                        checkedElement.m_backColor = Color.Transparent;
                        m_backColor    = Color.DarkSlateBlue;
                        checkedElement = this;
                    }
                    else
                    {
                        //проверка двух соседних элементов
                        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();
        }