Exemplo n.º 1
0
        public void Run()
        {
            while (true)
            {
                int value;
                var res = _io.Ask(FACTOR_QUESTION);
                if (string.IsNullOrEmpty(res))
                {
                    break;
                }

                if (!int.TryParse(res, out value))
                {
                    _io.Write(string.Format(FACTOR_VALIDATION));
                    continue;
                }

                var result = _primeFactorService.Generate(value);
                _io.Write(string.Format(PRIME_FACTORS_FORMAT, string.Join(" ", result)));
                if (TryAskAgain())
                {
                    continue;
                }
                break;
            }
        }
Exemplo n.º 2
0
        public void GamePlay()
        {
            var choice = _iio.Ask("Hit or stay? (Hit = 1, Stay = 0)");

            while (choice != "0" && _stateOfGamePlay)
            {
                var newHitCard     = ShuffledDeck.PopCard();
                var playerIsBusted = Player.Hit(newHitCard);
                _iio.Output("with a hand of: ");
                Player.PrintHandCard();

                if (Player.DetermineBlackjack())
                {
                    GameState = GameState.PlayerWon;
                    _iio.Output("Player has won Blackjack!!! Yay!");
                    _stateOfGamePlay = false;
                }

                if (playerIsBusted)
                {
                    GameState = GameState.DealerWon;
                    _iio.Output("Player is busted. Dealer wins!!");
                    _stateOfGamePlay = false;
                }

                else
                {
                    choice = _iio.Ask("Hit or stay? (Hit = 1, Stay = 0)");
                }
            }

            if (_stateOfGamePlay)
            {
                var dealerIsBusted = Dealer.Play(ShuffledDeck.Cards);
                if (dealerIsBusted)
                {
                    GameState = GameState.PlayerWon;
                    _iio.Output("The dealer has busted. Player is the winner!!");
                    _stateOfGamePlay = false;
                }
                CheckForWinner();
            }
        }