Esempio n. 1
0
        private void Load(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.FileName        = "";
            dlg.DefaultExt      = ".txt";
            dlg.Filter          = "Minesweeper documents (.txt)|*.txt";
            int[,] distribution = null;

            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                // Open document
                string filename = dlg.FileName;
                distribution = SaveAndLoad.Load(filename);
            }
            else
            {
                return;
            }
            int row = distribution.GetLength(0);
            int col = distribution.GetLength(1);

            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    Console.Write(distribution[i, j]);
                }
                Console.WriteLine();
            }
            VM.Restart(distribution);
        }
Esempio n. 2
0
 public MainWindow()
 {
     VM = new MainWindowViewModel();
     SL = new SaveAndLoad();
     InitializeComponent();
     DataContext = VM;
 }
Esempio n. 3
0
        private void Save(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            DateTime time = DateTime.Now;

            dlg.FileName   = "Minesweeper" + time.ToString().Replace(":", "-").Replace(" ", "-").Replace("/", "-");
            dlg.DefaultExt = ".txt";
            dlg.Filter     = "Minesweeper (.txt)|*.txt";


            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                // Save document
                string filename = dlg.FileName;
                SaveAndLoad.Save(VM.Row, VM.Col, VM.distribution, filename);
            }
        }