public void Save(int diffLevel, CustomGameSize customGameSize) { lastDiffLevel = diffLevel; if (!isLastGameAvailable) { return; } try { using (StreamWriter writer = new StreamWriter(filePath)) { writer.Write("" + lastDiffLevel); if (customGameSize != null) { writer.Write(" " + customGameSize.GetXSize() + " " + customGameSize.GetYSize() + " " + customGameSize.GetMines()); } } } catch { isLastGameAvailable = false; new ErrorMessageForm("Error saving last game data\nGame will start with default difficulty"); } }
private void LoadFile() { try { using (StreamReader reader = new StreamReader(filePath)) { try { string fileLine = reader.ReadLine(); string[] fileLineSplitted = fileLine.Split(null); lastDiffLevel = Convert.ToInt32(fileLineSplitted[0], 10); if (lastDiffLevel == 3) { customGameSize = new CustomGameSize(Convert.ToInt32(fileLineSplitted[1], 10), Convert.ToInt32(fileLineSplitted[2], 10), Convert.ToInt32(fileLineSplitted[3], 10)); } } catch (Exception e) { if (e is FormatException || e is IndexOutOfRangeException) { new ErrorMessageForm("Error loading last game data\nGame will start with default difficulty"); reader.Close(); Save(0, null); } } } } catch { isLastGameAvailable = false; new ErrorMessageForm("Error loading last game data\nGame will start with default difficulty"); } }