예제 #1
0
 private void BettingStateChange(GameState.Change change)
 {
     switch (change)
     {
         case GameState.Change.Loss:
         case GameState.Change.Bust:
             _inst.PlayerBalance -= _inst.CurrentBet;
             _inst.LastWin = 0;
             break;
         case GameState.Change.Win:
             _inst.PlayerBalance += _inst.CurrentBet * 2;
             _inst.LastWin = _inst.CurrentBet * 2;
             break;
         case GameState.Change.DoubleUp:
             _inst.CurrentBet *= 2;
             break;
         case GameState.Change.Push:
             _inst.LastWin = _inst.CurrentBet;
             _inst.PlayerBalance += _inst.CurrentBet;
             break;
     }
 }
예제 #2
0
        private void State_OnStateChange(GameState.Change change)
        {
            var psum = _cardHandler.PlayerHand.Sum();

            if (change == GameState.Change.Bet)
            {
                _cardHandler.Reset();
                _cardHandler.State.GameEnabled = true;

                var next = _cardHandler.Draw();
                var nxt = _cardHandler.Draw().AsHidden();
                _cardHandler.DealerHand.AddCard(next);
                _cardHandler.DealerHand.AddCard(nxt);
                lblDealerSum.Content = $"Dealer: {_cardHandler.DealerHand.Sum() - nxt.Value}?";

                _cardHandler.PlayerHand.AddCard(_cardHandler.Draw());
                _cardHandler.PlayerHand.AddCard(_cardHandler.Draw());
                btnDoubleUp.IsEnabled = btnHit.IsEnabled = btnStand.IsEnabled = true;
                btnBet.IsEnabled = false;
                lblStatus.Content = "OKAY";
            }
            else if (change == GameState.Change.Hit)
            {
                var card = _cardHandler.Draw();
                _cardHandler.PlayerHand.AddCard(card);
            }
            else if (change == GameState.Change.DoubleUp)
            {
            }
            else if (change == GameState.Change.Split)
            {
            }
            else if (change == GameState.Change.Stand)
            {
                _cardHandler.DealerHand.Show();

                if (psum > 21)
                {
                    _cardHandler.State.InvokeChange(GameState.Change.Bust);
                    return;
                }

                while (_cardHandler.DealerHand.Sum() < 17)
                {
                    _cardHandler.DealerHand.AddCard(_cardHandler.Draw());
                }

                if (psum > _cardHandler.DealerHand.Sum() || _cardHandler.DealerHand.Sum() > 21)
                {
                    _cardHandler.State.InvokeChange(GameState.Change.Win);
                    lblStatus.Content = "WIN";
                }
                else if (psum == _cardHandler.DealerHand.Sum())
                {
                    _cardHandler.State.InvokeChange(GameState.Change.Push);
                    lblStatus.Content = "PUSH";
                }
                else
                {
                    _cardHandler.State.InvokeChange(GameState.Change.Loss);
                    lblStatus.Content = "LOSE";
                }
                btnDoubleUp.IsEnabled = btnHit.IsEnabled = btnStand.IsEnabled = false;
                btnBet.IsEnabled = true;
            }
            else if (change == GameState.Change.Bust)
            {
                _cardHandler.Bust();
                _cardHandler.DealerHand.Show();
                lblStatus.Content = "BUST";
                btnDoubleUp.IsEnabled = btnHit.IsEnabled = btnStand.IsEnabled = false;
                btnBet.IsEnabled = true;
            }
            SetText();
        }