private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e) { if (!GameStarted) { SudokuPuzzle.DisplayActivity("Game not started yet.", true); return; } SudokuPuzzle.SaveGameToDisk(true); }
private void ExitToolStripMenuItem_Click(object sender, EventArgs e) { if (GameStarted) { Visible = false; var dr = ShowDialog(); MessageBox.Show(@"Do you want to save current game?"); if (dr == DialogResult.OK) { SudokuPuzzle.SaveGameToDisk(false); } else if (dr == DialogResult.Cancel) { return; } } Application.Exit(); }
private void OpenToolStripMenuItem_Click(object sender, EventArgs e) { try { if (GameStarted) { var dr = ShowDialog(); if (dr == DialogResult.OK) { SudokuPuzzle.SaveGameToDisk(false); } else if (dr == DialogResult.Cancel) { return; } } } catch (Exception) { Trace.WriteLine(typeof(Exception).ToString()); } // load the game from disk var filter = @"SS files (*.ss)|*.ss|SDO files (*.sdo)|*.sdo|All files (*.*)|*.*"; var dialog = new OpenFileDialog { Filter = filter, FilterIndex = 1, InitialDirectory = InitialDirectory, RestoreDirectory = false }; if (dialog.ShowDialog() == DialogResult.OK) { FileContent = File.ReadAllText(dialog.FileName).Replace("X", "0").Replace("\r", "").Replace("\n", "").Replace(".", "0").Replace("|", "").Replace("-", ""); if (FileContent.Length != 81) { throw new InvalidDataException("Input data was not formatted correctly."); } Text = dialog.FileName; SaveFileName = dialog.FileName; } else { return; } StartNewGame(); // initialize the board var counter = 0; foreach (var row in Enumerable.Range(1, 9)) { foreach (var col in Enumerable.Range(1, 9)) { var i = counter++; var value = int.Parse(FileContent[i].ToString()); SetCell(col, row, value); } } DisplayCandidatesForAllCells(); }