示例#1
0
        public MainWindow()
        {
            InitializeComponent();
            maze   = new Grid[MazeWidth, MazeHeight];
            maze1D = new List <Button>();

            //Initialise timer
            Stopwatch = new Stopwatch();

            mazeGenerator = new MazeGenerator(MazeWidth, MazeHeight);

            var verticalStackPanel = new StackPanel();

            verticalStackPanel.Orientation = Orientation.Vertical;

            for (int y = 0; y < MazeHeight; y++)
            {
                var horizontalStackPanel = new StackPanel();
                horizontalStackPanel.Orientation = Orientation.Horizontal;

                for (int x = 0; x < MazeWidth; x++)
                {
                    var button = new Grid();
                    button.Width             = 8;
                    button.Height            = 8;
                    button.PreviewMouseDown += Button_Click;
                    button.Background        = new SolidColorBrush(Colors.Black);
                    horizontalStackPanel.Children.Add(button);
                    maze[x, y] = button;
                }

                verticalStackPanel.Children.Add(horizontalStackPanel);
            }

            MainGrid.Children.Add(verticalStackPanel);

            mazeGenerator.generate();

            timer = new Timer(new TimerCallback((s) =>
            {
                try
                {
                    Dispatcher.Invoke(() => FillPathSquare());
                }
                catch
                {
                }
            }), null, 100, 1);
        }
示例#2
0
        private void Regenerate(object sender, RoutedEventArgs e)
        {
            mazeGenerator = new MazeGenerator(MazeWidth, MazeHeight);
            mazeGenerator.generate();

            var mazeMap = mazeGenerator.GetMaze();

            for (int y = 0; y < MazeHeight; y++)
            {
                for (int x = 0; x < MazeWidth; x++)
                {
                    maze[x, y].Background = new SolidColorBrush(Colors.Black);
                }
            }

            currentDrawMazePosition = 0;
            drawMaze = true;
        }