Example #1
0
        //private void Timer_Tick(object sender, EventArgs e)
        //{
        //    Random rand = new Random();
        //    int trytime = 0;
        //    int i = rand.Next(lsImgs.Count);

        //    while (lsImgs[i] == null || lsImgs[i].duringAnimation) {
        //        trytime++;
        //        if (trytime > 100) return;
        //        i = rand.Next(lsImgs.Count);
        //    }
        //    trytime = 0;
        //    int j = rand.Next(lsImgs.Count);
        //    while (i == j || lsImgs[j] == null || lsImgs[j].duringAnimation) {
        //        trytime++;
        //        if (trytime > 100) return;
        //        j = rand.Next(lsImgs.Count);
        //    }
        //    String temp = lsImgs[i].imgPath;

        //    lsImgs[i].changeImgSource(lsImgs[j].imgPath, 0, 3000);
        //    lsImgs[j].changeImgSource(temp, 0, 3000);
        //}

        private void InitGrid()
        {
            //clear data
            grid.ColumnDefinitions.Clear();
            grid.RowDefinitions.Clear();
            grid.Children.Clear();

            //calculate size
            gridSize = 4;
            while ((gridSize * gridSize * 3 / 4) < imgSources.Count)
            {
                gridSize += 4;
            }

            //add grid column and row
            for (int i = 0; i < gridSize; i++)
            {
                grid.ColumnDefinitions.Add(new ColumnDefinition());
                grid.RowDefinitions.Add(new RowDefinition());
            }

            //create main image
            mainImg = new UserImg(null, 600);
            mainImg.SetValue(Grid.RowProperty, gridSize / 4);
            mainImg.SetValue(Grid.ColumnProperty, gridSize / 4);
            mainImg.SetValue(Grid.RowSpanProperty, gridSize / 2);
            mainImg.SetValue(Grid.ColumnSpanProperty, gridSize / 2);
            grid.Children.Add(mainImg);

            //fill image to grid
            int count = 0;

            for (int i = 0; i < gridSize; i++)
            {
                for (int j = 0; j < gridSize; j++)
                {
                    if (((i >= gridSize / 4) && (i < gridSize * 3 / 4)) && ((j >= gridSize / 4) && (j < gridSize * 3 / 4)))
                    {
                        lsImgs.Add(null);
                    }
                    else
                    {
                        UserImg item = new UserImg(imgSources[count]);
                        item.SetValue(Grid.RowProperty, i);
                        item.SetValue(Grid.ColumnProperty, j);
                        item.SetValue(Grid.RowSpanProperty, 1);
                        item.SetValue(Grid.ColumnSpanProperty, 1);
                        grid.Children.Add(item);
                        count++;
                        if (count >= imgSources.Count)
                        {
                            count = 0;
                        }
                        lsImgs.Add(item);
                    }
                }
            }
        }
Example #2
0
        private void Awardtimer_Tick(object sender, EventArgs e)
        {
            lsImgs[next].BeginAnimation(UIElement.OpacityProperty, null);

            Awardtimer.Stop();

            luckyImg = new UserImg(lsImgs[next].imgPath, 1000);


            luckyImg.SetValue(Grid.RowProperty, 0);
            luckyImg.SetValue(Grid.ColumnProperty, 0);
            luckyImg.SetValue(Grid.RowSpanProperty, gridSize);
            luckyImg.SetValue(Grid.ColumnSpanProperty, gridSize);
            grid.Children.Add(luckyImg);
        }