コード例 #1
0
        public int AddPlayer(string name, int position)
        {
            if (PlayerBySeat.ContainsKey(position))
            {
                return(-1);
            }
            var player = new PlayerInfo(name, position);
            var id     = IDs.Where(x => !PlayerByID.ContainsKey(x)).FirstOrDefault();

            PlayerByID.Add(id, player);
            PlayerBySeat.Add(position, player);
            return(id);
        }
コード例 #2
0
        public void Start()
        {
            Func <Action, bool> conductBettingRoungAndReportIfRoundIsOver = currentRound =>
            {
                currentRound();
                return(Ready.Count(x => x) < 2);
            };
            Action setReadyPlayers = () =>
            {
                for (int i = 0; i < 10; i++)
                {
                    Ready[i] = PlayerBySeat.ContainsKey(i);
                }
            };

            setReadyPlayers();
            SetInitialRoles();
            while (true)
            {
                CheckWinner();
                if (Count < 2)
                {
                    break;
                }
                Deck.Shuffle();
                TableCards.Clear();
                setReadyPlayers();
                // Цикл раундов пока есть хотя бы 2 игрока
                if (conductBettingRoungAndReportIfRoundIsOver(PreFlop))
                {
                    continue;
                }
                if (conductBettingRoungAndReportIfRoundIsOver(Flop))
                {
                    continue;
                }
                if (conductBettingRoungAndReportIfRoundIsOver(Turn))
                {
                    continue;
                }
                if (conductBettingRoungAndReportIfRoundIsOver(River))
                {
                    continue;
                }
                ShowDown();
                Update();
            }
        }
コード例 #3
0
        public bool RemovePlayer(int playerId)
        {
            if (!PlayerByID.ContainsKey(playerId))
            {
                return(false);
            }
            var playerInfo = PlayerByID[playerId];
            var seat       = playerInfo.Position;

            PlayerBySeat.Remove(seat);
            PlayerByID.Remove(playerId);
            if (Ready[seat])
            {
                Ready[seat] = false;
                Count--;
            }
            return(true);
        }
コード例 #4
0
        public List <string> ListPlayerNames()
        {
            var names = new List <string>();

            for (int i = 0; i < 10; i++)
            {
                if (PlayerBySeat.ContainsKey(i))
                {
                    names.Add(PlayerBySeat[i].Name);
                }
                else
                {
                    names.Add(null);
                }
            }

            return(names);
        }