Ejemplo n.º 1
0
 private void UpdateDoubleAnimationByDiamond(DoubleAnimation da, Diamond diamond, double To)
 {
     try
     {
         Storyboard.SetTarget(da, diamond.RenderTransform);
         if (diamond.direction == Direction.Up || diamond.direction == Direction.Down)
         {
             Storyboard.SetTargetProperty(da, new PropertyPath("Y"));
             if (diamond.direction == Direction.Up)
             {
                 da.To = -To;
             }
             else
             {
                 da.To = To;
             }
         }
         if (diamond.direction == Direction.Left || diamond.direction == Direction.Right)
         {
             Storyboard.SetTargetProperty(da, new PropertyPath("X"));
             if (diamond.direction == Direction.Left)
             {
                 da.To = -To;
             }
             else
             {
                 da.To = To;
             }
         }
     }
     catch
     {
     }
 }
Ejemplo n.º 2
0
        void Diamond_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Diamond dia = sender as Diamond;

            dia.CaptureMouse();
            isMouseLeftButtonDown = true;
            mouseUpBeforePoint    = e.GetPosition(null);
        }
Ejemplo n.º 3
0
        void Diamond_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Diamond dia = sender as Diamond;

            dia.ReleaseMouseCapture();
            isMouseLeftButtonDown = false;
            //this.direction = Direction.Nothing;
        }
Ejemplo n.º 4
0
        private Diamond GetDiamondByDirection(Diamond firstDiamond)
        {
            switch (firstDiamond.direction)
            {
            case Direction.Nothing:
                secondDiamond = null;
                break;

            case Direction.Up:
                if (firstDiamond.Row != 0)
                {
                    secondDiamond = this[firstDiamond.Column, firstDiamond.Row - 1];
                    if (secondDiamond != null)
                    {
                        secondDiamond.direction = Direction.Down;
                    }
                }
                break;

            case Direction.Down:
                if (firstDiamond.Row != 9)
                {
                    secondDiamond = this[firstDiamond.Column, firstDiamond.Row + 1];
                    if (secondDiamond != null)
                    {
                        secondDiamond.direction = Direction.Up;
                    }
                }
                break;

            case Direction.Left:
                if (firstDiamond.Column != 0)
                {
                    secondDiamond = this[firstDiamond.Column - 1, firstDiamond.Row];
                    if (secondDiamond != null)
                    {
                        secondDiamond.direction = Direction.Right;
                    }
                }
                break;

            case Direction.Right:
                if (firstDiamond.Column != 8)
                {
                    secondDiamond = this[firstDiamond.Column + 1, firstDiamond.Row];
                    if (secondDiamond != null)
                    {
                        secondDiamond.direction = Direction.Left;
                    }
                }
                break;
            }
            return(secondDiamond);
        }
Ejemplo n.º 5
0
        //private void UpdateMatrix()
        //{
        //    foreach (var item in gridGameMain.Children)
        //    {
        //        Diamond dia = (Diamond)item;
        //        diamonds[dia.Column, dia.Row] = dia;
        //    }
        //}

        private void FillNull()
        {
            changedDiamonds = new List <Diamond>();
            for (int i = 0; i <= 8; i++)
            {
                int nullNum = 0;
                int row     = 0;
                for (int j = 0; j <= 9; j++)
                {
                    if (this[i, j] == null)
                    {
                        if (j > row)
                        {
                            row = j;
                        }
                        nullNum++;
                        //todo 填充被消除的图案
                    }
                }
                for (int k = row - nullNum; k >= 0 && nullNum != 0; k--)
                {
                    DoubleAnimation da      = new DoubleAnimation();
                    Diamond         tempdia = this[i, k];
                    Storyboard.SetTarget(da, tempdia.RenderTransform);
                    Storyboard.SetTargetProperty(da, new PropertyPath("Y"));
                    tempdia.Row = tempdia.Row + nullNum;
                    tempdia.RenderTransform.SetValue(TranslateTransform.YProperty, (double)-64 * nullNum);
                    da.To       = 0;
                    da.Duration = new Duration(TimeSpan.FromMilliseconds(300 * nullNum));
                    sbFill.Children.Add(da);
                    changedDiamonds.Add(tempdia);
                }
                for (int l = nullNum - 1; l >= 0 && nullNum != 0; l--)
                {
                    int    randomNum = new Random().Next(0, 16);
                    string imagePath = string.Format("images/{0}.png", randomNum);
                    this[i, l] = new Diamond(imagePath, i, l, randomNum);
                    Diamond tempdia = this[i, l];
                    tempdia.RenderTransform.SetValue(TranslateTransform.YProperty, (double)-64 * nullNum);
                    DoubleAnimation da = new DoubleAnimation();
                    da.Duration = new Duration(TimeSpan.FromMilliseconds(300 * nullNum));
                    da.To       = 0;
                    Storyboard.SetTarget(da, tempdia.RenderTransform);
                    Storyboard.SetTargetProperty(da, new PropertyPath("Y"));
                    sbFill.Children.Add(da);
                    this.gridGameMain.Children.Add(tempdia);
                    changedDiamonds.Add(tempdia);
                }
            }
            sbFill.Begin();
        }
Ejemplo n.º 6
0
        private void InitGame()
        {
            Random r = new Random();

            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    int    randomNum   = r.Next(1, 6);
                    string imagePath   = string.Format("images/{0}.png", randomNum);
                    var    tempDiamond = new Diamond(imagePath, i, j, randomNum);
                    tempDiamond.Column = i; tempDiamond.Row = j;
                    gridGameMain.Children.Add(tempDiamond);
                    tempDiamond.OnTestMode(); //测试状态
                }
            }
        }
Ejemplo n.º 7
0
 private void gridGameMain_MouseMove(object sender, MouseEventArgs e)
 {
     if (e.OriginalSource != null)
     {
         if (e.OriginalSource.GetType() == typeof(SilverlightDiamond.Diamond))
         {
             Diamond movedDiamond = (Diamond)e.OriginalSource;
             if (movedDiamond.direction != Direction.Nothing && movedDiamond.isMouseLeftButtonDown && !AnimationIsPlaying)
             {
                 Diamond secondDiamond = GetDiamondByDirection(movedDiamond);
                 if (secondDiamond != null && !AnimationIsPlaying)
                 {
                     firstDiamond = movedDiamond;
                     bool canChange = CheckAround(secondDiamond, false);
                     AnimationIsPlaying = true;
                     ChangeImage(firstDiamond, secondDiamond, !canChange);
                 }
             }
         }
     }
 }
Ejemplo n.º 8
0
 private void PlayAnimation(Diamond firstDiamond, Diamond secondDiamond, bool goBack)
 {
     if (firstDiamond != secondDiamond)
     {
         UpdateDoubleAnimationByDiamond(daChange1, firstDiamond, 64);
         UpdateDoubleAnimationByDiamond(daChange2, secondDiamond, 64);
         if (goBack)
         {
             sbChangeImage.Completed += sbChangeImage_Completed;
         }
         else
         {
             sbChangeImage.Completed += sbChangeImage_Completed_Success;
         }
         sbChangeImage.Begin();
     }
     else
     {
         AnimationIsPlaying = false;
     }
 }
Ejemplo n.º 9
0
 private void SetDiamondByMatrix(int Column, int Row, Diamond diamondValue)
 {
     gridGameMain.Children[Column * 10 + Row] = diamondValue;
 }
Ejemplo n.º 10
0
 private void SetDiamondByMatrix(int Column, int Row, Diamond diamondValue)
 {
     gridGameMain.Children[Column * 10 + Row] = diamondValue;
 }
Ejemplo n.º 11
0
        private bool CheckAround(Diamond diamond, bool removeNow)
        {
            List<Diamond> removedRowDiamond = new List<Diamond>();
            List<Diamond> removedColumnDiamond = new List<Diamond>();
            removedDiamonds = new List<Diamond>();
            if (firstDiamond.direction != Direction.Up)
            {
                for (int i = diamond.Row + 1; i <= 9; i++)
                {
                    Diamond tempDiamond = this[diamond.Column, i];
                    if (tempDiamond!= null && tempDiamond.Type == firstDiamond.Type)
                    {
                        removedRowDiamond.Add(tempDiamond);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (firstDiamond.direction != Direction.Down)
            {
                for (int i = diamond.Row - 1; i >= 0; i--)
                {
                    Diamond tempDiamond = this[diamond.Column, i];
                    if (tempDiamond != null && tempDiamond.Type == firstDiamond.Type)
                    {
                        removedRowDiamond.Add(tempDiamond);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (firstDiamond.direction != Direction.Left)
            {
                for (int i = diamond.Column + 1; i <= 8; i++)
                {
                    Diamond tempDiamond = this[diamond.Column, i];
                    if (tempDiamond != null && tempDiamond.Type == firstDiamond.Type)
                    {
                        removedColumnDiamond.Add(tempDiamond);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (firstDiamond.direction != Direction.Right)
            {
                for (int i = diamond.Column - 1; i >= 0; i--)
                {
                    Diamond tempDiamond = this[diamond.Column, i];
                    if (tempDiamond != null && tempDiamond.Type == firstDiamond.Type)
                    {
                        removedColumnDiamond.Add(tempDiamond);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            Action<Diamond> callBack = new Action<Diamond>(delegate(Diamond removediamond) {
                if (gridGameMain.Children.Contains(removediamond))
                {
                    removediamond = null;
                } });

            if (removedRowDiamond.Count >= 2 || removedColumnDiamond.Count >= 2)
            {
                if (removeNow)
                {
                    if (removedRowDiamond.Count >= 2)
                    {
                        firstDiamond.Disponse(callBack);
                        foreach (var tempDiamond in removedRowDiamond)
                        {
                            tempDiamond.Disponse(callBack);
                            removedDiamonds.Add(tempDiamond);
                        }
                    }
                    if (removedColumnDiamond.Count >= 2)
                    {
                        firstDiamond.Disponse(callBack);
                        foreach (var tempDiamond in removedColumnDiamond)
                        {
                            tempDiamond.Disponse(callBack);
                            removedDiamonds.Add(tempDiamond);
                        }
                    }
                }
                return true;
            }
            else
            {
                return false;
            }
        }
Ejemplo n.º 12
0
        private void ChangeZIndex(Diamond firstDiamond, Diamond secondDiamond)
        {
            int secDiaZindex = Canvas.GetZIndex(secondDiamond);

            Canvas.SetZIndex(firstDiamond, secDiaZindex + 1);
        }
Ejemplo n.º 13
0
 private Diamond GetDiamondByDirection(Diamond firstDiamond)
 {
     switch (firstDiamond.direction)
     {
         case Direction.Nothing:
             secondDiamond = null;
             break;
         case Direction.Up:
             if (firstDiamond.Row != 0)
             {
                 secondDiamond = this[firstDiamond.Column, firstDiamond.Row - 1];
                 if (secondDiamond != null)
                     secondDiamond.direction = Direction.Down;
             }
             break;
         case Direction.Down:
             if (firstDiamond.Row != 9)
             {
                 secondDiamond = this[firstDiamond.Column, firstDiamond.Row + 1];
                 if (secondDiamond != null)
                     secondDiamond.direction = Direction.Up;
             }
             break;
         case Direction.Left:
             if (firstDiamond.Column != 0)
             {
                 secondDiamond = this[firstDiamond.Column - 1, firstDiamond.Row];
                 if (secondDiamond != null)
                     secondDiamond.direction = Direction.Right;
             }
             break;
         case Direction.Right:
             if (firstDiamond.Column != 8)
             {
                 secondDiamond = this[firstDiamond.Column + 1, firstDiamond.Row];
                 if (secondDiamond != null)
                     secondDiamond.direction = Direction.Left;
             }
             break;
     }
     return secondDiamond;
 }
Ejemplo n.º 14
0
 private void ChangeImage(Diamond firstDiamond, Diamond secondDiamond, bool goBack)
 {
     ChangeZIndex(firstDiamond, secondDiamond);
     PlayAnimation(firstDiamond, secondDiamond, goBack);
 }
Ejemplo n.º 15
0
 private void PlayAnimation(Diamond firstDiamond, Diamond secondDiamond, bool goBack)
 {
     if (firstDiamond != secondDiamond)
     {
         UpdateDoubleAnimationByDiamond(daChange1, firstDiamond, 64);
         UpdateDoubleAnimationByDiamond(daChange2, secondDiamond, 64);
         if (goBack)
         {
             sbChangeImage.Completed += sbChangeImage_Completed;
         }
         else
         {
             sbChangeImage.Completed += sbChangeImage_Completed_Success;
         }
         sbChangeImage.Begin();
     }
     else
     {
         AnimationIsPlaying = false;
     }
 }
Ejemplo n.º 16
0
 private void ChangeImage(Diamond firstDiamond, Diamond secondDiamond, bool goBack)
 {
     ChangeZIndex(firstDiamond, secondDiamond);
     PlayAnimation(firstDiamond, secondDiamond, goBack);
 }
Ejemplo n.º 17
0
        private bool CheckAround(Diamond diamond, bool removeNow)
        {
            List <Diamond> removedRowDiamond    = new List <Diamond>();
            List <Diamond> removedColumnDiamond = new List <Diamond>();

            removedDiamonds = new List <Diamond>();
            if (firstDiamond.direction != Direction.Up)
            {
                for (int i = diamond.Row + 1; i <= 9; i++)
                {
                    Diamond tempDiamond = this[diamond.Column, i];
                    if (tempDiamond != null && tempDiamond.Type == firstDiamond.Type)
                    {
                        removedRowDiamond.Add(tempDiamond);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (firstDiamond.direction != Direction.Down)
            {
                for (int i = diamond.Row - 1; i >= 0; i--)
                {
                    Diamond tempDiamond = this[diamond.Column, i];
                    if (tempDiamond != null && tempDiamond.Type == firstDiamond.Type)
                    {
                        removedRowDiamond.Add(tempDiamond);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (firstDiamond.direction != Direction.Left)
            {
                for (int i = diamond.Column + 1; i <= 8; i++)
                {
                    Diamond tempDiamond = this[diamond.Column, i];
                    if (tempDiamond != null && tempDiamond.Type == firstDiamond.Type)
                    {
                        removedColumnDiamond.Add(tempDiamond);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (firstDiamond.direction != Direction.Right)
            {
                for (int i = diamond.Column - 1; i >= 0; i--)
                {
                    Diamond tempDiamond = this[diamond.Column, i];
                    if (tempDiamond != null && tempDiamond.Type == firstDiamond.Type)
                    {
                        removedColumnDiamond.Add(tempDiamond);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            Action <Diamond> callBack = new Action <Diamond>(delegate(Diamond removediamond) {
                if (gridGameMain.Children.Contains(removediamond))
                {
                    removediamond = null;
                }
            });

            if (removedRowDiamond.Count >= 2 || removedColumnDiamond.Count >= 2)
            {
                if (removeNow)
                {
                    if (removedRowDiamond.Count >= 2)
                    {
                        firstDiamond.Disponse(callBack);
                        foreach (var tempDiamond in removedRowDiamond)
                        {
                            tempDiamond.Disponse(callBack);
                            removedDiamonds.Add(tempDiamond);
                        }
                    }
                    if (removedColumnDiamond.Count >= 2)
                    {
                        firstDiamond.Disponse(callBack);
                        foreach (var tempDiamond in removedColumnDiamond)
                        {
                            tempDiamond.Disponse(callBack);
                            removedDiamonds.Add(tempDiamond);
                        }
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 18
0
 private void UpdateDoubleAnimationByDiamond(DoubleAnimation da, Diamond diamond, double To)
 {
     try
     {
         Storyboard.SetTarget(da, diamond.RenderTransform);
         if (diamond.direction == Direction.Up || diamond.direction == Direction.Down)
         {
             Storyboard.SetTargetProperty(da, new PropertyPath("Y"));
             if (diamond.direction == Direction.Up)
             {
                 da.To = -To;
             }
             else
             {
                 da.To = To;
             }
         }
         if (diamond.direction == Direction.Left || diamond.direction == Direction.Right)
         {
             Storyboard.SetTargetProperty(da, new PropertyPath("X"));
             if (diamond.direction == Direction.Left)
             {
                 da.To = -To;
             }
             else
             {
                 da.To = To;
             }
         }
     }
     catch
     {
     }
 }
Ejemplo n.º 19
0
        //private void UpdateMatrix()
        //{
        //    foreach (var item in gridGameMain.Children)
        //    {
        //        Diamond dia = (Diamond)item;
        //        diamonds[dia.Column, dia.Row] = dia;
        //    }
        //}

        private void FillNull()
        {
            changedDiamonds = new List<Diamond>();
            for (int i = 0; i <= 8; i++)
            {
                int nullNum = 0;
                int row = 0;
                for (int j = 0; j <= 9; j++)
                {
                    if (this[i, j] == null)
                    {
                        if (j > row) row = j;
                        nullNum++;
                        //todo 填充被消除的图案
                    }
                }
                for (int k = row - nullNum; k >=0 && nullNum != 0 ; k--)
                {
                    DoubleAnimation da = new DoubleAnimation();
                    Diamond tempdia = this[i, k];
                    Storyboard.SetTarget(da, tempdia.RenderTransform);
                    Storyboard.SetTargetProperty(da, new PropertyPath("Y"));
                    tempdia.Row = tempdia.Row + nullNum;
                    tempdia.RenderTransform.SetValue(TranslateTransform.YProperty, (double)-64 * nullNum);
                    da.To = 0;
                    da.Duration = new Duration(TimeSpan.FromMilliseconds(300 * nullNum));
                    sbFill.Children.Add(da);
                    changedDiamonds.Add(tempdia);
                }
                for (int l = nullNum - 1; l >= 0 && nullNum != 0; l--)
                {
                    int randomNum = new Random().Next(0, 16);
                    string imagePath = string.Format("images/{0}.png", randomNum);
                    this[i, l] = new Diamond(imagePath, i, l, randomNum);
                    Diamond tempdia = this[i, l] ;
                    tempdia.RenderTransform.SetValue(TranslateTransform.YProperty, (double)-64 * nullNum);
                    DoubleAnimation da = new DoubleAnimation();
                    da.Duration = new Duration(TimeSpan.FromMilliseconds(300 * nullNum));
                    da.To = 0;
                    Storyboard.SetTarget(da, tempdia.RenderTransform);
                    Storyboard.SetTargetProperty(da, new PropertyPath("Y"));
                    sbFill.Children.Add(da);
                    this.gridGameMain.Children.Add(tempdia);
                    changedDiamonds.Add(tempdia);
                }
            }
            sbFill.Begin();
        }
Ejemplo n.º 20
0
 private void ChangeZIndex(Diamond firstDiamond, Diamond secondDiamond)
 {
     int secDiaZindex = Canvas.GetZIndex(secondDiamond);
     Canvas.SetZIndex(firstDiamond, secDiaZindex + 1);
 }
Ejemplo n.º 21
0
        private void InitGame()
        {
            Random r = new Random();
            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    int randomNum = r.Next(1,6);
                    string imagePath = string.Format("images/{0}.png", randomNum);
                    var tempDiamond = new Diamond(imagePath, i, j, randomNum);
                    tempDiamond.Column = i; tempDiamond.Row = j;
                    gridGameMain.Children.Add(tempDiamond);
                    tempDiamond.OnTestMode(); //测试状态
                }
            }

        }