Ejemplo n.º 1
0
        /// <summary>
        /// Method used to load the game - called only once (when the user loads the blackjack page for the first time)
        /// </summary>
        private async void LoadGame()
        {
            //boolean variable used to determine if there should be a delay or not
            bool wait = false;

            //if there is a data file
            if (File.Exists($"{_serializer.DirectoryPath}\\{_serializer.FilePath}"))
            {
                //load the game from the data file
                _game.Load(_serializer);

                _uiFinalTextBorder.Visibility = Visibility.Visible;

                //if the player has a name saved
                if (_game.Player.Name != "")
                {
                    //address them by their name
                    _txtDisplayOutcome.Text = $"WELCOME BACK, {_game.Player.Name.ToUpper()}";
                }
                //if the user does not have a name saved
                else
                {
                    //address them and welcome them back, but since there is no name that is all that can be done
                    _txtDisplayOutcome.Text = $"WELCOME BACK";
                }

                //update controls to display loaded information
                _txtNameInput.Text = _game.Player.Name;

                _uiEditProfilePane.IsPaneOpen = false;

                _txtChipCount.Text  = $"CHIP TOTAL: {_game.Player.GameMoney.ToString()}";
                _txtTotalMoney.Text = $"${_game.Player.Money.ToString()}";

                //the program will need to have a delay before the next message to the user
                wait = true;
            }
            //if there is no data file
            else
            {
                //delay
                await Task.Delay(TimeSpan.FromMilliseconds(10));

                //automatically open the pane for the user (they have to get money and buy chips since this is their first time playing
                _uiEditProfilePane.IsPaneOpen = true;

                //edit functionality of certain controls
                _btnAddFunds.IsEnabled     = true;
                _btnAddGameMoney.IsEnabled = false;
            }

            //update the labels (whether the game has been loaded or not) to show the money (cash) and game money (chips) of the user
            _txtGameMoney.Text  = _game.Player.GameMoney.ToString();
            _txtTotalMoney.Text = $"${_game.Player.Money.ToString()}";

            //if the user does not have a name
            if (_game.Player.Name == "")
            {
                //show placeholder text for an example name
                _txtNameInput.PlaceholderText = "Ex: User123";
            }

            //if the player does not have any money
            if (_game.Player.Money == 0)
            {
                //do not let them add any chips
                _btnAddGameMoney.IsEnabled = false;
            }

            //if the player does not have any chips
            if (_game.Player.GameMoney == 0)
            {
                //update the chip stack to make it look empty
                _uiPlayerChips.Stroke = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));
                _uiPlayerChips.Fill   = new SolidColorBrush();
                _txtGameMoney.Text    = "";
            }

            //if a file was loaded from
            if (wait == true)
            {
                //wait five seconds before the next message is shown
                await Task.Delay(TimeSpan.FromMilliseconds(5000));

                //if the player has no chips
                if (_game.Player.GameMoney == 0)
                {
                    //inform them to buy chips from the user menu
                    _txtDisplayOutcome.Text = "CLICK 'USER MENU' TO BUY CHIPS";
                }

                //if the player has chips
                else
                {
                    //inform them to place a bet
                    _txtDisplayOutcome.Text = "CLICK ON A CHIP TO MAKE A BET";
                }
            }

            //if a file was not loaded from
            else
            {
                //ask them to buy chips - if no file was loaded from, a default player is made, meaning they have no chips
                _txtDisplayOutcome.Text = "CLICK 'USER MENU' TO BUY CHIPS";
            }
        }