/// <summary> /// Shows the open dialog to load a game /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OpenCommandExecuted(object sender, ExecutedRoutedEventArgs e) { OpenFileDialog openDialog = new OpenFileDialog(); openDialog.Filter = "Arc Othello files (*.arcgh)|*.arcgh|All files (*.*)|*.*"; if (openDialog.ShowDialog() == true) { try { using (Stream stream = File.Open(openDialog.FileName, FileMode.Open)) { BinaryFormatter binaryFormatter = new BinaryFormatter(); GameWithBoardInItsName unserializedGame = (GameWithBoardInItsName)binaryFormatter.Deserialize(stream); unserializedGame.SetViews(this.boardView, this); this.game = unserializedGame; this.DataContext = this.game; game.StartGame(); } } catch (IOException exception) { MessageBox.Show($"Unable to load the game : {exception.Message}", "Load file error", MessageBoxButton.OK, MessageBoxImage.Error); } } }
/// <summary> /// Creates a new game object and passes the board's display to it /// </summary> public void CreateGame() { this.game = new GameWithBoardInItsName(boardView, this); this.DataContext = game; game.StartGame(); }