/// <summary>
 /// Shows a blank game screen.
 /// </summary>
 /// <param name="form">This form will be hidden.</param>
 public static void EnterNewPuzzle(Form form)
 {
     form.Hide();
     GameForm gform = new GameForm(new Grid(), false);
     gform.ShowDialog();
     form.Close();
 }
示例#2
0
        /// <summary>
        /// Shows a blank game screen.
        /// </summary>
        /// <param name="form">This form will be hidden.</param>
        public static void EnterNewPuzzle(Form form)
        {
            form.Hide();
            GameForm gform = new GameForm(new Grid(), false);

            gform.ShowDialog();
            form.Close();
        }
 /// <summary>
 /// Shows the dialog for creating a puzzle. May also show the new game screen.
 /// </summary>
 /// <param name="form">This form will be hidden.</param>
 public static void GeneratePuzzle(Form form)
 {
     Cursor.Current = Cursors.WaitCursor;
     DifficultyForm dform = new DifficultyForm();
     Cursor.Current = Cursors.Default;
     dform.ShowDialog();
     if (dform.HasResult)
     {
         form.Hide();
         GameForm gform = new GameForm(dform.Result, true);
         gform.ShowDialog();
         form.Close();
     }
 }
示例#4
0
        /// <summary>
        /// Shows the dialog for creating a puzzle. May also show the new game screen.
        /// </summary>
        /// <param name="form">This form will be hidden.</param>
        public static void GeneratePuzzle(Form form)
        {
            Cursor.Current = Cursors.WaitCursor;
            DifficultyForm dform = new DifficultyForm();

            Cursor.Current = Cursors.Default;
            dform.ShowDialog();
            if (dform.HasResult)
            {
                form.Hide();
                GameForm gform = new GameForm(dform.Result, true);
                gform.ShowDialog();
                form.Close();
            }
        }
        /// <summary>
        /// Loads a game from disk (showing load dialog) and then shows the game form.
        /// </summary>
        /// <param name="form">This form will be hidden.</param>
        public static bool LoadGame(Form form)
        {
            bool result = false;
            File fileOpener = new File();
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "Sudoku Game|*.sud";
            dialog.Title = "Load Game";
            dialog.ShowDialog();

            if (dialog.FileName != "")
            {
                form.Hide();
                Grid newGrid = new Grid();
                fileOpener.ReadFile(newGrid, dialog.FileName);
                GameForm gform = new GameForm(newGrid, true);
                gform.ShowDialog();
                form.Close();
                result = true;
            }
            return result;
        }
示例#6
0
        /// <summary>
        /// Loads a game from disk (showing load dialog) and then shows the game form.
        /// </summary>
        /// <param name="form">This form will be hidden.</param>
        public static bool LoadGame(Form form)
        {
            bool           result     = false;
            File           fileOpener = new File();
            OpenFileDialog dialog     = new OpenFileDialog();

            dialog.Filter = "Sudoku Game|*.sud";
            dialog.Title  = "Load Game";
            dialog.ShowDialog();

            if (dialog.FileName != "")
            {
                form.Hide();
                Grid newGrid = new Grid();
                fileOpener.ReadFile(newGrid, dialog.FileName);
                GameForm gform = new GameForm(newGrid, true);
                gform.ShowDialog();
                form.Close();
                result = true;
            }
            return(result);
        }
示例#7
0
        /// <summary>
        /// When the player transitions from "edit grid" mode to "play this game" mode
        /// </summary>
        internal static void PlayThisPuzzle(Grid oldGrid, Form form)
        {
            // Set all the squares as non-editable
            Grid grid = oldGrid.Copy();

            grid.ForEachSquare((row, col, val) =>
            {
                if (val != 0)
                {
                    grid.SetEditable(false, row, col);
                }
            });

            // Tries to solve the grid. If the grid has no unique solution, warn first.
            Grid copyGrid = grid.Copy(); // yes another copy; the solver will mess with this one.
            bool result   = (new Solver().Solve(copyGrid));

            if (result)
            {
                SaveGame(grid);
                form.Hide();
                GameForm gform = new GameForm(grid, true);
                gform.ShowDialog();
                form.Close();
            }
            else
            {
                if (MessageBox.Show(copyGrid.IsFull()? "This puzzle can be solved in more than one way. Play anyway?" : "This puzzle cannot be solved. Play anyway?", "Unsolvable Puzzle", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    SaveGame(grid);
                    form.Hide();
                    GameForm gform = new GameForm(grid, true);
                    gform.ShowDialog();
                    form.Close();
                }
            }
        }
        /// <summary>
        /// When the player transitions from "edit grid" mode to "play this game" mode
        /// </summary>
        internal static void PlayThisPuzzle(Grid oldGrid, Form form)
        {
            // Set all the squares as non-editable
            Grid grid = oldGrid.Copy();
            grid.ForEachSquare((row, col, val) =>
            {
                if (val != 0)
                {
                    grid.SetEditable(false, row, col);
                }
            });

            // Tries to solve the grid. If the grid has no unique solution, warn first.
            Grid copyGrid = grid.Copy(); // yes another copy; the solver will mess with this one.
            bool result = (new Solver().Solve(copyGrid));
            if (result)
            {
                SaveGame(grid);
                form.Hide();
                GameForm gform = new GameForm(grid, true);
                gform.ShowDialog();
                form.Close();
            }
            else
            {
                if (MessageBox.Show(copyGrid.IsFull()? "This puzzle can be solved in more than one way. Play anyway?" : "This puzzle cannot be solved. Play anyway?", "Unsolvable Puzzle", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    SaveGame(grid);
                    form.Hide();
                    GameForm gform = new GameForm(grid, true);
                    gform.ShowDialog();
                    form.Close();
                }
            }
        }