コード例 #1
0
        public IPlayer Start()
        {
            var playerNames = this.allPlayers.Select(x => x.Name).ToList().AsReadOnly();

            foreach (var player in this.allPlayers)
            {
                player.StartGame(new StartGameContext(playerNames, this.initialMoney));
            }

            // While at least two players have money
            while (this.allPlayers.Count(x => x.PlayerMoney.Money > 0) > 1)
            {
                this.HandsPlayed++;

                // Every 10 hands the blind increases
                var smallBlind = SmallBlinds[(this.HandsPlayed - 1) / 10];

                // Rotate players
                IHandLogic hand = this.HandsPlayed % 2 == 1
                               ? new TwoPlayersHandLogic(new[] { this.firstPlayer, this.secondPlayer }, this.HandsPlayed, smallBlind)
                               : new TwoPlayersHandLogic(new[] { this.secondPlayer, this.firstPlayer }, this.HandsPlayed, smallBlind);

                hand.Play();
            }

            var winner = this.allPlayers.FirstOrDefault(x => x.PlayerMoney.Money > 0);

            foreach (var player in this.allPlayers)
            {
                player.EndGame(new EndGameContext(winner.Name));
            }

            return(winner);
        }
コード例 #2
0
        public IPlayer Start()
        {
            Console.WriteLine("Game started....");
            var allRelayConnections = (from current in NetworkComms.GetExistingConnection() where current != null select current).ToArray();

            foreach (var relayConnection in allRelayConnections)
            {
                relayConnection.SendObject("Message", "Game started...");
            }
            List <string> playerNames = this.allPlayers.Select(x => x.Name).ToList();

            foreach (InternalPlayer player in this.allPlayers)
            {
                StartGameContext StartGameContext = new StartGameContext(playerNames, this.initialMoney);
                player.StartGame(StartGameContext);
                player.Connection.SendObject("StartGameContext", StartGameContext);
            }

            while (this.allPlayers.Count(x => x.PlayerMoney.Money > 0) > 1)
            {
                var smallBlind = SmallBlinds[(this.HandsPlayed) / 10];
                this.HandsPlayed++;
                IHandLogic hand = this.HandsPlayed % 2 == 1
                               ? new TwoPlayersHandLogic(new[] { this.firstPlayer, this.secondPlayer }, this.HandsPlayed, smallBlind)
                               : new TwoPlayersHandLogic(new[] { this.secondPlayer, this.firstPlayer }, this.HandsPlayed, smallBlind);

                hand.Play();
            }

            var winner = this.allPlayers.FirstOrDefault(x => x.PlayerMoney.Money > 0);

            foreach (var player in this.allPlayers)
            {
                EndGameContext EndGameContext = new EndGameContext(winner.Name);
                player.EndGame(EndGameContext);
                player.Connection.SendObject("EndGameContext", EndGameContext);
            }

            return(winner);
        }