Exemplo n.º 1
0
        protected override void OnJoin(GamePeer peer)
        {
            BlackjackPlayer player = playerManager.GetPlayer(peer) as BlackjackPlayer;

            SitInEmptySeat(player);

            NewPlayerJoinEvent newJoin = new NewPlayerJoinEvent();

            newJoin.Actor = player.key.ID;
            newJoin.Money = player.money;
            newJoin.Name  = player.name;
            newJoin.Seat  = player.seat;

            EventData eventData = new EventData(EventCode.PlayerJoin, newJoin);

            BroadcastMessage(peer, eventData, new SendParameters());

            ConfirmJoinResponse joinRes = new ConfirmJoinResponse();

            joinRes.Actor = player.key.ID;
            joinRes.Seat  = player.seat;
            joinRes.Money = player.money;
            ExistingPlayerInfos infos;

            infos.infos = new List <ExistingPlayerInfo>();

            playerManager.ForEach((roomPlayer) =>
            {
                var bRoomPlayer = roomPlayer as BlackjackPlayer;
                if (bRoomPlayer.key.ID == player.key.ID)
                {
                    return;
                }
                ExistingPlayerInfo pInfo;
                pInfo.ID     = bRoomPlayer.key.ID;
                pInfo.Name   = bRoomPlayer.name;
                pInfo.Seat   = bRoomPlayer.seat;
                pInfo.Money  = bRoomPlayer.money;
                pInfo.Bet    = playerBetsDic.ContainsKey(bRoomPlayer) ? playerBetsDic[bRoomPlayer] : new BlackjackBet();
                pInfo.Decks  = player.status == PlayerStatus.Playing ? PacketHelper.Serialize <List <BlackjackCardSet> >(playerCards[bRoomPlayer]) : new byte[] { };
                pInfo.Status = bRoomPlayer.status;

                infos.infos.Add(pInfo);
            });
            joinRes.OtherPlayerInfos = PacketHelper.Serialize <ExistingPlayerInfos>(infos);

            var response = new OperationResponse(CommonOperationCode.ConfirmJoin, joinRes);

            peer.SendOperationResponse(response, new SendParameters());

            if (playerManager.Count == 1)
            {
                ClearGame();
                StartGame();
            }
        }
Exemplo n.º 2
0
        public void BroadcastBet(GamePeer peer, BroadcastBetRequest broadcastBet)
        {
            broadcastBet.Actor = playerManager.GetPlayer(peer).key.ID;
            var eventData = new EventData(EventCode.BlackjackBroadcastBet, broadcastBet);

            lock (syncRoot)
            {
                BroadcastMessage(peer, eventData, new SendParameters());
            }

            var response = new OperationResponse(CommonOperationCode.BlackjackBroadcastBet, new Dictionary <byte, object> {
                { (byte)CommonParameterKey.Success, true }
            });

            peer.SendOperationResponse(response, new SendParameters());
        }
Exemplo n.º 3
0
        public void OnPlayerAction(GamePeer peer, ActionRequest action)
        {
            if (peer.ValidateOperation(action, new SendParameters()) == false)
            {
                return;
            }

            BlackjackPlayer player = playerManager.GetPlayer(peer) as BlackjackPlayer;

            if (player.status != PlayerStatus.Playing)
            {
                return;
            }

            if (playerCards[player][action.DeckIndex].Finished)
            {
                return;
            }

            BlackjackBet bet = playerBetsDic[player];

            ActionEvent actionEvent = new ActionEvent();

            actionEvent.Actor      = player.key.ID;
            actionEvent.ActionType = action.ActionType;
            actionEvent.DeckIndex  = action.DeckIndex;

            switch (action.ActionType)
            {
            case BlackjackActionType.Hit:
                PlayerHit(player, action.DeckIndex);
                FillActionEventDeck(ref actionEvent, player, action.DeckIndex);
                break;

            case BlackjackActionType.Split:
                if (AddBet(player, bet.initialBet) == false)
                {
                    return;
                }
                Card originalDeckCard;
                Card newDeckCard;
                Split(player, action.DeckIndex, out originalDeckCard, out newDeckCard);
                FillActionEventDeck(ref actionEvent, player, action.DeckIndex, playerCards[player].Count - 1);
                break;

            case BlackjackActionType.Stand:
                Finish(player, action.DeckIndex);
                FillActionEventDeck(ref actionEvent, player, action.DeckIndex);
                break;

            case BlackjackActionType.DoubleDown:
                if (AddBet(player, bet.initialBet) == false)
                {
                    return;
                }
                DoubleDown(player, action.DeckIndex);
                PlayerHit(player, action.DeckIndex);
                FillActionEventDeck(ref actionEvent, player, action.DeckIndex);
                break;
            }

            EventData eventData = new EventData(EventCode.BlackjackAction, actionEvent);

            BroadcastMessage(peer, eventData, new SendParameters());

            var response = new OperationResponse(CommonOperationCode.BlackjackAction, actionEvent);

            peer.SendOperationResponse(response, new SendParameters());

            PlayerActionDone(player, action.DeckIndex);
        }