diff --git a/ZoFo/GameCore/Client.cs b/ZoFo/GameCore/Client.cs index 8a936b4..d23c318 100644 --- a/ZoFo/GameCore/Client.cs +++ b/ZoFo/GameCore/Client.cs @@ -99,6 +99,10 @@ namespace ZoFo.GameCore gameObjects[i].UpdateAnimations(); } } + public void SendData() + { + networkManager.SendData(); + } internal void Draw(SpriteBatch spriteBatch) { for (int i = 0; i < mapObjects.Count; i++) diff --git a/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs b/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs index 2764fb1..4e90bd5 100644 --- a/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs +++ b/ZoFo/GameCore/GUI/WaitingForPlayersGUI.cs @@ -34,8 +34,8 @@ public class WaitingForPlayersGUI : AbstractGUI // string pcIp = // string pcIp = - ip = new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 7, (int)(width / 4), (int)(height / 20)), text = AppManager.Instance.server.MyIp.ToString(), fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts/Font3" }; - Elements.Add(ip); + //ip = new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 7, (int)(width / 4), (int)(height / 20)), text = AppManager.Instance.server.MyIp.ToString(), fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts/Font3" }; + //Elements.Add(ip); if (isHost) { ip = new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 7, (int)(width / 4), (int)(height / 20)), text = AppManager.Instance.server.MyIp.ToString(), fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font3" }; @@ -72,6 +72,7 @@ public class WaitingForPlayersGUI : AbstractGUI waitButton.LeftButtonPressed += () => { // start + AppManager.Instance.client.SendData(); AppManager.Instance.ChangeState(GameState.ClientPlaying); // ваш код здесь }; diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs index a50a6ad..6c43891 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs @@ -38,6 +38,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager endPoint = new IPEndPoint(GetIp(), 8081); socket.Bind(endPoint); Thread thread = new Thread(StartListening); + thread.IsBackground = true; thread.Start(); } @@ -144,14 +145,18 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager { string hostName = Dns.GetHostName(); // Retrive the Name of HOST var ipList = Dns.GetHostEntry(hostName).AddressList; - + var ipV4List = new List(); foreach (var ip in ipList) { if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { - return ip; + ipV4List.Add(ip); } } + if (ipV4List.Count>0) + { + return ipV4List[ipV4List.Count - 1]; + } return IPAddress.Loopback; }