Exemplo n.º 1
0
        public LobbyWindow(MatchDescriptor match)
        {
            this._viewModel = new LobbyViewModel(match);

            InitializeComponent();

            this._viewModel.GameStarted += () => LoadGameUI();
            this._viewModel.GameAborted += () => AbortGame();
            DataContext = this._viewModel;
            this._viewModel.StartPolling();
        }
Exemplo n.º 2
0
        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();
                }
            }
        }
Exemplo n.º 3
0
 internal void SetupGame(MatchDescriptor match)
 {
     this.ID        = match.MatchId;
     this.ViewModel = this.CreateGameViewModel(match);
 }
Exemplo n.º 4
0
 protected abstract ViewModelBase CreateGameViewModel(MatchDescriptor match);
Exemplo n.º 5
0
 public LobbyViewModel(MatchDescriptor match)
 {
     _match     = match;
     GameName   = match.Game;
     PlayerList = new ObservableCollection <Tuple <string, int> >();
 }
Exemplo n.º 6
0
 public TicTacToeViewModel(MatchDescriptor match) : base(match)
 {
     StartPollingState <TicTacToeStateDescriptor, TicTacToeOptionDescriptor>();
 }
Exemplo n.º 7
0
 public CEViewModel(MatchDescriptor match)
     : base(match)
 {
     StartPollingState <CEStateDescriptor, CEOptionDescriptor>();
 }
Exemplo n.º 8
0
 protected override ViewModelBase CreateGameViewModel(MatchDescriptor match)
 {
     _model = new CEViewModel(match);
     return(_model);
 }