Beispiel #1
0
        /// <summary>
        /// Processes a stay request.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private BlackjackResponse processStay(BlackjackRequest request)
        {
            BlackjackTable table = (BlackjackTable)_tables.Get(request.Table);

            if (null == table)
            {
                throw new Exception(
                          "Cannot perform action. Table does not exist.");
            }

            BlackjackPlayer player = (BlackjackPlayer)table.Get(request.Player);

            if (null == player)
            {
                throw new Exception(
                          "Cannot perform action. Player does not exist at table.");
            }

            if (table.State != TableState.Started)
            {
                throw new Exception(
                          "Cannot perform action. Table has not started.");
            }

            if (player.State != PlayerStateEnum.Turn)
            {
                throw new Exception("It is not " + player.Name + " turn.");
            }

            table.AddHistory(
                "Player " + player.Name + " stays.");

            BlackjackResponse response = null;

            if (true == table.IsLastPlayer)
            {
                response = processEvaluate(request);
            }
            else
            {
                table.NextPlayer();

                response = new BlackjackResponse(
                    table,
                    BlackjackResult.Success);
            }

            return(response);
        }
Beispiel #2
0
        /// <summary>
        /// Processes a hit request.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private BlackjackResponse processHit(BlackjackRequest request)
        {
            BlackjackTable table = (BlackjackTable)_tables.Get(request.Table);

            if (null == table)
            {
                throw new Exception(
                          "Cannot perform action. Table does not exist.");
            }

            BlackjackPlayer player = (BlackjackPlayer)table.Get(request.Player);

            if (null == player)
            {
                throw new Exception(
                          "Cannot perform action. Player does not exist at table.");
            }

            if (table.State != TableState.Started)
            {
                throw new Exception(
                          "Cannot perform action. Table has not started.");
            }

            if (player.State != PlayerStateEnum.Turn)
            {
                throw new Exception("It is not " + player.Name + " turn.");
            }

            Card card = table.CurrentDeck.Deal();

            player.Hand.AddCard(card);
            table.AddHistory(
                "Player " + player.Name + " drew a " + card);

            BlackjackResponse response = null;

            if (true == player.Hand.IsBusted)
            {
                table.AddHistory(
                    "Player " + player.Name + " busted.");

                if (true == table.IsLastPlayer)
                {
                    response = processEvaluate(request);
                }
                else
                {
                    table.NextPlayer();

                    response = new BlackjackResponse(
                        table,
                        BlackjackResult.Busted);
                }
            }
            else
            {
                response = new BlackjackResponse(
                    table,
                    BlackjackResult.Success);
            }

            return(response);
        }