Example #1
0
        private void MoveItem(ItemUC4 it, int i, int j)
        {
            ItemUC4 a = new ItemUC4(1);

            a.I               = 1;
            Board[i, j]       = Board[it.I, it.J];
            Board[it.I, it.J] = 0;
            Storyboard      sb = new Storyboard();
            DoubleAnimation da = new DoubleAnimation();

            if (i == it.I)
            {
                da.From = it.J * it.Width;
                da.By   = j * it.Width - da.From;
            }
            else
            {
                da.From = it.I * it.Height;
                da.By   = i * it.Height - da.From;
            }
            da.Duration = new Duration(TimeSpan.FromSeconds(.2));
            sb.Children.Add(da);
            object prop = it.I == i ? Canvas.LeftProperty : Canvas.TopProperty;

            Storyboard.SetTargetProperty(da, new PropertyPath(prop));
            sb.Begin(it, true);
            sb.Completed += new EventHandler(sb_Completed);
            it.I          = i;
            it.J          = j;
        }
Example #2
0
        private void AutoSlideImage()
        {
            Random  rnd = new Random();
            ItemUC4 it  = new ItemUC4(1);
            int     temp;
            int     count;
            bool    flag = true;

            while (flag)
            {
                temp  = 0;
                count = 1;
                for (int k = 0; k < 300; k++)
                {
                    int i = rnd.Next(0, 4);
                    int j = rnd.Next(0, 4);
                    it.I      = i;
                    it.J      = j;
                    it.Width  = 0;
                    it.Height = 0;
                    if (CheckMove(it.I - 1, it.J))
                    {
                        MoveItem(it, it.I - 1, it.J);
                    }
                    else if (CheckMove(it.I, it.J + 1))
                    {
                        MoveItem(it, it.I, it.J + 1);
                    }
                    else if (CheckMove(it.I + 1, it.J))
                    {
                        MoveItem(it, it.I + 1, it.J);
                    }
                    else if (CheckMove(it.I, it.J - 1))
                    {
                        MoveItem(it, it.I, it.J - 1);
                    }
                }

                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        if (Board[i, j] == count)
                        {
                            temp++;
                        }
                        count++;
                    }
                }
                if (temp < Global.level + 4)
                {
                    flag = false;
                    break;
                }
                flag = true;
            }
        }
Example #3
0
        void cnv_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            ItemUC4 it = (ItemUC4)sender;

            if (CheckMove(it.I - 1, it.J))
            {
                MoveItem(it, it.I - 1, it.J);
            }
            else if (CheckMove(it.I, it.J + 1))
            {
                MoveItem(it, it.I, it.J + 1);
            }
            else if (CheckMove(it.I + 1, it.J))
            {
                MoveItem(it, it.I + 1, it.J);
            }
            else if (CheckMove(it.I, it.J - 1))
            {
                MoveItem(it, it.I, it.J - 1);
            }
            if (CheckWin())
            {
                Board[3, 3] = 16;
                ItemUC4 cnv = new ItemUC4(16);
                Canvas.SetTop(cnv, 330);
                Canvas.SetLeft(cnv, 330);
                cnBoard.Children.Add(cnv);
                UCWin uCWin = new UCWin();
                uc.Children.Add(uCWin);
                Uri uri = new Uri("../../Sound/chucmung.mp3", UriKind.Relative);
                mediaPlayer.Open(uri);
                mediaPlayer.Play();
                bantay.Visibility = Visibility.Visible;
                next.Visibility   = Visibility.Visible;
            }
        }
Example #4
0
 private void DrawBord()
 {
     cnBoard.Children.Clear();
     for (int i = 0; i < 4; i++)
     {
         for (int j = 0; j < 4; j++)
         {
             if (Board[i, j] > 0)
             {
                 ItemUC4 cnv = new ItemUC4(Board[i, j])
                 {
                     Width  = cnBoard.Width / 4,
                     Height = cnBoard.Height / 4,
                     I      = i,
                     J      = j
                 };
                 Canvas.SetTop(cnv, i * cnBoard.Height / 4);
                 Canvas.SetLeft(cnv, j * cnBoard.Width / 4);
                 cnBoard.Children.Add(cnv);
                 cnv.MouseLeftButtonUp += new MouseButtonEventHandler(cnv_MouseLeftButtonUp);
             }
         }
     }
 }