Пример #1
0
        /// <summary>
        /// Will stop the AriadneController and de-construct this object.
        /// </summary>
        private void TargetWindowClosing(object sender, FormClosingEventArgs e)
        {
            // When the target window is closed, stop the controller.
            ariadneController.Stop();

            // Discard all member variables.
            this.ariadneController = null;
            this.mazeUserControl   = null;
            this.painter           = null;
        }
Пример #2
0
        private void restart_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("Do you want to restart game?",
                                                      "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result == MessageBoxResult.Yes)
            {
                MazeUserControl.updateToStartPos();
            }
        }
Пример #3
0
        /// <summary>
        /// Creates a ScreenSaverController instance,
        /// draws an initial maze
        /// and starts an AriadneController.
        /// </summary>
        /// <param name="windowHandleArg">The MazePainter will draw on this window.</param>
        /// <remarks>
        /// If this is not the primary screen, no cotroller is started,
        /// the application will terminate and the screen will stay blank.
        /// </remarks>
        public ScreenSaverController(string windowHandleArg)
        {
            #region Evaluate the given window's properties.
            var windowHandle    = (IntPtr)UInt32.Parse(windowHandleArg);
            var targetGraphics  = Graphics.FromHwnd(windowHandle);
            var targetRectangle = Platform.GetClientRectangle(windowHandle);
            //Log.WriteLine("targetRectangle = " + targetRectangle, true); // {X=0,Y=0,Width=1366,Height=768}
            #endregion

#if true
            #region Blank secondary screen(s).
            // ... because more than one of these mazes is just too distracting.  :-)
            if (!IsOnPrimaryScreen(windowHandle))
            {
                // We don't have to do anything, really.
                // xscreensaver has given us a blank (black) window and we may
                // terminate the application
                //Log.WriteLine("Goodbye on " + targetRectangle, true);
                //Application.Run();
                Application.Exit();
            }
            #endregion
#endif

            // Create an ImageLoader, now that it is clear that we will need it.
            Directory.ResultValidForSeconds = -1;
            var imageLoader = ImageLoader.GetScreenSaverImageLoader(Screen.PrimaryScreen.Bounds);

            #region Create a MazePainter.
            this.painter = new MazePainter(targetGraphics, targetRectangle, this as IMazePainterClient);
            #endregion

            #region Create a MazeUserControl.
            this.mazeUserControl             = new MazeUserControl(painter, targetRectangle.Size);
            this.mazeUserControl.ImageLoader = imageLoader;
            this.mazeUserControl.MazeForm    = this;
            #endregion

            #region Apply some registered options.
            if (RegisteredOptions.GetBoolSetting(RegisteredOptions.OPT_PAINT_ALL_WALLS) == false)
            {
                painter.RandomizeWallVisibility = true;
            }
            ContourImage.DisplayProcessedImage = RegisteredOptions.GetBoolSetting(RegisteredOptions.OPT_IMAGE_SUBTRACT_BACKGROUND);

            // Load background images.
            if (RegisteredOptions.GetBoolSetting(RegisteredOptions.OPT_BACKGROUND_IMAGES))
            {
                string imageFolder = RegisteredOptions.GetStringSetting(RegisteredOptions.OPT_BACKGROUND_IMAGE_FOLDER);
                if (imageFolder == "")
                {
                    imageFolder = RegisteredOptions.GetStringSetting(RegisteredOptions.OPT_IMAGE_FOLDER);
                }
                int percentage = ((RegisteredOptions.GetIntSetting(RegisteredOptions.OPT_IMAGE_NUMBER) > 0) ? 20 : 100);
                painter.CreateBackgroundImageLoader(imageFolder, percentage);
            }

            if (RegisteredOptions.GetBoolSetting(RegisteredOptions.OPT_SHOW_DETAILS_BOX))
            {
                this.infoPanelPainter = new InfoPanelPainter(painter);
            }
            #endregion

            // Create and display the first maze.
            this.OnNew(null, null);

            #region Create and start an AriadneController.
            SolverController controller = new SolverController(this, painter, null);
            this.ariadneController       = new AriadneController(this, controller);
            ariadneController.RepeatMode = true;
            ariadneController.Start();
            #endregion
        }
Пример #4
0
        private void solveMaze_Click(object sender, RoutedEventArgs e)
        {
            string sol = vm.solveCommand();

            MazeUserControl.SolveAnimation(sol);
        }