Beispiel #1
0
 public NetworkRoom(PlayerUser connectUser)
 {
     InitializeComponent();
     User = connectUser;
     NicknamePlayer.Text = connectUser.GetNickname();
     LevelPlayer.Text    = connectUser.GetLevel().ToString();
     UpdateAllRoom();
 }
Beispiel #2
0
 public NetworkRoom(PlayerUser connectUser, int exit)
 {
     InitializeComponent();
     User = connectUser;
     NicknamePlayer.Text = connectUser.GetNickname();
     LevelPlayer.Text    = connectUser.GetLevel().ToString();
     Exits(exit.ToString());
     User.SetStateRoom(null);
     User.SetStateMap(null);
     UpdateAllRoom();
 }
Beispiel #3
0
        private void CreateRoom_Click(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (Convert.ToInt32(ValuePlayers.Text) <= 1)
                {
                    throw new Exception("Вместительность не должна быть меньше 2!\r\n");
                }
                if (Convert.ToInt32(RangeDown.Text) > Convert.ToInt32(RangeUp.Text))
                {
                    throw new Exception("Нижний порог входа выше чем верхний!\r\n");
                }
                if (Convert.ToInt32(RangeUp.Text) < Convert.ToInt32(RangeDown.Text))
                {
                    throw new Exception("Верхний порог входа ниже чем нижний!\r\n");
                }
                foreach (StackPanel stack in StackPlayer.Children)
                {
                    if (stack.Name == NameRoom.Text)
                    {
                        throw new Exception("Комната с таким именем уже существует\r\n");
                    }
                }
                if (CreateRoom.Visibility == Visibility.Collapsed)
                {
                    CreateWindow.IsEnabled = false;
                    StatsPlayer.Margin     = new Thickness(0, 0, 165, 0);
                    ValuePlayers.Text      = "2";
                    RangeUp.Text           = "0";
                    RangeDown.Text         = "0";
                    CreateRoom.Visibility  = Visibility.Visible;
                }
                else if (MapSelection.SelectedItem == null || ValuePlayers.Text == "" || NameRoom.Text == "" || RangeUp.Text == "" || RangeDown.Text == "")
                {
                    throw new Exception("Не все поля заполнены\r\n");
                }
                else
                {
                    client = new TcpClient(address, port);
                    stream = client.GetStream();
                    User.SetStateRoom(NameRoom.Text);
                    User.SetStateMap(MapSelection.Text);
                    message = "2 " + NameRoom.Text + " " + ValuePlayers.Text + " " + RangeUp.Text + " " + RangeDown.Text + " " + MapSelection.Text + " " + User.GetNickname() + " " + User.GetLevel().ToString();
                    byte[] data = Encoding.Unicode.GetBytes(message);
                    stream.Write(data, 0, data.Length);
                    data = new byte[64];
                    StringBuilder builder = new StringBuilder();
                    int           bytes   = 0;
                    do
                    {
                        bytes = stream.Read(data, 0, data.Length);
                        builder.Append(Encoding.Unicode.GetString(data, 0, bytes));
                    }while (stream.DataAvailable);

                    if (builder.ToString() == "Комната успешно создана")
                    {
                        CreateWindow.IsEnabled   = false;
                        CreateWindow.MouseMove  -= MoveMouseMenuOnline_but;
                        CreateWindow.MouseLeave -= MoveLeave_but;
                        CreateWindow.Background  = null;
                        CreateWindow.Opacity     = 0.3;

                        ChatTextBlock.Text += builder.ToString() + "\r\n";
                        client.Close();

                        StatsPlayer.Margin     = new Thickness(0, 86, 5, 0);
                        CreateWindow.IsEnabled = true;
                        Border room = new Border();
                        room.Height               = 20;
                        room.Background           = Brushes.Black;
                        room.BorderBrush          = Brushes.Green;
                        room.BorderThickness      = new Thickness(2);
                        room.Margin               = new Thickness(0, 5, 0, 0);
                        room.MouseMove           += MoveMouseRoom_but;
                        room.MouseLeave          += MoveLeaveRoom_but;
                        room.MouseLeftButtonDown += MoveClickRoom_but;

                        WrapPanel wrap = new WrapPanel();

                        TextBlock namemap = new TextBlock();
                        namemap.Width         = 220;
                        namemap.TextAlignment = TextAlignment.Center;
                        namemap.Foreground    = Brushes.Lime;
                        namemap.FontSize      = 12;
                        namemap.FontFamily    = new FontFamily(new Uri("pack://application:,,,/Nuclear"), "/data/fonts/#Fallout Display");
                        namemap.Text          = NameRoom.Text;

                        TextBlock map = new TextBlock();
                        map.Width         = 170;
                        map.TextAlignment = TextAlignment.Center;
                        map.Foreground    = Brushes.Lime;
                        map.FontSize      = 12;
                        map.FontFamily    = new FontFamily(new Uri("pack://application:,,,/Nuclear"), "/data/fonts/#Fallout Display");
                        map.Text          = MapSelection.Text;

                        TextBlock valPlayers = new TextBlock();
                        valPlayers.Width         = 90;
                        valPlayers.TextAlignment = TextAlignment.Center;
                        valPlayers.Foreground    = Brushes.Lime;
                        valPlayers.FontSize      = 12;
                        valPlayers.Name          = NameRoom.Text + "Count";
                        valPlayers.FontFamily    = new FontFamily(new Uri("pack://application:,,,/Nuclear"), "/data/fonts/#Fallout Display");
                        valPlayers.Text          = "0" + "/" + ValuePlayers.Text;

                        TextBlock range = new TextBlock();
                        range.Width         = 75;
                        range.TextAlignment = TextAlignment.Center;
                        range.Foreground    = Brushes.Lime;
                        range.FontSize      = 12;
                        range.FontFamily    = new FontFamily(new Uri("pack://application:,,,/Nuclear"), "/data/fonts/#Fallout Display");
                        range.Text          = RangeDown.Text + " - " + RangeUp.Text;

                        TextBlock active = new TextBlock();
                        active.Width         = 115;
                        active.TextAlignment = TextAlignment.Center;
                        active.Foreground    = Brushes.Lime;
                        active.FontSize      = 12;
                        active.FontFamily    = new FontFamily(new Uri("pack://application:,,,/Nuclear"), "/data/fonts/#Fallout Display");
                        active.Text          = "ОЖИДАНИЕ";

                        wrap.Children.Add(namemap);
                        wrap.Children.Add(map);
                        wrap.Children.Add(valPlayers);
                        wrap.Children.Add(range);
                        wrap.Children.Add(active);
                        room.Child = wrap;
                        StackRoom.Children.Add(room);

                        StackPanel listPlayer = new StackPanel();
                        listPlayer.Name       = NameRoom.Text;
                        listPlayer.Visibility = Visibility.Collapsed;
                        StackPlayer.Children.Add(listPlayer);
                        NameRoom.Text = "";

                        CreateRoom.Visibility = Visibility.Collapsed;
                        UpdateAllRoom();
                        User.SetStateRoom(namemap.Text);
                        this.NavigationService.Navigate(new Game(User));
                    }
                    else
                    {
                    }
                }
            }
            catch (Exception error)
            {
                ChatTextBlock.Text += error.Message + "\r\n";
            }
            finally
            {
                client.Close();
            }
        }