예제 #1
0
 private void buttonChat_Click(object sender, RoutedEventArgs e)
 {
     if (textBoxChat.Text != "")
     {
         Data msgToSend = new Data();
         msgToSend.cmdCommand = Command.chat;
         msgToSend.cardID = 0;
         msgToSend.usersInRoom = textBoxChat.Text;
         if (!w.client.Send(msgToSend))
         {
             Connection c = new Connection();
             c.Show();
             this.Close();
             return;
         }
         textBoxChat.Text = "";
     }
 }
예제 #2
0
 private void onClosing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     Dispatcher.Invoke((Action)(() =>
     {
         Data msgToSend = new Data();
         msgToSend.cmdCommand = Command.Disconnect;
         w.client.Send(msgToSend);
         Application app = Application.Current;
         app.Shutdown();
     }));
 }
예제 #3
0
 private void createGame_Click(object sender, RoutedEventArgs e)
 {
     if (roomNameBox.Text == "")
     {
         txt.Text = "Невозможно создать комнату с таким именем!";
         if (w.IsSoundEnabled)
             soundPlay(new Uri(@"sounds\\error.mp3", UriKind.Relative), null);
             return;
     }
     if (roomNameBox.Text.Length > 15)
     {
         txt.Text = "Максимальная длина названия комнаты - 15 символов!";
         if (w.IsSoundEnabled)
             soundPlay(new Uri(@"sounds\\error.mp3", UriKind.Relative), null);
         return;
     }
     if (pwdBox.Text.Length > 20)
     {
         txt.Text = "Максимальная длина пароль 20 символов, вот так.";
         if (w.IsSoundEnabled)
             soundPlay(new Uri(@"sounds\\error.mp3", UriKind.Relative), null);
         return;
     }
     //проверка уникальности имени комнаты
     foreach (Room r in w.client.list)
     {
         if (r.roomName == roomNameBox.Text )
         {
             expander.IsExpanded = true;
             if (w.IsSoundEnabled)
                 soundPlay(new Uri(@"sounds\\error.mp3", UriKind.Relative), null);
             txt.Text = "Невозможно создать комнату с таким именем!";
             return;
         }
     }
     //отправка создания комнаты
     w.Title += " [" + roomNameBox.Text + " | " + (int)Math.Round(sliderScores.Value) + " ]";
     Data msgToSend = new Data();
     msgToSend.cmdCommand = Command.newGame;
     msgToSend.gameToConnectRoomName = roomNameBox.Text;
     msgToSend.login = pwdBox.Text;
     msgToSend.cardID = (int)Math.Round(sliderScores.Value);
     msgToSend.usersInRoom = deckSize.ToString();
     if (!w.client.Send(msgToSend))
     {
         this.Close();
         return;
     }
     //w.client.createGame(, , ,);
     w.isAdmin = true;
     this.Hide();
     w.Show();
     w.buttonTaskOK.Content = "Начать игру";
     w.buttonTaskOK.IsEnabled = true;
     if (w.IsSoundEnabled)
         soundPlay(new Uri(@"sounds\\connect.mp3", UriKind.Relative), null);
 }
예제 #4
0
        private void connectToRoom_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Room selecterdRoom = (Room)roomsDataGrid.SelectedItem;
                if (selecterdRoom.status > 0)
                {
                    txt.Text = "Игра уже началась! Вы не можете подключиться";
                    if (w.IsSoundEnabled) soundPlay(new Uri(@"sounds\\warning.mp3", UriKind.Relative), null);
                    return;
                }
                if (selecterdRoom.status == 0)
                {
                    passed = false;
                    if (selecterdRoom.password == "") passed = true;
                    else
                    {
                        pass p = new pass(this, selecterdRoom.password);
                        p.ShowDialog();
                    }

                    if (passed)
                    {
                        w.isAdmin = false;
                        Data msgToSend = new Data();
                        msgToSend.cmdCommand = Command.connectToGame;
                        msgToSend.gameToConnectRoomName = selecterdRoom.roomName;

                        if (!w.client.Send(msgToSend))
                        {
                            this.Close();
                            return;
                        }

                        this.Hide();
                        w.Show();
                        w.buttonTaskOK.IsEnabled = false;
                        w.buttonTaskOK.Content = "Ожидание. . .";
                        w.Title += " [" + selecterdRoom.roomName + " | " + selecterdRoom.maxScores.ToString() + " ]";
                        if (w.IsSoundEnabled)
                            soundPlay(new Uri(@"sounds\\connect.mp3", UriKind.Relative), null);
                    }
                    else
                    {
                        txt.Text = "Неверный пароль!";
                        if (w.IsSoundEnabled) soundPlay(new Uri(@"sounds\\warning.mp3", UriKind.Relative), null);
                    }
                }

            }
            catch { }
        }
예제 #5
0
 private void Window_Closing_1(object sender, System.ComponentModel.CancelEventArgs e)
 {
     lock (locker)
         Dispatcher.Invoke((Action)(() =>
         {
             player.Close();
             m.Close();
             Data msgToSend = new Data();
             msgToSend.cmdCommand = Command.Disconnect;
             client.Send(msgToSend);
             Application app = Application.Current;
             app.Shutdown();
         }));
 }
예제 #6
0
 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();
 }
예제 #7
0
        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;
            }
        }