Esempio n. 1
0
        public void DownCornerConflict(Point desiredLocation)
        {
            Point cellLocation     = Map.FindCell(globalIndex);
            Point nearCellLocation = Map.FindCell(globalIndex + Map.CountCells);

            if (Map.Table[cellLocation.X, cellLocation.Y].index != globalIndex || Map.Table[nearCellLocation.X, nearCellLocation.Y].index != globalIndex + Map.CountCells)
            {
                Point nearDesiredLocation = GetNeededPosition(globalIndex + Map.CountCells);
                desiredLocation.X++;
                nearDesiredLocation.Y--;
                MoveToDesiredPosition(globalIndex + Map.CountCells, nearDesiredLocation);
                if (Map.Table[nearDesiredLocation.X, nearDesiredLocation.Y + 1].element == null)
                {
                    Map.MoveCell(new Point(nearDesiredLocation.X + 1, nearDesiredLocation.Y + 1));
                }
                cellLocation = Map.FindCell(globalIndex);
                if (nearDesiredLocation.X == cellLocation.X && nearDesiredLocation.Y + 1 == cellLocation.Y)
                {
                    GoNullX(1, new Point(nearDesiredLocation.X, nearDesiredLocation.Y + 1));
                    GoNullY(0, new Point(nearDesiredLocation.X, nearDesiredLocation.Y + 1));
                    MakeCycling(-1, -1, false);
                    MakeCycling(1, 1, false);
                    MoveToDesiredPosition(globalIndex + Map.CountCells, nearDesiredLocation);
                    if (Map.Table[nearDesiredLocation.X, nearDesiredLocation.Y + 1].element == null)
                    {
                        Map.MoveCell(new Point(nearDesiredLocation.X + 1, nearDesiredLocation.Y + 1));
                    }
                }
                MoveToDesiredPosition(globalIndex, desiredLocation);
                GoNullX(0, desiredLocation);
                GoNullY(1, desiredLocation);
                MakeCycling(-1, -1, false);
            }
        }
Esempio n. 2
0
        public void GoNullY(int directionY, Point cellLocation)
        {
            Point nullCell  = Map.FindCell(0);
            int   direction = GetDirection(nullCell.Y, cellLocation.Y + directionY);

            while (nullCell.Y != cellLocation.Y + directionY)
            {
                if ((nullCell.Y + direction == cellLocation.Y && nullCell.X == cellLocation.X) || !CheckOpportunity(new Point(nullCell.X, nullCell.Y + direction)))
                {
                    if (nullCell.X < Map.CountCells)
                    {
                        nullCell.X++;
                    }
                    else
                    {
                        nullCell.X--;
                    }
                }
                else
                {
                    nullCell.Y += direction;
                }
                Map.MoveCell(nullCell);
            }
        }
Esempio n. 3
0
        public void GoNullX(int directionX, Point cellLocation)
        {
            Point nullCell  = Map.FindCell(0);
            int   direction = GetDirection(nullCell.X, cellLocation.X + directionX);

            while (nullCell.X != cellLocation.X + directionX)
            {
                if ((nullCell.X + direction == cellLocation.X && nullCell.Y == cellLocation.Y) || !CheckOpportunity(new Point(nullCell.X + direction, nullCell.Y)))
                {
                    if (nullCell.Y < Map.CountCells)
                    {
                        nullCell.Y++;
                    }
                    else
                    {
                        nullCell.Y--;
                    }
                }
                else
                {
                    nullCell.X += direction;
                }
                Map.MoveCell(nullCell);
            }
        }
Esempio n. 4
0
        public void MoveToDesiredPosition(int index, Point desiredLocation)
        {
            Point cellLocation = Map.FindCell(index);
            int   direction;

            while (desiredLocation != cellLocation)
            {
                direction = GetDirection(cellLocation.X, desiredLocation.X);
                GoNullX(direction, cellLocation);
                if (direction == 0)
                {
                    direction = GetDirection(cellLocation.Y, desiredLocation.Y);
                }
                else
                {
                    direction = 0;
                }
                GoNullY(direction, cellLocation);
                Map.MoveCell(cellLocation);
                cellLocation = Map.FindCell(index);
            }
        }
Esempio n. 5
0
        public void MakeCycling(int directionX, int directionY, bool Cycling) //Cycling = true - по часовой и Cycling = false - против часовой
        {
            Point nullCell = Map.FindCell(0);

            if (Cycling)
            {
                nullCell.Y += directionY;
                Map.MoveCell(new Point(nullCell.X, nullCell.Y));
                nullCell.X += directionX;
                Map.MoveCell(new Point(nullCell.X, nullCell.Y));
                nullCell.Y += directionY * -1;
                Map.MoveCell(new Point(nullCell.X, nullCell.Y));
            }
            else
            {
                nullCell.X += directionX;
                Map.MoveCell(new Point(nullCell.X, nullCell.Y));
                nullCell.Y += directionY;
                Map.MoveCell(new Point(nullCell.X, nullCell.Y));
                nullCell.X += directionX * -1;
                Map.MoveCell(new Point(nullCell.X, nullCell.Y));
            }
        }
Esempio n. 6
0
        protected override void OnMouseClick(MouseEventArgs mevent)
        {
            Point Cell = new Point((Location.X + SizeBarleyBreak) / SizeBarleyBreak, (Location.Y + SizeBarleyBreak) / SizeBarleyBreak);

            Map.MoveCell(Cell);
        }