/// <summary> /// This event is fired when the 'SaveButton' is clicked. /// </summary> private void SaveButton_Click(object sender, EventArgs e) { // Capture the Game Manager from this form this.GameManager = CaptureGameManager(); // If the GameManager object exists (should always be true) if (this.HasGameManager) { // if the values needs to be saved on this computer if (gameManager.HouseRules.SaveSettingsOnThisComputer) { // The gameManager needs to be converted to a SecureUserData (ApplicationSettings) object. SecureUserData security = SecureUserDataFactory.Convert(gameManager); // If the security object exists if (NullHelper.Exists(security)) { // set the LastSavedDate security.LastSavedDate = DateTime.Now; // save the values in the settings security.Save(); } } // The user did not cancel this.UserCancelled = false; // Close this form this.Close(); } }
/// <summary> /// This method returns the GameManager. It first attempts to load the values from the settings /// and if not found the default GameManager.Options and GameManager.Players are created. /// </summary> private GameManager LoadGameManager() { // initial value GameManager gameManager = null; // local so the Settings file only has to be loaded once SecureUserData security = new SecureUserData(); // this is used during development so everything default is restored, this has to be taken out or commented out // security.LastSavedDate = new DateTime(1900, 1, 1); // save (this needs to be taken out or commented out also) // security.Save(); // We must load our five PlayerControls List <BlackJackPlayerControl> playerControls = GetPlayerControls(); // if the security object has a LastSavedDate we can load a GameManager from it if (security.HasLastSavedDate) { // convert the settings to a gameManager object gameManager = SecureUserDataFactory.Export(security, playerControls, this); } else { // Create a new instance of a 'GameManager' object. gameManager = new GameManager(NumericHelper.ParseInteger(Properties.Resources.TimesToShuffle, 0, -1), this); // Now we must load the Options and Players from the Settings gameManager.HouseRules = Options.CreateDefault(); // Load the players from the Settings or create them gameManager.Players = CreateDefaultPlayers(gameManager.HouseRules); } //// Create a new instance of an 'OptionsForm' object. OptionsForm optionsForm = new OptionsForm(this); // Setup the form optionsForm.Setup(gameManager); //// Show the dialog optionsForm.ShowDialog(); // if the user did not cancel if (!optionsForm.UserCancelled) { // set the return value this.GameManager = optionsForm.GameManager; } else { // if the GameManager does not exist if (!this.HasGameManager) { // Close this app Environment.Exit(0); } } // return value return(gameManager); }