Пример #1
0
        /// <summary>
        /// Loads the previously saved game selected by the user
        /// </summary>
        public override void ButtonClicked()
        {
            saveString = loadDialog.getSaveString();
            gameExists = loadDialog.saveStringAlreadyExists();
            try
            {
                if (!gameExists)
                {
                    DialogResult shouldSave = MessageBox.Show("No saved game by that name was found. Try again?", "Save", MessageBoxButtons.YesNo);
                    if (shouldSave == DialogResult.No)
                    {
                        loadDialog.setDialogDone(true);
                    }
                }
                else
                {
                    string[] linesOfText = ReadTextFile();


                    int.TryParse(LoadNewLineText(linesOfText, 0), out numberOfColumns);
                    int.TryParse(LoadNewLineText(linesOfText, 1), out numberOfRows);
                    containsMine     = LoadBoolArrayFromSpaceTextFixedLength(LoadNewLineText(linesOfText, 2), numberOfColumns, numberOfRows);
                    stateOfMineSpace = LoadEnumArrayFromSpaceTextFixedLength(LoadNewLineText(linesOfText, 3), numberOfColumns, numberOfRows);
                    ObjectController.createGameMapFromLoad(numberOfColumns, numberOfRows, containsMine, stateOfMineSpace);
                    loadDialog.setDialogDone(true);
                    GameMapSender.setExitImmediately(true);
                    GameMapSender.Game.Close();
                    loadDialog.GameFilesForm.Close();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Error encountered while trying to load the file!");
            }
        }
Пример #2
0
        /// <summary>
        /// Overwrites the virtual method that the parent has.
        /// Saves the currently selected save file.
        /// </summary>
        public override void ButtonClicked()
        {
            saveString = saveDialog.getSaveString();
            bool skip = false;

            try
            {
                if (saveDialog.saveStringAlreadyExists())
                {
                    DialogResult shouldSave = MessageBox.Show("Are you sure that you want to overwrite the old save by that name?", "Save", MessageBoxButtons.YesNo);
                    if (shouldSave == DialogResult.No)
                    {
                        skip = true;
                    }
                }
                if (!skip)
                {
                    saveDialog.setDialogDone(true);
                    System.IO.File.WriteAllText(Application.StartupPath + "\\" + saveString + ".txt", "");
                    writeNewLineText(numberOfColumns.ToString());
                    writeNewLineText(numberOfRows.ToString());
                    for (int y = 0; y < numberOfRows; y++)
                    {
                        for (int x = 0; x < numberOfColumns; x++)
                        {
                            if (containsMine[x, y])
                            {
                                writeSpaceText("1");
                            }
                            else
                            {
                                writeSpaceText("0");
                            }
                        }
                    }
                    writeNewLineText("");
                    for (int y = 0; y < numberOfRows; y++)
                    {
                        for (int x = 0; x < numberOfColumns; x++)
                        {
                            int value = Convert.ToInt32(stateOfMineSpace[x, y]);
                            writeSpaceText(value.ToString());
                        }
                    }
                    writeNewLineText("");
                    saveDialog.SaveGameDialogDone();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Error encountered while trying to save the file!");
            }
        }
Пример #3
0
 /// <summary>
 /// This method overwrites the virtual method that the parent has.
 /// This method is used delete the currently selected save file.
 /// </summary>
 public override void ButtonClicked()
 {
     saveString = saveDialog.getSaveString();
     try
     {
         if (saveDialog.saveStringAlreadyExists())
         {
             System.IO.File.Delete(Application.StartupPath + "\\" + saveString + ".txt");
             saveDialog.PopulateSaveList();
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Error encountered while trying to save the file!");
     }
 }