Example #1
0
        }//fallDown

        //tar bort blocken som man håller över och flyttar ner blocken som är över.
        private void figur_Click(object sender, RoutedEventArgs e)
        {
            if (IsHover)
            {
                window.BlockClicks.Visibility = Visibility.Visible;
            }
            List <Rectangle> columRek = new List <Rectangle>();
            rektangelInfo    rekinfo  = new rektangelInfo();

            for (int i = 0; i < que.Count; i++)
            {
                rekinfo = (rektangelInfo)que.Dequeue();
                Brush     color = rekinfo.br;
                Rectangle rekt  = rekinfo.rekt;
                que.Enqueue(rekinfo);
                window.canvas1.Children.Remove(rekt);
            }
            double rekLeft = 0;
            int    queSize = que.Count;

            if (queSize > 2)
            {
                _player.dropBlock();
            }
            while (que.Count != 0)
            {
                for (int i = 0; i < queSize; i++)
                {
                    rekinfo = (rektangelInfo)que.Dequeue();
                    Rectangle rekt = rekinfo.rekt;

                    if (columRek.Count == 0 || rekLeft == Canvas.GetLeft(rekt))
                    {
                        rekLeft = Canvas.GetLeft(rekt);
                        columRek.Add(rekt);
                    }
                    else
                    {
                        que.Enqueue(rekinfo);
                    }
                }
                queSize = que.Count;
                int    columnCount = columRek.Count;
                double bottom      = 0;
                for (int i = 0; i < columnCount; i++)
                {
                    Rectangle tangel = columRek[i];

                    if (bottom < Canvas.GetTop(tangel))
                    {
                        bottom = Canvas.GetTop(tangel);
                    }
                }
                Point pt = new Point(rekLeft + 1, bottom - _rectSize + 1);
                columRek.Clear();
                while (pt.X < maxX && pt.X > minX && pt.Y < maxY && pt.Y > minY)
                {
                    HitTestResult hr = VisualTreeHelper.HitTest(window.canvas1, pt);

                    if (hr.VisualHit is Rectangle)
                    {
                        Rectangle  re = (Rectangle)hr.VisualHit;
                        Storyboard sb = new Storyboard();
                        fallDown(Canvas.GetTop(re), Canvas.GetLeft(re), sb, re, bottom, 0.1);
                        ++_numberOfFalling;
                        sb.Completed += delegate
                        {
                            --_numberOfFalling;
                        };
                        sb.Begin();
                        bottom -= _rectSize;
                        pt.Y   -= _rectSize;
                    }
                    else
                    {
                        pt.Y -= _rectSize;
                    }
                }
            }
            if (IsHover)
            {
                var mChanger = new System.Threading.Thread(new System.Threading.ThreadStart(Blockclickproperly));
                mChanger.Start();
            }
            IsHover = false;
        }//figur_Click
Example #2
0
        //tar bort blocken som man håller över och flyttar ner blocken som är över.
        private void figur_Click(object sender, RoutedEventArgs e)
        {
            if (IsHover)
            {
                window.BlockClicks.Visibility = Visibility.Visible;
                window.Points.Content         = scorePoints(que.Count);
                window.scoreFS.Content        = window.Points.Content;
                double timeTemp = _time;
                _time   += addTime(que.Count);
                timeTemp = _time - timeTemp;
                ShowLblTime(timeTemp);
                updateTime();
            }

            rektangelInfo rekinfo = new rektangelInfo();

            for (int i = 0; i < que.Count; i++)
            {
                rekinfo = (rektangelInfo)que.Dequeue();
                Rectangle rekt = rekinfo.rekt;
                window.canvas1.Children.Remove(rekt);
                que.Enqueue(rekinfo);
            }
            double rekLeft = 0;
            int    queSize = que.Count;

            if (queSize > 2)
            {
                _player.dropBlock();
            }
            List <Rectangle> columRek = new List <Rectangle>();

            while (que.Count != 0)
            {
                for (int i = 0; i < queSize; i++)
                {
                    rekinfo = (rektangelInfo)que.Dequeue();
                    Rectangle rekt = rekinfo.rekt;

                    if (columRek.Count == 0 || rekLeft == Canvas.GetLeft(rekt))
                    {
                        window.canvas1.Children.Remove(rekt);
                        rekLeft = Canvas.GetLeft(rekt);
                        columRek.Add(rekt);
                    }
                    else
                    {
                        que.Enqueue(rekinfo);
                    }
                }
                queSize = que.Count;
                int    columnCount = columRek.Count;
                double bottom      = 0;
                for (int i = 0; i < columnCount; i++)
                {
                    Rectangle tangel = columRek[i];

                    if (bottom < Canvas.GetTop(tangel))
                    {
                        bottom = Canvas.GetTop(tangel);
                    }
                }
                Point pt = new Point(rekLeft + 1, bottom - _rectSize + 1);
                columRek.Clear();
                while (pt.X < maxX && pt.X > minX && pt.Y < maxY && pt.Y > minY)
                {
                    HitTestResult hr = VisualTreeHelper.HitTest(window.canvas1, pt);

                    if (hr.VisualHit is Rectangle)
                    {
                        Rectangle  re = (Rectangle)hr.VisualHit;
                        Storyboard sb = new Storyboard();
                        fallDown(Canvas.GetTop(re), Canvas.GetLeft(re), sb, re, bottom, 0.15);

                        ++_numberOfFalling;

                        sb.Completed += delegate {
                            --_numberOfFalling;
                        };
                        sb.Begin();
                        bottom -= _rectSize;
                        pt.Y   -= _rectSize;
                    }
                    else
                    {
                        pt.Y -= _rectSize;
                    }
                }
                int stepsDown = columnCount;
                for (int i = 0; i < columnCount; i++)
                {
                    _shapeSelected = load_Figures(Convert.ToInt32((pt.X) / _rectSize + 1));
                    window.canvas1.Children.Add(_shapeSelected);
                    Storyboard sb = new Storyboard();
                    animationFigures((_nrOfBlocks + 1) - stepsDown, sb, 0.15);

                    sb.Completed += delegate
                    {
                    };
                    sb.Begin();

                    sb.Begin();

                    stepsDown--;
                }
            }

            if (IsHover)
            {
                var mChanger = new System.Threading.Thread(new System.Threading.ThreadStart(Blockclickproperly));
                mChanger.Start();
            }
            IsHover = false;
        }//figur_Click