/// <summary> /// Load the current game state from the given file path /// </summary> /// <param name="filePath"></param> public void LoadGame() { // Show the File Save as dialog and get the target file path OpenFileDialog openDialog = new OpenFileDialog(); openDialog.Title = "Load CSChess file..."; openDialog.Filter = "CSChess File (*.qcf)|*.qcf"; openDialog.RestoreDirectory = true; if (openDialog.ShowDialog() == DialogResult.OK) { ChessGame = new Game(); ChessGame.Reset(); // Reset the game board ParentForm.ChessCaptureBar.Clear(); IsRunning = true; LogCounter = 0; // Handle the events fired by the library ChessGame.ComputerThinking += new ChessLibrary.Game.ChessComputerThinking(ComputerThinking); // Save the file at the given path ChessGame.LoadGame(openDialog.FileName); // Show the player info InitPlayers(); ParentForm.BlackPlayerTime.Text = ChessGame.BlackPlayer.ThinkTime; ParentForm.WhitePlayerTime.Text = ChessGame.WhitePlayer.ThinkTime; // Restore the Log and Capture bar items object[] moves = ChessGame.MoveHistory.ToArray(); for (int i = moves.Length - 1; i >= 0; i--) { Move move = (Move)moves[i]; // Log this user move LogUserMove(move.ToString()); // Add to the capture list if (move.IsCaptureMove()) { ParentForm.ChessCaptureBar.Add(ChessImages.GetImageForPiece(move.CapturedPiece)); } } // Restore the menu state ParentForm.EnableSaveMenu(); ParentForm.SetGamePrefrencesMenu(); RedrawBoard(); // Make the chess board visible on screen NextPlayerTurn(); // When the both players are computer this start the game } }
/// <summary> /// Load the current game state from the given file path /// </summary> /// <param name="filePath"></param> public void LoadGame() { // Show the File Save as dialog and get the target file path OpenFileDialog openDialog = new OpenFileDialog(); openDialog.Title = "Load Quick Chess file..."; openDialog.Filter = "Quick Chess File (*.qcf)|*.qcf"; openDialog.RestoreDirectory = true; if (openDialog.ShowDialog() == DialogResult.OK) { ChessGame = new Game(); ChessGame.Reset(); // Reset the game board IsRunning = true; LogCounter = 0; // Save the file at the given path ChessGame.LoadGame(openDialog.FileName); // Show the player info InitPlayers(); // Restore the Log and Capture bar items object[] moves = ChessGame.MoveHistory.ToArray(); for (int i = moves.Length - 1; i >= 0; i--) { Move move = (Move)moves[i]; // Log this user move LogUserMove(move.ToString()); } // Restore the menu state ParentForm.EnableSaveMenu(); RedrawBoard(); this.result.Clear(); this.result.Push(InitCounter(ChessGame.Board)); this.resultBlack.Clear(); this.resultBlack.Push(InitCounterBlack(ChessGame.Board)); // Make the chess board visible on screen } }