void client_gamerTurn(object sender, EventArgs e) { lock (locker) Dispatcher.Invoke((Action)(() => { if (IsSoundEnabled) { playSound(new Uri(@"sounds\\beep.mp3", UriKind.Relative)); } TaskBlock.Text = LeaderName + ": " + (string)sender; TaskBlock.Focus(); TaskBlock.Visibility = Visibility.Visible; buttonTaskOK.IsEnabled = true; (Tag as TextBlock).Text = "Ассоциация загадана!"; status = 4; buttonTaskOK.Content = "Отправить карту"; SetCardVoatingPanel(0, LeaderName, 1); })); }
private void buttonTaskOK_Click(object sender, RoutedEventArgs e) { if (status == 0) { if (GamersdataGrid.Items.Count == 1) { SetCardSample(9999, ""); if (IsSoundEnabled) { playSound(new Uri(@"sounds\\warning.mp3", UriKind.Relative)); } return; } Data msgToSend = new Data(); msgToSend.cmdCommand = Command.startGame; if (!client.Send(msgToSend)) { this.Close(); } return; } if (status == 2) { if (textBoxTask.Text.Length < 3 || textBoxTask.Text == "Плохая ассоциация! :(" || textBoxTask.Text == "Напишите здесь свою ассоциацию") { (Tag as TextBlock).Text = "Загадайте нормальную ассоциацию!"; textBoxTask.Text = "Плохая ассоциация! :("; textBoxTask.FontStyle = FontStyles.Italic; textBoxTask.FontWeight = FontWeights.Normal; if (IsSoundEnabled) { playSound(new Uri(@"sounds\\warning.mp3", UriKind.Relative)); } return; } int flag = -1; for (int i = 0; i < 6; i++) { if ((userCardsPanel.Children[i] as RadioButton).IsChecked == true) { flag = i; } } if (flag == -1) { (Tag as TextBlock).Text = "Выберите карту!"; if (IsSoundEnabled) { playSound(new Uri(@"sounds\\warning.mp3", UriKind.Relative)); } foreach (RadioButton r in userCardsPanel.Children) { r.Focusable = true; r.Focus(); r.Focusable = false; } return; } Data msgToSend = new Data(); msgToSend.cmdCommand = Command.LeaderTurn; msgToSend.cardID = cards[flag]; msgToSend.gameToConnectRoomName = textBoxTask.Text; if (!client.Send(msgToSend)) { this.Close(); return; } buttonTaskOK.IsEnabled = false; textBoxTask.IsEnabled = false; textBoxTask.Visibility = System.Windows.Visibility.Hidden; TaskBlock.Text = textBoxTask.Text; TaskBlock.Visibility = System.Windows.Visibility.Visible; TaskBlock.Focus(); (Tag as TextBlock).Text = "Ожидание ответа игроков"; SetCardVoatingPanel(0, LeaderName, 1); cards[flag] = -1; //типа сбросили карту там пусто } if (status == 4) { int flag = -1; for (int i = 0; i < 6; i++) { if ((userCardsPanel.Children[i] as RadioButton).IsChecked == true) { flag = i; } } if (flag == -1) { (Tag as TextBlock).Text = "Выберите карту!"; if (IsSoundEnabled) { playSound(new Uri(@"sounds\\warning.mp3", UriKind.Relative)); } foreach (RadioButton r in userCardsPanel.Children) { r.Focusable = true; r.Focus(); r.Focusable = false; } return; } buttonTaskOK.IsEnabled = false; Data msgToSend = new Data(); msgToSend.cmdCommand = Command.GamerTurn; msgToSend.cardID = cards[flag]; if (!client.Send(msgToSend)) { this.Close(); return; } cards[flag] = -1; //типа сбросили карту там пусто (Tag as TextBlock).Text = "Карта отправлена! Ожидание игроков"; return; } if (status == 5) { int flag = -1; for (int i = 0; i < VoatingPanel.Children.Count; i++) { if (((VoatingPanel.Children[i] as DockPanel).Children[1] as RadioButton).IsChecked == true) { flag = Convert.ToInt32(((VoatingPanel.Children[i] as DockPanel).Children[1] as RadioButton).Tag); } } if (flag == -1) { for (int i = 0; i < VoatingPanel.Children.Count; i++) { ((VoatingPanel.Children[i] as DockPanel).Children[1] as RadioButton).Focusable = true; ((VoatingPanel.Children[i] as DockPanel).Children[1] as RadioButton).Focus(); ((VoatingPanel.Children[i] as DockPanel).Children[1] as RadioButton).Focusable = false; } if (IsSoundEnabled) { playSound(new Uri(@"sounds\\warning.mp3", UriKind.Relative)); } (Tag as TextBlock).Text = "Выберите карту!"; return; } buttonTaskOK.IsEnabled = false; Data msgToSend = new Data(); msgToSend.cmdCommand = Command.VoatingTurn; msgToSend.cardID = flag; if (!client.Send(msgToSend)) { this.Close(); return; } (Tag as TextBlock).Text = "Ожидание голосования игроков"; return; } if (status == 6) { buttonTaskOK.IsEnabled = false; (Tag as TextBlock).Text = "Ожидание готовности игроков"; Data msgToSend = new Data(); msgToSend.cmdCommand = Command.Success; if (!client.Send(msgToSend)) { this.Close(); return; } return; } if (status == 8) { buttonTaskOK.IsEnabled = false; Data msgToSend = new Data(); msgToSend.cmdCommand = Command.startGame; if (!client.Send(msgToSend)) { this.Close(); } return; } }