コード例 #1
0
 public SBClientModel(SBClient client)
 {
     this.Client        = client;
     this.CurrentGames  = new ObservableCollection <GameInfo>();
     this.PlayersOnline = new ObservableCollection <PlayerInfo>();
     this.Subscribe(client);
 }
コード例 #2
0
        private void Subscribe(SBClient client)
        {
            client.OnAddKnownClient += info => this.Invoke(() => {
                this.PlayersOnline.Add(new PlayerInfo(info.Id, info.Name, info.State));
            });
            client.OnRemoveAllKnownClients += () => this.Invoke(() => {
                this.PlayersOnline.Clear();
            });
            client.OnRemoveKnownClient += id => this.Invoke(() => {
                this.PlayersOnline.Remove(this.PlayersOnline.FirstOrDefault(p => p.Id == id));
            });
            client.OnKnownClientStateUpdate += (id, state) => this.Invoke(() => {
                var c = this.PlayersOnline.FirstOrDefault(p => p.Id == id);
                if (c != null)
                {
                    c.UpdateState(state);
                }
            });

            client.OnNewGame += (gid, ida, idb) => this.Invoke(() => {
                var pa = this.PlayersOnline.FirstOrDefault(p => p.Id == ida);
                var pb = this.PlayersOnline.FirstOrDefault(p => p.Id == idb);
                if (pa != null && pb != null)
                {
                    this.CurrentGames.Add(new GameInfo(gid, pa.Name, pb.Name));
                }
            });
            client.OnUpdateGameScore += (gid, sa, sb) => this.Invoke(() => {
                var c = this.CurrentGames.FirstOrDefault(g => g.Id == gid);
                if (c != null)
                {
                    c.UpdateScores(sa, sb);
                }
            });
            client.OnRemoveGame += gid => this.Invoke(() => {
                this.CurrentGames.Remove(this.CurrentGames.FirstOrDefault(g => g.Id == gid));
            });
        }