private void ListendForCommand() { while (client.Connected) { string data = clientIO.ReadData(); string[] command = data.Split(','); if (command[0] == "plist.add") { Dispatcher.BeginInvoke((Action)(() => PlayerList.Items.Add(command[1]))); } if (command[0] == "plist.sing") { for (int i = 1; i < command.Length - 1; i++) { Dispatcher.Invoke((Action)(() => PlayerList.Items.Add(command[i]))); } } if (command[0] == "plist.del") { int i = 0; foreach (var item in PlayerList.Items) { if (PlayerList.Items[i].Equals(command[1])) { Dispatcher.Invoke(() => PlayerList.Items.RemoveAt(i)); break; } i++; } } // play,true,nick if (command[0] == "play") { string Ynick = null; Dispatcher.Invoke((Action)(() => Ynick = NickBox.Text)); bool YP1 = Convert.ToBoolean(command[1]); clientIO.SendData("disc," + Ynick); Dispatcher.Invoke((Action)(() => game = new Game(client, YP1, Ynick, command[2]))); Dispatcher.Invoke((Action)(() => game.Show())); Dispatcher.Invoke((Action)(() => Close())); return; } } }
private void ListendForCommand() { while (client.Connected) { string data = clientIO.ReadData(); string[] command = data.Split(','); if (command[0] != "") { if (command[0] == "mv") { int index = Convert.ToInt32(command[1]); mResults[index] = YouPlayer1 ? MarkType.Nought : MarkType.Cross; switch (index) { case 0: Dispatcher.BeginInvoke((Action)(() => Button0_0.Content = YouPlayer1 ? "O" : "X")); if (YouPlayer1) { Dispatcher.BeginInvoke((Action)(() => Button0_0.Foreground = Brushes.Red)); } break; case 1: Dispatcher.BeginInvoke((Action)(() => Button1_0.Content = YouPlayer1 ? "O" : "X")); if (YouPlayer1) { Dispatcher.BeginInvoke((Action)(() => Button1_0.Foreground = Brushes.Red)); } break; case 2: Dispatcher.BeginInvoke((Action)(() => Button2_0.Content = YouPlayer1 ? "O" : "X")); if (YouPlayer1) { Dispatcher.BeginInvoke((Action)(() => Button2_0.Foreground = Brushes.Red)); } break; case 3: Dispatcher.BeginInvoke((Action)(() => Button0_1.Content = YouPlayer1 ? "O" : "X")); if (YouPlayer1) { Dispatcher.BeginInvoke((Action)(() => Button0_1.Foreground = Brushes.Red)); } break; case 4: Dispatcher.BeginInvoke((Action)(() => Button1_1.Content = YouPlayer1 ? "O" : "X")); if (YouPlayer1) { Dispatcher.BeginInvoke((Action)(() => Button1_1.Foreground = Brushes.Red)); } break; case 5: Dispatcher.BeginInvoke((Action)(() => Button2_1.Content = YouPlayer1 ? "O" : "X")); if (YouPlayer1) { Dispatcher.BeginInvoke((Action)(() => Button2_1.Foreground = Brushes.Red)); } break; case 6: Dispatcher.BeginInvoke((Action)(() => Button0_2.Content = YouPlayer1 ? "O" : "X")); if (YouPlayer1) { Dispatcher.BeginInvoke((Action)(() => Button0_2.Foreground = Brushes.Red)); } break; case 7: Dispatcher.BeginInvoke((Action)(() => Button1_2.Content = YouPlayer1 ? "O" : "X")); if (YouPlayer1) { Dispatcher.BeginInvoke((Action)(() => Button1_2.Foreground = Brushes.Red)); } break; case 8: Dispatcher.BeginInvoke((Action)(() => Button2_2.Content = YouPlayer1 ? "O" : "X")); if (YouPlayer1) { Dispatcher.BeginInvoke((Action)(() => Button2_2.Foreground = Brushes.Red)); } break; default: break; } Dispatcher.Invoke((Action)(() => CheckForWinner())); if (command.Length < 3) { Dispatcher.BeginInvoke((Action)(() => State.Content = "Ваш ход")); Dispatcher.BeginInvoke((Action)(() => State.Foreground = Brushes.Green)); } YouTurn = true; } if (command[0] == "win") { NewGame(); } if (command[0] == "disc") { MessageBox.Show("Противник отключился. Нажмите ОК чтобы вернуться в лобби"); Dispatcher.Invoke((Action)(() => BackToLobby_Click(this, EventArgs.Empty))); } } } }