Beispiel #1
0
        public void Slide(MoveWay way)
        {
            Point p  = GetEmptySpaceLoc();
            var   tb = tableLayoutPanel1;

            switch (way)
            {
            case MoveWay.Left:
                p.Offset(1, 0);
                break;

            case MoveWay.Right:
                p.Offset(-1, 0);
                break;

            case MoveWay.Up:
                p.Offset(0, 1);
                break;

            case MoveWay.Down:
                p.Offset(0, -1);
                break;
            }

            (tb.GetControlFromPosition(p.X, p.Y) as Square).SlideMove();
        }
        public SolveBox(int order, MoveWay dimension, Color color) : this()
        {
            this.dimension = dimension;
            this.order     = order;

            if (color != null)
            {
                Color = color;
            }
            label1.Text = order.ToString();

            switch (dimension)
            {
            case MoveWay.Left:
                pictureBox1.BackgroundImage = arrows.left;
                break;

            case MoveWay.Right:
                pictureBox1.BackgroundImage = arrows.right;
                break;

            case MoveWay.Up:
                pictureBox1.BackgroundImage = arrows.up;
                break;

            case MoveWay.Down:
                pictureBox1.BackgroundImage = arrows.down;
                break;
            }
        }
Beispiel #3
0
        public static void SlideMove(this Control obje, MoveWay move)
        {
            Size             parentLoc = obje.Parent.Size;
            int              MoveLengt = parentLoc.Width / 3;
            TableLayoutPanel tlp       = obje.Detach() as TableLayoutPanel;
            Point            tempPoint = obje.Location;

            switch (move)
            {
            case MoveWay.Left:
                for (int i = 0; i < MoveLengt; i += speed)
                {
                    Application.DoEvents();
                    Thread.Sleep(SleepInterval);
                    obje.Location = new Point(tempPoint.X - i, tempPoint.Y);
                }

                break;

            case MoveWay.Right:
                for (int i = 0; i < MoveLengt; i += speed)
                {
                    Application.DoEvents();
                    Thread.Sleep(SleepInterval);
                    obje.Location = new Point(tempPoint.X + i, tempPoint.Y);
                }

                break;

            case MoveWay.Up:
                for (int i = 0; i < MoveLengt; i += speed)
                {
                    Application.DoEvents();
                    Thread.Sleep(SleepInterval);
                    obje.Location = new Point(tempPoint.X, tempPoint.Y - i);
                }

                break;

            case MoveWay.Down:

                for (int i = 0; i < MoveLengt; i += speed)
                {
                    Application.DoEvents();
                    Thread.Sleep(SleepInterval);
                    obje.Location = new Point(tempPoint.X, tempPoint.Y + i);
                }

                break;
            }

            obje.Attach(tlp);
        }
Beispiel #4
0
        public static MoveWay ReverseMoveWay(this MoveWay way)
        {
            switch (way)
            {
            case MoveWay.Left:
                return(MoveWay.Right);

            case MoveWay.Right:
                return(MoveWay.Left);

            case MoveWay.Up:
                return(MoveWay.Down);

            case MoveWay.Down:
                return(MoveWay.Up);
            }

            return(0);
        }
Beispiel #5
0
        public static int?[] SimulateSlideMove(this int[] order, MoveWay way)
        {
            int[][] grid = new int[3][];
            grid[0] = new int[3];
            grid[1] = new int[3];
            grid[2] = new int[3];

            Point emptyLoc = Point.Empty;

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    int item = order[i * 3 + j];
                    if (item == 0)
                    {
                        emptyLoc = new Point(i, j);
                    }

                    grid[i][j] = item;
                }
            }

            int temp;

            switch (way)
            {
            case MoveWay.Left:
                if (emptyLoc.Y + 1 > 2)
                {
                    return(null);
                }
                temp = grid[emptyLoc.X][emptyLoc.Y + 1];
                grid[emptyLoc.X][emptyLoc.Y + 1] = 0;
                grid[emptyLoc.X][emptyLoc.Y]     = temp;
                break;

            case MoveWay.Right:
                if (emptyLoc.Y - 1 < 0)
                {
                    return(null);
                }
                temp = grid[emptyLoc.X][emptyLoc.Y - 1];
                grid[emptyLoc.X][emptyLoc.Y - 1] = 0;
                grid[emptyLoc.X][emptyLoc.Y]     = temp;

                break;

            case MoveWay.Up:
                if (emptyLoc.X + 1 > 2)
                {
                    return(null);
                }
                temp = grid[emptyLoc.X + 1][emptyLoc.Y];
                grid[emptyLoc.X + 1][emptyLoc.Y] = 0;
                grid[emptyLoc.X][emptyLoc.Y]     = temp;

                break;

            case MoveWay.Down:
                if (emptyLoc.X - 1 < 0)
                {
                    return(null);
                }
                temp = grid[emptyLoc.X - 1][emptyLoc.Y];
                grid[emptyLoc.X - 1][emptyLoc.Y] = 0;
                grid[emptyLoc.X][emptyLoc.Y]     = temp;

                break;
            }

            int?[] newOrder = new int?[9];
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    // Console.Write((grid[i][j].ToString()== "0" ?" ":grid[i][j].ToString())+" ");
                    newOrder[i * 3 + j] = grid[i][j];
                }

                //OutputDebugString();
            }

            return(newOrder);
        }