public GameWindow() { InitializeComponent(); GameTCP = new GameTCPClient(); //LoginIn[] loginIn = new LoginIn[4] //{ // new LoginIn(){UserName="******",Password="******" }, // new LoginIn(){UserName="******",Password="******" }, // new LoginIn(){UserName="******",Password="******" }, // new LoginIn(){UserName="******",Password="******" }, //}; //Match match = new Match() { GameMode = GameMode.SiAn }; //for (int i = 1; i < GameTCP.Count + 1; i++) //{ // GameTCP[(OfSide)i].StartUp(IPAddress.Loopback); // GameTCP[(OfSide)i].SendAsync(loginIn[i - 1]).Wait(); // GameTCP[(OfSide)i].SendAsync(match).Wait(); //} GameTCP.NetMsgRev += _onMsgRecv; try { GameTCP.StartUp(IPAddress.Loopback); } catch (Exception e) { GameInfo.Content = "无法连接服务器,请重试"; } }
private void LoginButton_Click(object sender, RoutedEventArgs e) { LoginInfoLable.Content = string.Empty; if (!GameTCP.TcpClient.Connected) { try { GameTCP.StartUp(IPAddress.Loopback); } catch (Exception exc) { LoginInfoLable.Content = "无法连接服务器,请重试"; return; } } LoginIn loginIn = new LoginIn() { UserName = UsernameTextB.Text, Password = PasswordTextB.Password }; GameTCP.SendAsync(loginIn); }
/// <summary> /// 连接服务器 /// </summary> /// <param name="ip"></param> /// <param name="port"></param> public void StartUp(IPAddress ip, int port, GameMode mode) { GameTCPClient.StartUp(ip, port); Room.Cb.ChangeMode(mode); }