private void InitGame() { if (NetworkClient != null) { var pkt = NetworkClient.Receive(); Trace.Assert(pkt is ConnectionResponse); if ((pkt as ConnectionResponse).Settings.GameType == GameType.Pk1v1) _game = new Pk1v1Game(); if ((pkt as ConnectionResponse).Settings.GameType == GameType.RoleGame) _game = new RoleGame(); if (pkt is ConnectionResponse) { _game.Settings = ((ConnectionResponse)pkt).Settings; NetworkClient.SelfId = ((ConnectionResponse)pkt).SelfId; } else { return; } } if (hasSeed != null) { _game.RandomGenerator = new Random((int)hasSeed); _game.IsPanorama = true; } Game.CurrentGameOverride = _game; if (_networkClient == null) { _game.Settings = new GameSettings(); _game.Settings.Accounts = new List<Account>(); _game.Settings.NumberOfDefectors = 1; _game.Settings.NumHeroPicks = 3; _game.Settings.DualHeroMode = false; _game.Settings.TotalPlayers = 8; _game.Settings.TimeOutSeconds = 15; for (int i = 0; i < 8; i++) { _game.Settings.Accounts.Add(new Account() { UserName = "******" + i }); } } ClientNetworkProxy activeClientProxy = null; if (NetworkClient != null) { for (int i = 0; i < _game.Settings.TotalPlayers; i++) { Player player = new Player(); player.Id = i; _game.Players.Add(player); } } else { for (int i = 0; i < 8; i++) { Player player = new Player(); player.Id = i; _game.Players.Add(player); } } if (NetworkClient != null) { _game.GameClient = NetworkClient; } else { _game.GlobalProxy = new GlobalDummyProxy(); } GameViewModel gameModel = new GameViewModel(); gameModel.Game = _game; if (NetworkClient != null) { gameModel.MainPlayerSeatNumber = NetworkClient.SelfId >= _game.Players.Count ? 0 : NetworkClient.SelfId; } else { gameModel.MainPlayerSeatNumber = 0; } _game.NotificationProxy = gameView; List<ClientNetworkProxy> inactive = new List<ClientNetworkProxy>(); for (int i = 0; i < _game.Players.Count; i++) { var player = gameModel.PlayerModels[i].Player; if (NetworkClient != null) { var proxy = new ClientNetworkProxy( new AsyncProxyAdapter(gameModel.PlayerModels[i]), NetworkClient); proxy.HostPlayer = player; proxy.TimeOutSeconds = _game.Settings.TimeOutSeconds; if (i == 0) { activeClientProxy = proxy; } else { inactive.Add(proxy); } _game.UiProxies.Add(player, proxy); } else { var proxy = new AsyncProxyAdapter(gameModel.PlayerModels[i]); _game.UiProxies.Add(player, proxy); } } if (NetworkClient != null) { _game.ActiveClientProxy = activeClientProxy; _game.GlobalProxy = new GlobalClientProxy(_game, activeClientProxy, inactive); _game.UpdateUiAttachStatus(); } Application.Current.Dispatcher.Invoke((ThreadStart)delegate() { gameView.DataContext = gameModel; if (BackwardNavigationService != null && !ViewModelBase.IsDetached) { BackwardNavigationService.Navigate(this); BackwardNavigationService = null; } }); _game.Run(); }
public GlobalClientProxy(Game g, ClientNetworkProxy p, List<ClientNetworkProxy> inactive) { game = g; proxy = p; inactiveProxies = inactive; }
public GlobalClientProxy(Game g, ClientNetworkProxy p, List <ClientNetworkProxy> inactive) { game = g; proxy = p; inactiveProxies = inactive; }