Пример #1
0
        public void UnStick(Puzzel puzzel)
        {
            var maxGroup = (from item in Puzzles
                            orderby item.Group descending
                            select item.Group).FirstOrDefault();

            puzzel.AssignToGroup(maxGroup + 1);
        }
Пример #2
0
        private void Align(Puzzel basePuzzel, Puzzel puzzelToAlign)
        {
            double horizontal = basePuzzel.Location.X - puzzelToAlign.Location.X;
            double vertical   = basePuzzel.Location.Y - puzzelToAlign.Location.Y;
            double span       = _puzzleSize.Width;

            //frame
            if (puzzelToAlign.Location.X < _puzzleSize.Width)
            {
                Move(puzzelToAlign, new Point(0, puzzelToAlign.Location.Y));
            }
            if (puzzelToAlign.Location.Y < _puzzleSize.Height)
            {
                Move(puzzelToAlign, new Point(puzzelToAlign.Location.X, 0));
            }
            //left
            if (puzzelToAlign.Location.X > basePuzzel.Location.X - _puzzleSize.Width - span && puzzelToAlign.Location.X < basePuzzel.Location.X - _puzzleSize.Width + span &&
                puzzelToAlign.Location.Y > basePuzzel.Location.Y - span && puzzelToAlign.Location.Y < basePuzzel.Location.Y + span)
            {
                Move(puzzelToAlign, new Point(basePuzzel.Location.X - _puzzleSize.Width, basePuzzel.Location.Y));
                ChangeGroup(puzzelToAlign, basePuzzel);
            }
            //right
            else if (puzzelToAlign.Location.X > basePuzzel.Location.X + _puzzleSize.Width - span && puzzelToAlign.Location.X < basePuzzel.Location.X + _puzzleSize.Width + span &&
                     puzzelToAlign.Location.Y > basePuzzel.Location.Y - span && puzzelToAlign.Location.Y < basePuzzel.Location.Y + span)
            {
                Move(puzzelToAlign, new Point(basePuzzel.Location.X + _puzzleSize.Width, basePuzzel.Location.Y));
                ChangeGroup(puzzelToAlign, basePuzzel);
            }

            //top
            else if (puzzelToAlign.Location.X > basePuzzel.Location.X - span && puzzelToAlign.Location.X < basePuzzel.Location.X + span &&
                     puzzelToAlign.Location.Y > basePuzzel.Location.Y - _puzzleSize.Height - span && puzzelToAlign.Location.Y < basePuzzel.Location.Y - _puzzleSize.Height + span)
            {
                Move(puzzelToAlign, new Point(basePuzzel.Location.X, basePuzzel.Location.Y - _puzzleSize.Height));
                ChangeGroup(puzzelToAlign, basePuzzel);
            }
            //bottom
            else if (puzzelToAlign.Location.X > basePuzzel.Location.X - span && puzzelToAlign.Location.X < basePuzzel.Location.X + span &&
                     puzzelToAlign.Location.Y > basePuzzel.Location.Y + _puzzleSize.Height - span && puzzelToAlign.Location.Y < basePuzzel.Location.Y + _puzzleSize.Height + span)
            {
                Move(puzzelToAlign, new Point(basePuzzel.Location.X, basePuzzel.Location.Y + _puzzleSize.Height));
                ChangeGroup(puzzelToAlign, basePuzzel);
            }
            else
            {
                puzzelToAlign.AssignToGroup(-1);
            }
        }