Exemplo n.º 1
0
        private void MoveItem(ItemUC3 it, int i, int j)
        {
            ItemUC3 a = new ItemUC3(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;
        }
Exemplo n.º 2
0
        private void AutoSlideImage()
        {
            Random  rnd = new Random();
            ItemUC3 it  = new ItemUC3(1);
            int     temp;
            int     count;
            bool    flag = true;

            while (flag)
            {
                temp  = 0;
                count = 1;
                for (int k = 0; k < 200; k++)
                {
                    int i = rnd.Next(0, 3);
                    int j = rnd.Next(0, 3);
                    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 < 3; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        if (Board[i, j] == count)
                        {
                            temp++;
                        }
                        count++;
                    }
                }
                if (temp < Global.level)
                {
                    flag = false;
                    break;
                }
                flag = true;
            }
        }
Exemplo n.º 3
0
        void cnv_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            ItemUC3 it = (ItemUC3)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[2, 2] = 9;
                ItemUC3 cnv = new ItemUC3(9);
                Canvas.SetTop(cnv, 300);
                Canvas.SetLeft(cnv, 300);
                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;
            }
        }
Exemplo n.º 4
0
 private void DrawBord()
 {
     cnBoard.Children.Clear();
     for (int i = 0; i < 3; i++)
     {
         for (int j = 0; j < 3; j++)
         {
             if (Board[i, j] > 0 && Board[i, j] < 9)
             {
                 ItemUC3 cnv = new ItemUC3(Board[i, j])
                 {
                     Width  = cnBoard.Width / 3,
                     Height = cnBoard.Height / 3,
                     I      = i,
                     J      = j
                 };
                 Canvas.SetTop(cnv, i * cnBoard.Height / 3);
                 Canvas.SetLeft(cnv, j * cnBoard.Width / 3);
                 cnBoard.Children.Add(cnv);
                 cnv.MouseLeftButtonUp += new MouseButtonEventHandler(cnv_MouseLeftButtonUp);
             }
         }
     }
 }