public int Path_Load(int r, int c, Position End, Position Start)
        {
            int[,] a_map_1 = new int[100, 100];
            Loading_map a_map = new Loading_map("地图01.txt");

            a_map.Loading();
            a_map_1     = a_map.get_map();
            EndPosition = End;
            StartPos    = Start;
            arrMaze     = a_map_1;
            row         = r;
            column      = c;
            point_flag  = 0;
            Page_Load();
            return(WalkLong);
        }
示例#2
0
        private void reSetMap()
        {
            Loading_map loadfile = new Loading_map("地图01.txt");

            loadfile.Loading();
            int[,] other_map = loadfile.get_map();
            for (int k = 0; k < mr; k++)
            {
                for (int j = 0; j < mc; j++)
                {
                    if (other_map[k, j] == 0)
                    {
                        Button     c_btn        = grid.FindName("Button" + k + "_" + j) as Button;
                        ImageBrush berriesBrush = new ImageBrush();
                        berriesBrush.ImageSource =
                            new BitmapImage(
                                new Uri(@"road.jpg", UriKind.Relative)
                                );
                        c_btn.Background = berriesBrush;
                    }
                }
            }
        }
示例#3
0
        public MainWindow()
        {
            InitializeComponent();

            //初始化地图数据
            int         map_row = 0, map_column = 0;
            Loading_map a_map = new Loading_map("地图01.txt");

            a_map.Loading();
            mr = map_row = a_map.getrow();
            mc = map_column = a_map.getcolumn();
            a  = a_map.get_map();
            Console.WriteLine(map_row + "-" + map_column);

            //生成绘制地图表格
            grid     = this.map_grid;
            path_Con = this.path_panel;
            box      = this.start_path;
            for (int i = 0; i < map_row; i++)
            {
                RowDefinition row = new RowDefinition();
                row.Height = new GridLength(1, GridUnitType.Star);
                grid.RowDefinitions.Add(row);
            }
            for (int j = 0; j < map_column; j++)
            {
                ColumnDefinition column = new ColumnDefinition();
                column.Width = new GridLength(1, GridUnitType.Star);
                grid.ColumnDefinitions.Add(column);
            }
            //填充表格
            for (int k = 0; k < map_row; k++)
            {
                for (int j = 0; j < map_column; j++)
                {
                    Button btn = new Button();
                    btn.Content = "";
                    btn.Name    = "Button" + k + "_" + j;
                    grid.RegisterName("Button" + k + "_" + j, btn);
                    btn.Style = (Style)FindResource("Borderless_style");
                    if (a[k, j] == 1)
                    {
                        ImageBrush berriesBrush = new ImageBrush();
                        berriesBrush.ImageSource =
                            new BitmapImage(
                                new Uri(@"tree.jpg", UriKind.Relative)
                                );
                        btn.Background = berriesBrush;
                    }
                    else if (a[k, j] == 0 || a[k, j] == 7)
                    {
                        ImageBrush berriesBrush = new ImageBrush();
                        berriesBrush.ImageSource =
                            new BitmapImage(
                                new Uri(@"road.jpg", UriKind.Relative)
                                );
                        btn.Background = berriesBrush;
                    }
                    else if (a[k, j] == 9)
                    {
                        ImageBrush berriesBrush = new ImageBrush();
                        berriesBrush.ImageSource =
                            new BitmapImage(
                                new Uri(@"house.jpg", UriKind.Relative)
                                );
                        btn.Background = berriesBrush;
                    }
                    else if (a[k, j] == 8)
                    {
                        ImageBrush berriesBrush = new ImageBrush();
                        berriesBrush.ImageSource =
                            new BitmapImage(
                                new Uri(@"men.jpg", UriKind.Relative)
                                );
                        btn.Background = berriesBrush;
                    }
                    grid.Children.Add(btn);
                    Grid.SetRow(btn, k);
                    Grid.SetColumn(btn, j);
                    btn.Click += new RoutedEventHandler(Button_Click);
                }
            }
        }