コード例 #1
0
ファイル: Game.cs プロジェクト: makalainspire/Programming
        public void Stand()
        {
            if ((this.AllowedActions & GameAction.Stand) != GameAction.Stand)
            {
                // TODO: Add a descriptive error message
                throw new InvalidOperationException();
            }

            while (this.Dealer.Hand.SoftValue < 17)
            {
                this.deck.GiveAdditionalCard(this.Dealer.Hand);
            }

            if (this.Dealer.Hand.TotalValue > 21 || this.Player.Hand.TotalValue > this.Dealer.Hand.TotalValue)
            {
                this.Player.Balance += this.Player.Bet;
                this.LastState = GameState.PlayerWon;
            }
            else if (this.Dealer.Hand.TotalValue == this.Player.Hand.TotalValue)
            {
                this.LastState = GameState.Draw;
            }
            else
            {
                this.Player.Balance -= this.Player.Bet;
                this.LastState = GameState.DealerWon;
            }

            this.Dealer.Hand.Show();
            this.AllowedActions = GameAction.Deal;
        }
コード例 #2
0
ファイル: Game.cs プロジェクト: makalainspire/Programming
        public void Deal()
        {
            if ((this.AllowedActions & GameAction.Deal) != GameAction.Deal)
            {
                // TODO: Add a descriptive error message
                throw new InvalidOperationException();
            }

            this.LastState = GameState.Unknown;
            
            if (this.deck == null)
            {
                this.deck = new Deck();
            }
            else
            {
                this.deck.Populate();
            }

            this.deck.Shuffle();
            this.Dealer.Hand.Clear();
            this.Player.Hand.Clear();

            this.deck.Deal(this.Dealer.Hand);
            this.deck.Deal(this.Player.Hand);

            if (this.Player.Hand.SoftValue == 21)
            {
                if (this.Dealer.Hand.SoftValue == 21)
                {
                    this.LastState = GameState.Draw;
                }
                else
                {
                    this.Player.Balance += this.Player.Bet / 2;
                    this.LastState = GameState.PlayerWon;
                }

                this.Dealer.Hand.Show();
                this.AllowedActions = GameAction.Deal;
            }
            else if (this.Dealer.Hand.TotalValue == 21)
            {
                this.Player.Balance -= this.Player.Bet / 2;
                this.Dealer.Hand.Show();
                this.LastState = GameState.DealerWon;
                this.AllowedActions = GameAction.Deal;
            }
            else
            {
                // TODO: Add support of other actions
                this.AllowedActions = GameAction.Hit | GameAction.Stand;
            }
        }
コード例 #3
0
ファイル: Game.cs プロジェクト: makalainspire/Programming
        public void Hit()
        {
            if ((this.AllowedActions & GameAction.Hit) != GameAction.Hit)
            {
                // TODO: Add a descriptive error message
                throw new InvalidOperationException();
            }

            this.deck.GiveAdditionalCard(this.Player.Hand);

            if (this.Player.Hand.TotalValue > 21)
            {
                this.Player.Balance -= this.Player.Bet;
                this.Dealer.Hand.Show();
                this.LastState = GameState.DealerWon;
                this.AllowedActions = GameAction.Deal;
            }
        }