Esempio n. 1
0
        public void TestGameEngine_Leave()
        {
            BlackjackEngine engine =
                new BlackjackEngine();

            BlackjackPlayer player =
                new BlackjackPlayer("Cory");

            BlackjackPlayer player2 =
                new BlackjackPlayer("Bob");

            BlackjackTable table =
                new BlackjackTable(
                    "1",
                    "Yes",
                    null,
                    null);

            BlackjackResponse response1 = engine.Process(
                new BlackjackRequest(
                    player,
                    BlackjackAction.JoinTable,
                    table));


            BlackjackResponse response2 = engine.Process(
                new BlackjackRequest(
                    player2,
                    BlackjackAction.JoinTable,
                    table));


            BlackjackResponse response3 = engine.Process(
                new BlackjackRequest(
                    player,
                    BlackjackAction.LeaveTable,
                    table));

            BlackjackResponse response4 = engine.Process(
                new BlackjackRequest(
                    player2,
                    BlackjackAction.LeaveTable,
                    table));
        }
Esempio n. 2
0
        /// <summary>
        /// Processes the incoming blackjack request.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public BlackjackResponse Process(BlackjackRequest request)
        {
            BlackjackResponse response = null;

            try
            {
                response = _engine.Process(request);
            }
            catch (Exception exception)
            {
                response = new BlackjackResponse(
                    request.Table,
                    BlackjackResult.Failure,
                    exception.Message);

                LogHelper.Instance().Write(
                    "Error processing request: " + toString(request),
                    LogEntrySeverityEnum.Error,
                    exception);
            }

            return(response);
        }
Esempio n. 3
0
        /// <summary>
        /// Processes a BlackjackResponse and updates the form
        /// with the newest info.
        /// </summary>
        /// <param name="response"></param>
        private void processResponse(BlackjackResponse response)
        {
            if (response.Result == BlackjackResult.Success)
            {
                try
                {
                    if (response.Table != null &&
                        response.Table.History.Count > _previousHistory)
                    {
                        _previousHistory = response.Table.History.Count;

                        BlackjackPlayer player =
                            ((BlackjackPlayer)response.Table.Get(new Player(_player)));
                        if (null != player)
                        {
                            refreshListbox(response.Table.History.ToArray(), listBoxHistory);
                            refreshListbox(player.Hand.Cards.ToArray(), listBoxCards);
                            refreshListbox(response.Table.Dealer.Hand.Cards.ToArray(), listBoxDealer);

                            updateLabel(player.Hand.Value.ToString(), labelValue);
                            updateLabel(response.Table.Dealer.Hand.Value.ToString(), labelDealter);

                            if (response.Table.State == TableState.Waiting &&
                                response.Table.Owner.Equals(new Player(_player)))
                            {
                                updateControlEnabled(
                                    buttonHit, false);
                                updateControlEnabled(
                                    buttonStay, false);
                                updateControlEnabled(
                                    buttonStart, true);
                            }
                            else if (response.Table.State == TableState.Stopped)
                            {
                                updateControlEnabled(
                                    buttonHit, false);
                                updateControlEnabled(
                                    buttonStay, false);
                                if (response.Table.Owner.Equals(new Player(_player)))
                                {
                                    updateControlEnabled(
                                        buttonStart, true);
                                }
                                else
                                {
                                    updateControlEnabled(
                                        buttonStart, false);
                                }
                            }
                            else if (player.State == PlayerStateEnum.Turn)
                            {
                                updateControlEnabled(
                                    buttonHit, true);
                                updateControlEnabled(
                                    buttonStay, true);
                                updateControlEnabled(
                                    buttonStart, false);
                            }
                            else
                            {
                                updateControlEnabled(
                                    buttonHit, false);
                                updateControlEnabled(
                                    buttonStay, false);
                                updateControlEnabled(
                                    buttonStart, false);
                            }

                            if (null != player)
                            {
                                updateLabel(player.State.ToString(), labelCurrentState);
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    // Swallow
                }
            }
            if (response.Result == BlackjackResult.Failure)
            {
                throw new Exception(response.Message);
            }
        }