/// <summary> /// Moves to the GameForm and starts the simulation is all required information is inputted /// </summary> private void StartGame() { // Check if a valid username has been set if (txtUsername.Text == "" || txtUsername.Text.Contains("(") || txtUsername.Text.Contains(")")) { MessageBox.Show("Please enter a valid username."); } // Check if an environment has been selected else if (!manager.IsEnvironmentCreated()) { MessageBox.Show("Please select an environment."); } // Otherwise, can start the game else { // Create the game form GameForm gameForm = new GameForm(manager, txtUsername.Text); //create a new grid for the state manager.CreateGrid(); // Display the new game form this.Hide(); gameForm.ShowDialog(); // Close this form this.Close(); } }
// ************ LOADING ************ // /// <summary> /// Presents a FolderBrowserDialog that allows for the user to select a past state to load. /// </summary> /// <remarks> /// Author: Rudy Ariaz /// </remarks> private void btnLoadState_Click(object sender, EventArgs e) { // Create the browser using (FolderBrowserDialog browser = new FolderBrowserDialog()) { // Set the initial path to the directory with all the past states browser.SelectedPath = Datastore.GeneralStatesDirectoryPath; // Hide the "New Folder" button in the dialog browser.ShowNewFolderButton = false; // Get the result of the selection DialogResult result = browser.ShowDialog(); // Check if there was an error with the selection, if: // A folder was selected // The selected path was empty, or it was out of the past states directory, or // if no subdirectory was selected if (result == DialogResult.OK && (string.IsNullOrWhiteSpace(browser.SelectedPath) || !browser.SelectedPath.Contains(Datastore.GeneralStatesDirectoryPath) || browser.SelectedPath.Length <= Datastore.GeneralStatesDirectoryPath.Length)) { // Show an error message MessageBox.Show("Please select a valid directory within the PastStates directory."); } // Otherwise, if a valid folder was selected: else if (result == DialogResult.OK) { // Load the selected state manager.LoadState(browser.SelectedPath); // Create the game form GameForm gameForm = new GameForm(manager, manager.Username); // Display the new game form gameForm.ShowDialog(); // Close this form this.Close(); } } }