void StartGame(List<PlayerConnection> connections, List<PlayerInfo> players, List<DeckItem> decks, string[] passwords, GameType gameType, bool modal) { List<PlayerAccountData> allPlayers = new List<PlayerAccountData>(); for(int i = 0; i < players.Count; i++) allPlayers.Add(new PlayerAccountData() { Info = players[i], Password = passwords[i], Deck = decks[i] }); var gameModel = new GameModel(logicStarter.GameItem); var gameView = logicStarter.ViewFactory.CreateGameView(); //using(GameCommandHandler gameCommandHandler = new GameCommandHandler(gameModel, allPlayers.First().Player.UniqueID)) //{ GameCommandHandler gameCommandHandler = new GameCommandHandler(gameModel, allPlayers.First().Info.NickName, logicStarter.ServicesProvider); for(int i = 0; i < connections.Count; i++) gameCommandHandler.AddChannel(connections[i].NetClient, players[i + 1].NickName); var gameController = new GameController(gameCommandHandler, gameModel, gameView, allPlayers, gameType, logicStarter.ServicesProvider, true); gameController.ShowOptionsRequested += new EventHandler(gameController_ShowOptionsRequested); if(modal) gameView.ShowModal(); else gameView.Show(); //} }
void StartGame(List<PlayerAccountData> players, GameModel gameModel, GameType gameType) { bool savedGame = gameModel != null; if(savedGame) gameModel.Console.Messages.Clear(); // clients must not see saved server's log else gameModel = new GameModel(gameItem); bool exitGame = false; while(!exitGame) { var gameView = viewFactory.CreateGameView(); using(var commandHandler = new GameCommandHandler(gameModel, players.First().Info.NickName, servicesProvider)) { foreach(var player in players.Where(e => e.Channel != null)) commandHandler.AddChannel(player.Channel, player.Info.NickName); var gameController = new GameController(commandHandler, gameModel, gameView, players, gameType, servicesProvider, !savedGame); gameController.ShowOptionsRequested += new EventHandler(gameController_ShowOptionsRequested); gameView.ShowModal(); } exitGame = !gameModel.IsRestartNotified; if(!exitGame) { players = players.Where(e => gameModel.Players.Any(p => p.Key == e.Info.NickName)).ToList(); exitGame = RunRestartGame(players, gameType); if(!exitGame) { gameModel = new GameModel(gameItem); savedGame = false; } } } }