コード例 #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();
        }
コード例 #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();
                }
            }
        }
コード例 #3
0
 internal void SetupGame(MatchDescriptor match)
 {
     this.ID        = match.MatchId;
     this.ViewModel = this.CreateGameViewModel(match);
 }
コード例 #4
0
 protected abstract ViewModelBase CreateGameViewModel(MatchDescriptor match);
コード例 #5
0
 public LobbyViewModel(MatchDescriptor match)
 {
     _match     = match;
     GameName   = match.Game;
     PlayerList = new ObservableCollection <Tuple <string, int> >();
 }
コード例 #6
0
 public TicTacToeViewModel(MatchDescriptor match) : base(match)
 {
     StartPollingState <TicTacToeStateDescriptor, TicTacToeOptionDescriptor>();
 }
コード例 #7
0
ファイル: CEViewModel.cs プロジェクト: bsguedes/board-game-ui
 public CEViewModel(MatchDescriptor match)
     : base(match)
 {
     StartPollingState <CEStateDescriptor, CEOptionDescriptor>();
 }
コード例 #8
0
 protected override ViewModelBase CreateGameViewModel(MatchDescriptor match)
 {
     _model = new CEViewModel(match);
     return(_model);
 }