static ViewModelLocator() { #if LOCALTESTMODEON hostCommunicator = new MockHostCommunicator(); var mockHostCommunicator = hostCommunicator as MockHostCommunicator; clientCommunicator = new MockClientCommunicator { Host = mockHostCommunicator }; clientCommunicator2 = new MockClientCommunicator { Host = mockHostCommunicator }; mockHostCommunicator.Client1 = clientCommunicator as MockClientCommunicator; mockHostCommunicator.Client2 = clientCommunicator2 as MockClientCommunicator; #else clientCommunicator = new ClientCommunicator(); hostCommunicator = new HostCommunicator(); #endif }
static ViewModelLocator() { #if LOCALTESTMODEON hostCommunicator = new MockHostCommunicator(); var mockHostCommunicator = hostCommunicator as MockHostCommunicator; clientCommunicator = new MockClientCommunicator { Host = mockHostCommunicator }; clientCommunicator2 = new MockClientCommunicator { Host = mockHostCommunicator }; mockHostCommunicator.Client1 = clientCommunicator as MockClientCommunicator; mockHostCommunicator.Client2 = clientCommunicator2 as MockClientCommunicator; #else clientCommunicator = new ClientCommunicator(); hostCommunicator = new HostCommunicator(); #endif }
public HostViewModel(IGame game, IHostCommunicator hostCommunicator) { if (game == null) { throw new ArgumentNullException("game"); } if (hostCommunicator == null) { throw new ArgumentNullException("hostCommunicator"); } this.Game = game; this.HostCommunicator = hostCommunicator; this.Game.PropertyChanged += (s, e) => { if (e.PropertyName.Equals("SubmittedAnswers")) { this.OnPropertyChanged(nameof(PlayerProgress)); } if (e.PropertyName.Equals("CurrentQuestion") && this.Game.Questions.Last() == this.Game.CurrentQuestion) { this.NextButtonText = "Show results"; } }; this.Game.NewQuestionAvailable += (s, e) => this.HostCommunicator.SendQuestionAsync(e.Question); this.NextButtonText = "Next question"; Func <DispatchedHandler, Task> callOnUiThread = async(handler) => await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, handler); this.HostCommunicator.PlayerJoined += async(s, e) => await callOnUiThread(() => this.Game.AddPlayer(e.PlayerName)); this.HostCommunicator.PlayerDeparted += async(s, e) => await callOnUiThread(() => this.Game.RemovePlayer(e.PlayerName)); this.HostCommunicator.AnswerReceived += async(s, e) => await callOnUiThread(() => this.Game.SubmitAnswer(e.PlayerName, e.AnswerIndex)); this.HostCommunicator.EnterLobbyAsync(); }
public ViewModelLocator() { #if LOCALTESTMODEON hostCommunicator = new MockHostCommunicator(); var mockHostCommunicator = hostCommunicator as MockHostCommunicator; clientCommunicator = new MockClientCommunicator { Host = mockHostCommunicator }; clientCommunicator2 = new MockClientCommunicator { Host = mockHostCommunicator }; mockHostCommunicator.Client1 = clientCommunicator as MockClientCommunicator; mockHostCommunicator.Client2 = clientCommunicator2 as MockClientCommunicator; #else var config = new P2PSession.P2PSessionConfigurationData { multicastIP = "239.7.7.7", multicastPort = "60608", tcpPort = "4400" }; clientCommunicator = new ClientCommunicator(new P2PSessionClient(config)); hostCommunicator = new HostCommunicator(new P2PSessionHost(config)); #endif }
public HostViewModel(IGame game, IHostCommunicator hostCommunicator) { if (game == null) throw new ArgumentNullException("game"); if (hostCommunicator == null) throw new ArgumentNullException("hostCommunicator"); this.Game = game; this.HostCommunicator = hostCommunicator; this.Game.PropertyChanged += (s, e) => { if (e.PropertyName.Equals("SubmittedAnswers")) { this.OnPropertyChanged(nameof(PlayerProgress)); } if (e.PropertyName.Equals("CurrentQuestion") && this.Game.Questions.Last() == this.Game.CurrentQuestion) { this.NextButtonText = "Show results"; } }; this.Game.NewQuestionAvailable += (s, e) => this.HostCommunicator.SendQuestionAsync(e.Question); this.NextButtonText = "Next question"; Func<DispatchedHandler, Task> callOnUiThread = async (handler) => await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, handler); this.HostCommunicator.PlayerJoined += async (s, e) => await callOnUiThread(() => this.Game.AddPlayer(e.PlayerName)); this.HostCommunicator.PlayerDeparted += async (s, e) => await callOnUiThread(() => this.Game.RemovePlayer(e.PlayerName)); this.HostCommunicator.AnswerReceived += async (s, e) => await callOnUiThread(() => this.Game.SubmitAnswer(e.PlayerName, e.AnswerIndex)); this.HostCommunicator.EnterLobbyAsync(); }
public ViewModelLocator() { #if LOCALTESTMODEON hostCommunicator = new MockHostCommunicator(); var mockHostCommunicator = hostCommunicator as MockHostCommunicator; clientCommunicator = new MockClientCommunicator { Host = mockHostCommunicator }; clientCommunicator2 = new MockClientCommunicator { Host = mockHostCommunicator }; mockHostCommunicator.Client1 = clientCommunicator as MockClientCommunicator; mockHostCommunicator.Client2 = clientCommunicator2 as MockClientCommunicator; #else var config = new P2PSession.P2PSessionConfigurationData { multicastIP = "239.7.7.7", multicastPort = "60608", tcpPort = "4400" }; clientCommunicator = new ClientCommunicator(new P2PSessionClient(config)); hostCommunicator = new HostCommunicator(new P2PSessionHost(config)); #endif }