public LobbyWindow(MatchDescriptor match) { this._viewModel = new LobbyViewModel(match); InitializeComponent(); this._viewModel.GameStarted += () => LoadGameUI(); this._viewModel.GameAborted += () => AbortGame(); DataContext = this._viewModel; this._viewModel.StartPolling(); }
internal async void StartPolling() { while (true) { if (PollingCancelled) { break; } Stopwatch timer = new Stopwatch(); timer.Start(); IEnumerable <MatchDescriptor> currentStatus = await GameLoader.Instance.LoadMatchesFromServer(true); timer.Stop(); Ping = (int)timer.ElapsedMilliseconds; GameLoader.Instance.Player.Ping = Ping; _match = currentStatus.FirstOrDefault(x => x.MatchId == _match.MatchId); if (_match != null) { MaxPlayers = _match.MaxPlayers; IsGameReady = _match.CurrentPlayers.Length == _match.MaxPlayers; IsHost = (_match.HostPlayer == GameLoader.Instance.Player.Name); CurrentPlayerCount = _match.CurrentPlayers.Length; PlayerList.Clear(); foreach ((string name, int ping) in _match.CurrentPlayers.Zip(_match.CurrentPings, (a, b) => (a, b))) { PlayerList.Add(new Tuple <string, int>(name, ping)); } DisplayText = IsGameReady ? "Game is ready to start!" : "Waiting for players..."; if (_match.Status == "Started") { PollingCancelled = true; if (!IsHost) { GameStarted(); } } await Task.Delay(1000); } else { PollingCancelled = true; GameAborted(); } } }
internal void SetupGame(MatchDescriptor match) { this.ID = match.MatchId; this.ViewModel = this.CreateGameViewModel(match); }
protected abstract ViewModelBase CreateGameViewModel(MatchDescriptor match);
public LobbyViewModel(MatchDescriptor match) { _match = match; GameName = match.Game; PlayerList = new ObservableCollection <Tuple <string, int> >(); }
public TicTacToeViewModel(MatchDescriptor match) : base(match) { StartPollingState <TicTacToeStateDescriptor, TicTacToeOptionDescriptor>(); }
public CEViewModel(MatchDescriptor match) : base(match) { StartPollingState <CEStateDescriptor, CEOptionDescriptor>(); }
protected override ViewModelBase CreateGameViewModel(MatchDescriptor match) { _model = new CEViewModel(match); return(_model); }