Esempio n. 1
0
        }//mouseEnter

        private void mouseLeave(object sender, MouseEventArgs e)
        {
            int queee = que.Count;

            for (int i = 0; i < queee; i++)
            {
                rektangelInfo rekinfo = new rektangelInfo();
                rekinfo = (rektangelInfo)que.Dequeue();
                Brush     color = rekinfo.br;
                Rectangle rekt  = rekinfo.rekt;
                rekt.Fill = color;
            }
        }//mouseLeave
        }//checkForNeighbor

        public void connectedColors(ImageBrush pressedColor, double ptX, double ptY, double _rectSize, Queue que)
        {
            Point  pt  = new Point();
            object obj = new object();

            pt.X = ptX;
            pt.Y = ptY;

            if (pt.X < maxX && pt.X > minX && pt.Y < maxY && pt.Y > minY)
            {
                HitTestResult hr = VisualTreeHelper.HitTest(window.canvas1, pt);
                obj = hr.VisualHit;
            }

            if (obj is Rectangle)
            {
                Rectangle  figur              = (Rectangle)obj;
                ImageBrush figurImage         = (ImageBrush)figur.Fill;
                string     pressedImagestring = Convert.ToString(pressedColor.ImageSource);
                string     figurImageString   = Convert.ToString(figurImage.ImageSource);
                if (figurImageString == pressedImagestring)
                {
                    rektangelInfo rekinfo = new rektangelInfo();
                    rekinfo.br   = pressedColor;
                    rekinfo.rekt = figur;
                    que.Enqueue(rekinfo);
                    double top  = Canvas.GetTop(figur);
                    double left = Canvas.GetLeft(figur);
                    string str  = "";
                    str        = figurImageString.Remove(figurImageString.Length - 4, 4) + "H.png";
                    figur.Fill = new ImageBrush(new BitmapImage(new Uri(@str, UriKind.Relative)));
                    connectedColors(pressedColor, pt.X + _rectSize, pt.Y, _rectSize, que);
                    connectedColors(pressedColor, pt.X - _rectSize, pt.Y, _rectSize, que);
                    connectedColors(pressedColor, pt.X, pt.Y + _rectSize, _rectSize, que);
                    connectedColors(pressedColor, pt.X, pt.Y - _rectSize, _rectSize, que);
                }
            }
        }//connectedColors
Esempio n. 3
0
        }//figur_Click

        private void mouseEnter(object sender, MouseEventArgs e)
        {
            IsHover = true;
            Rectangle  entered      = (Rectangle)sender;
            double     top          = Canvas.GetTop(entered);
            double     left         = Canvas.GetLeft(entered);
            ImageBrush enteredImage = (ImageBrush)entered.Fill;

            func.connectedColors(enteredImage, left + _rectSize / 2, top + _rectSize / 2, _rectSize, que);
            if (que.Count < 3)
            {
                object obj   = new object();
                int    queee = que.Count;
                for (int i = 0; i < queee; i++)
                {
                    rektangelInfo rekinfo = new rektangelInfo();
                    rekinfo = (rektangelInfo)que.Dequeue();
                    Brush     color = rekinfo.br;
                    Rectangle rekt  = rekinfo.rekt;
                    rekt.Fill = color;
                    IsHover   = false;
                }
            }
        }//mouseEnter
Esempio n. 4
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
Esempio n. 5
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