private void Button_Click_1(object sender, RoutedEventArgs e) { this.Hide(); Data msgToSend = new Data(); msgToSend.cmdCommand = Command.logOutRoom; if (!client.Send(msgToSend)) { this.Close(); return; } if (IsSoundEnabled) playSound(new Uri(@"sounds\\beep.mp3", UriKind.Relative)); (Tag as TextBlock).Text = "Ожидание игроков"; userCardsPanel.Children.Clear(); VoatingPanel.Children.Clear(); textBoxTask.Text = ""; gamers.Clear(); GamersdataGrid.Items.Clear(); Gamer alone = new Gamer(myLogin, 0); GamersdataGrid.Items.Add(alone); textBoxTask.Visibility = System.Windows.Visibility.Hidden; userCardsPanel.Visibility = System.Windows.Visibility.Hidden; VoatingPanel.Visibility = System.Windows.Visibility.Hidden; userCardsPanelBorder.Visibility = System.Windows.Visibility.Hidden; VoatingPanelBorder.Visibility = System.Windows.Visibility.Hidden; SetCardSample(); ChatBox.Text = ""; TaskBlock.Text = ""; gameStarted = false; status = 0; round = 1; this.Title = "Dixit - " + myLogin; r.Show(); }
//список игроков для комнаты void client_refreshUsersInRooms(object sender, EventArgs e) { Dispatcher.Invoke((Action)(() => { lock (locker) { if (!gameStarted) gamers.Clear(); string temp = (string)sender; string[] usrs = temp.Split(' '); if (gameStarted) foreach (string s in usrs) { //проверка, никого не удалили ли for (int i = 0; i < gamers.Count; i++) if (temp.IndexOf(gamers[i].login) == -1) { AddChatMsg(0, null, "Игрок " + gamers[i].login + " покинул комнату\n", Brushes.Firebrick); gamers.Remove(gamers[i]); } for (int j = 0; j < gamers.Count; j++) if (s.StartsWith(gamers[j].login)) { if (s.Length <= 1) continue; if (s.Contains<char>('*')) gamers[j].status = 2; //загадывал else if (s.Contains<char>('#')) { if ((status == 4 || status == 2) && gamers[j].status == 0) SetCardVoatingPanel(0, gamers[j].login, 1); gamers[j].status = 1; //прислал карту } else if (s.Contains<char>('&')) { gamers[j].status = 3; //выиграл! gameStarted = false; } else if (s.Contains<char>('?')) { gamers[j].status = -1; //отключился в важную фазу, засранец! //AddChatMsg(0, null, "Игрок " + gamers[j].login + " покинул комнату\n", Brushes.Firebrick); } else gamers[j].status = 0; } } else for (int i = 0; i < usrs.Length; i++) { if (usrs[i].Length < 1) continue; Gamer g; if (usrs[i].Contains<char>('*')) { g = new Gamer(usrs[i].Replace('*', ' '), i); g.status = 2; //загадывал } else if (usrs[i].Contains<char>('#')) { g = new Gamer(usrs[i].Replace('#', ' '), i); g.status = 1; //прислал карту } else g = new Gamer(usrs[i], i); gamers.Add(g); } GamersdataGrid.Items.Clear(); for (int i = 0; i < gamers.Count; i++) if (gamers[i].status != -1) GamersdataGrid.Items.Add(gamers[i]); } })); }
public MainWindow(string login, Client cl, double opacity, bool snd, messageViewer _m) { InitializeComponent(); myLogin = login; this.Title = "Dixit - " + myLogin; client = cl; client.needExit += client_needExit; client.gameStart += client_gameStart; client.refreshUsersInRooms += client_refreshUsersInRooms; client.leaderTurn += client_leaderTurn; client.waiting += client_waiting; client.gamerTurn += client_gamerTurn; client.voatingTurn += client_voatingTurn; client.result += client_result; client.resultChat += client_resultChat; //client.newRound +=client_newRound; client.win+=client_win; client.serverDisconnect += client_serverDisconnect; client.chatMsg += client_chatMsg; client.setAdmin += client_setAdmin; player = new MediaPlayer(); IsSoundEnabled = snd; if (!IsSoundEnabled) buttonSoundText.Text = "V"; m = _m; r = new rooms(this, opacity); r.soundPlay += new EventHandler(r_soundPlay); r.Show(); this.Hide(); textBoxTask.Visibility = System.Windows.Visibility.Hidden; gamers = new List<Gamer>(); Gamer alone = new Gamer(myLogin, 0); GamersdataGrid.Items.Add(alone); tag = new TextBlock(); tag.Text = "Ожидание начала игры"; tag.FontWeight = FontWeights.Bold; tag.FontStyle = FontStyles.Italic; tag.TextAlignment = TextAlignment.Center; tag.FontSize = 14; Tag = tag; userCardsPanel.Visibility = System.Windows.Visibility.Hidden; VoatingPanel.Visibility = System.Windows.Visibility.Hidden; userCardsPanelBorder.Visibility = System.Windows.Visibility.Hidden; VoatingPanelBorder.Visibility = System.Windows.Visibility.Hidden; SetCardSample(); LinearGradientBrush myBrush = new LinearGradientBrush(Colors.PowderBlue, Colors.MediumSlateBlue, 30); ImgBrdr.Background = myBrush; VoatingBackgroundBrush.Opacity = opacity; ChatBackgroundBrush.Opacity = opacity; UsersGridBackgroundBrush.Opacity = opacity; }