コード例 #1
0
        public void CycleActivePlayer()
        {
            // Cycle to the next active player that hasn't folded.
            do
            {
                _activePlayerIndex = _activePlayerIndex + 1 < Players.Count ? ++_activePlayerIndex : 0;
            }while (ActivePlayer.HasFolded);

            foreach (var(id, socket) in _server.UserIdToSockets)
            {
                var markActivePacket = new MarkActivePlayer
                {
                    PacketId    = 4,
                    UserId      = ActivePlayer.Id,
                    HighestBid  = _lastBet,
                    PersonalBid = _playerBets[id]
                };
                socket.Send(JsonConvert.SerializeObject(markActivePacket));
            }

            // This conditional checks if the action has gotten back to the person
            // who originally raised. That player isn't allow to raise again and
            // the game immediately proceedes to the next card.
            if (_lastRaisedId == ActivePlayer.Id)
            {
                DetermineNextCardAction();
            }
        }
コード例 #2
0
        /// <summary>
        /// Starts a new hand of the game.
        /// </summary>
        public void StartGame()
        {
            _playerBets = Players.ToDictionary(p => p.Id, p => 0);
            // Reset state of the game
            _cardIndex = 0;
            _deck.Reset();
            foreach (var player in Players)
            {
                player.HasFolded = false;
                player.EmptyHand();
            }
            GameInProgress = true;

            // Deal 2 cards to each player
            foreach (var player in Players)
            {
                player.GiveCard(_deck.DrawCard());
            }
            foreach (var player in Players)
            {
                player.GiveCard(_deck.DrawCard());
            }

            // Send network traffic
            foreach (var player in Players)
            {
                var socket            = _server.UserIdToSockets[player.Id];
                var initialGamePacket = new InitialGameStatePacket
                {
                    PacketId     = 1,
                    InitialChips = player.Chips,
                    Rank1        = player.CardInSpot(0).Rank,
                    Rank2        = player.CardInSpot(1).Rank,
                    Suit1        = (char)player.CardInSpot(0).Suit,
                    Suit2        = (char)player.CardInSpot(1).Suit,
                    Pot          = Pot,
                    NumPlayers   = (byte)(Players.Count - 1),
                    PlayersChips = Players.Where(p => p.Id != player.Id).Select(p => p.Chips).ToArray(),
                    PlayerIds    = Players.Where(p => p.Id != player.Id).Select(p => p.Id).ToArray()
                };

                socket.Send(JsonConvert.SerializeObject(initialGamePacket));
            }

            // Assign a player the active role.
            _activePlayerIndex = 0;
            var markActivePacket = new MarkActivePlayer
            {
                PacketId = 4,
                UserId   = ActivePlayer.Id
            };

            _server.BroadcastMessage(JsonConvert.SerializeObject(markActivePacket));
        }