Exemplo n.º 1
0
        protected override void Initialize()
        {
            base.Initialize();

            // Setup controller
            Microsoft.Xna.Framework.Input.Mouse.WindowHandle = Window.Handle;
            IsMouseVisible = true;

            // Create world
            world = new World();
            Viewport vp = _graphicsDeviceManager.GraphicsDevice.Viewport;

            camera = new Camera(ref vp);

            // Load sprites
            spriteBatch = new SpriteBatch(GraphicsDevice);
            Sprites.Load(this);

            // Setup Ui
            ui = new UiManager();

            //regenerate maze window button
            ui.Regenerate.AddClickEvent(() => {
                if (solver != null)
                {
                    solver.Dispose();
                    solver = null;
                }
                World.width  = (ui.WidthSlider.currentValue * 4) + 3;
                World.height = (ui.HeightSlider.currentValue * 4) + 3;



                world.RegenerateMaze();
            });

            // Register step buttons
            ui.Forward.AddClickEvent(() => {
                if (solver != null && !play)
                {
                    solver.Step();
                }
            });


            ui.Play.AddClickEvent(() => {
                play = !play;
            });

            // Register solver button handlers
            ui.WallFollower.AddClickEvent(() => {
                if (solver != null)
                {
                    solver.Dispose();
                }
                solver = new WallFollower(ref world);
                if (play)
                {
                    solver.Start();
                }
            });

            ui.RandomMouser.AddClickEvent(() => {
                if (solver != null)
                {
                    solver.Dispose();
                }
                solver = new RandomMouser(ref world);
                if (play)
                {
                    solver.Start();
                }
            });

            ui.DeadEndFilling.AddClickEvent(() => {
                if (solver != null)
                {
                    solver.Dispose();
                }
                solver = new DeadEndFilling(ref world);
                if (play)
                {
                    solver.Start();
                }
            });

            ui.Recursive.AddClickEvent(() => {
                if (solver != null)
                {
                    solver.Dispose();
                }
                solver = new Recursive(ref world);
                if (play)
                {
                    solver.Start();
                }
            });
        }
Exemplo n.º 2
0
 protected override void UnloadContent()
 {
     spriteBatch.Dispose();
     Sprites.Dispose();
 }