public void GivenANewHostedGameWithPlayers(int playerCount)
        {
            var gameBinding = Binding<GameStateBindings>();
            gameBinding.GivenANewGameWithPlayers(playerCount);

            _gameHost = new LockingGameHost(gameBinding.Game);           

            _clients = new List<GameClient>();
            _notifications = new Dictionary<GameClient, int>();

            foreach(var player in gameBinding.Game.Players)
            {
                var client = new GameClient(player.Id, player.Name);
                _gameHost.RegisterGameClient(client, player);
                _clients.Add(client);
                _notifications[client] = 0;
                client.GameStateUpdates.Subscribe( _ =>
                                                       {                                                           
                                                           _notifications[client] += 1;
                                                       });
            }

            

        }
Exemple #2
0
        public string CreateNewGame(IEnumerable<string> playerNames, int numberOfPlayers, IEnumerable<string> selectedCardNames, bool useProsperity)
        {
            var key = _gameData.Count.ToString();
            var startingConfig = new ChosenStartingConfiguration(numberOfPlayers, selectedCardNames, useProsperity);
            var game = startingConfig.CreateGame(playerNames);

            var host = new LockingGameHost(game);            
            _gameData[key] = new GameData { GameKey = key };

            int aiPlayerCount = 0;
            foreach (var player in game.Players)
            {
                IGameClient client = new GameClient(player.Id, player.Name);

                if (_aiTypeList.Select(x => x.Name).Contains(player.Name))
                {                    
                    var ai = (BaseAIClient) Activator.CreateInstance(_aiTypeList.Single(x => x.Name == player.Name));
                    ai.Attach(client);
                    string newName = string.Format("{0} (Comp {1})", player.Name, ++aiPlayerCount);
                    player.Rename(newName);
                }

                host.RegisterGameClient(client, player);
                _clients[player.Id] = client;
                _gameData[key].Slots[player.Id] = player.Name;
            }

            host.AcceptMessage(new BeginGameMessage());

            return key;
        }    
Exemple #3
0
        private void RunGame(int gameNumber, ChosenStartingConfiguration startingConfig)
        {
            var game = startingConfig.CreateGame(Players.Keys);
            var clients = new List<IGameClient>();

            var host = new LockingGameHost(game);

            foreach (var player in game.Players)
            {
                IGameClient client = new GameClient(player.Id, player.Name);
                clients.Add(client);

                var ai = _aiFactory.Create(Players[player.Name]);
                ai.Attach(client);

                host.RegisterGameClient(client, player);
            }

            host.AcceptMessage(new BeginGameMessage());

            var firstClient = clients.First();

            while (!firstClient.GetGameState().Status.GameIsComplete)
                Thread.Sleep(500);

            var state = firstClient.GetGameState();

            File.WriteAllText(Path.Combine(Name, string.Format("game_{0}.txt", gameNumber)), state.Log);

            _results[gameNumber] = state.Results;            
        }
Exemple #4
0
        public string CreateNewGame(IEnumerable <string> playerNames, int numberOfPlayers, IEnumerable <string> selectedCardNames, bool useProsperity)
        {
            var key            = _gameData.Count.ToString();
            var startingConfig = new ChosenStartingConfiguration(numberOfPlayers, selectedCardNames, useProsperity);
            var game           = startingConfig.CreateGame(playerNames);

            var host = new LockingGameHost(game);

            _gameData[key] = new GameData {
                GameKey = key
            };

            int aiPlayerCount = 0;

            foreach (var player in game.Players)
            {
                IGameClient client = new GameClient(player.Id, player.Name);

                if (_aiTypeList.Select(x => x.Name).Contains(player.Name))
                {
                    var ai = (BaseAIClient)Activator.CreateInstance(_aiTypeList.Single(x => x.Name == player.Name));
                    ai.Attach(client);
                    string newName = string.Format("{0} (Comp {1})", player.Name, ++aiPlayerCount);
                    player.Rename(newName);
                }

                host.RegisterGameClient(client, player);
                _clients[player.Id]             = client;
                _gameData[key].Slots[player.Id] = player.Name;
            }

            host.AcceptMessage(new BeginGameMessage());

            return(key);
        }