Exemplo n.º 1
0
        public Form1()
        {
            InitializeComponent();

            bit = new Bitmap(length, length);
            Graphics g = Graphics.FromImage(bit);

            g.Clear(this.BackColor);
            g.DrawRectangle(Pens.SlateGray, new Rectangle(0, 0, length, length));
            g.Dispose();
            textureBrush = new TextureBrush(bit);//使用TextureBrush可以有效减少窗体拉伸时的闪烁

            mapSearch2 = new mapSearch.MapSearch2(areaY / length, areaX / length);

            mapSearch2.setStartPoint(10, 10);
            mapSearch2.setEndPoints(30, 30);
            mapSearch2.setEndPoints(35, 1);
            mapSearch2.setEndPoints(5, 16);

            for (int i = 0; i < 30; i++)
            {
                mapSearch2.setWallPoint(5 + i, 15);
            }
        }
Exemplo n.º 2
0
        /**
         * @param args
         */
        public static void main(String[] args)
        {
            MapSearch2 mSearch = new MapSearch2(100, 100);

            /*		for (int i=0;i<40;i++) {
             *          mSearch.setWallPoint(2,5+i);
             *          mSearch.setWallPoint(4,4+i);
             *      }
             *      mSearch.setWallPoint(2,3);
             *      mSearch.setWallPoint(3,4);
             */
            int ty = 1, tx = 0;
            int tDir = 1;

            while (true)
            {
                if (tDir == 1)
                {
                    mSearch.setWallPoint(ty, tx);
                    if (tx + 2 >= mSearch.lengthX || mSearch.map[ty, tx + 2].wallFlg)
                    {
                        tDir = 2;
                        ty   = ty + 1;
                        if (mSearch.map[ty, tx].wallFlg || mSearch.map[ty + 1, tx].wallFlg)
                        {
                            break;
                        }
                    }
                    else
                    {
                        tx = tx + 1;
                    }
                }
                else if (tDir == 2)
                {
                    mSearch.setWallPoint(ty, tx);
                    if (ty + 2 >= mSearch.lengthY || mSearch.map[ty + 2, tx].wallFlg)
                    {
                        tDir = 3;
                        tx   = tx - 1;
                        if (mSearch.map[ty, tx].wallFlg || mSearch.map[ty, tx - 1].wallFlg)
                        {
                            break;
                        }
                    }
                    else
                    {
                        ty = ty + 1;
                    }
                }
                else if (tDir == 3)
                {
                    mSearch.setWallPoint(ty, tx);
                    if (tx - 2 < 0 || mSearch.map[ty, tx - 2].wallFlg)
                    {
                        tDir = 4;
                        ty   = ty - 1;
                        if (mSearch.map[ty, tx].wallFlg || mSearch.map[ty - 1, tx].wallFlg)
                        {
                            break;
                        }
                    }
                    else
                    {
                        tx = tx - 1;
                    }
                }
                else if (tDir == 4)
                {
                    mSearch.setWallPoint(ty, tx);
                    if (ty - 2 < 0 || mSearch.map[ty - 2, tx].wallFlg)
                    {
                        tDir = 1;
                        tx   = tx + 1;
                        if (mSearch.map[ty, tx].wallFlg || mSearch.map[ty, tx + 1].wallFlg)
                        {
                            break;
                        }
                    }
                    else
                    {
                        ty = ty - 1;
                    }
                }
            }



            // Start point
            int startY = 0;
            int startX = 0;

            mSearch.setStartPoint(startY, startX);

            // End point
            int endY = 50;
            int endX = 48;

            mSearch.setEndPoint(endY, endX);

            //		mSearch.drawMap();
            System.Console.WriteLine("Start time:" + DateTime.Now.ToString());
            for (int aa = 0; aa < 1; aa++)
            {
                mSearch.searchStart();
            }
            System.Console.WriteLine("End time  :" + DateTime.Now.ToString());

            mSearch.drawMap();
        }