Exemple #1
0
        /// <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);
        }