예제 #1
0
        private void LoadBoard(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog
            {
                Filter = "Save file |*.othellosave",
                Title  = "Load a save file"
            };

            if (openFileDialog.ShowDialog() == true)
            {
                if (openFileDialog.CheckFileExists)
                {
                    try
                    {
                        SaveDataGame save = BinarySave.ReadFromBinaryFile <SaveDataGame>(openFileDialog.FileName);
                        board     = save.board;
                        timers    = save.timers;
                        whiteTurn = save.isWhite;
                        gameController.SetBoard(board);
                        RefreshUI(board);
                    }
                    catch (Exception) {
                        MessageBox.Show("Invalid file format", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
        }
예제 #2
0
        private void SaveBoard(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog
            {
                Filter = "Save file |*.othellosave",
                Title  = "Load a save file"
            };

            if (saveFileDialog.ShowDialog() == true)
            {
                try
                {
                    SaveDataGame save = new SaveDataGame(board, timers, whiteTurn);
                    BinarySave.WriteToBinaryFile(saveFileDialog.FileName, save);
                }
                catch (Exception) {
                    MessageBox.Show("Can't save here !", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }