From f6663bdd3c90065aaa38b7e8461587f419b9b4b4 Mon Sep 17 00:00:00 2001 From: rawer470 Date: Sat, 17 Aug 2024 10:50:05 +0300 Subject: [PATCH] StartCreateLogicMultiPlayer --- ZoFo/GameCore/GUI/SelectingServerGUI.cs | 15 ++++++++++++--- .../NetworkManager/ClientNetworkManager.cs | 10 ++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/ZoFo/GameCore/GUI/SelectingServerGUI.cs b/ZoFo/GameCore/GUI/SelectingServerGUI.cs index 1827f03..531f9db 100644 --- a/ZoFo/GameCore/GUI/SelectingServerGUI.cs +++ b/ZoFo/GameCore/GUI/SelectingServerGUI.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Net; using System.Xml; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; @@ -62,10 +63,18 @@ public class SelectingServerGUI : AbstractGUI }; joinButton.LeftButtonPressed += () => { - AppManager.Instance.SetGUI(new WaitingForPlayersGUI(false)); + // join - - // ваш код здесь + Client client = new Client(); + var endpoint = ipBox.text.Split(':'); + int port; + if (int.TryParse(endpoint[1], out port)) + { + client.JoinRoom(endpoint[0], port); + AppManager.Instance.SetClient(client); + AppManager.Instance.SetGUI(new WaitingForPlayersGUI(false)); + } + // ваш код здесь }; Elements.Add(joinButton); Button hostButton = new Button(Manager) diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs index b55d8cb..2a93f71 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs @@ -71,6 +71,16 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager listen.IsBackground = true; listen.Start(); } + public void JoinRoom(IPEndPoint endPoint) // multyplayer + { + + this.endPoint = endPoint; + socket.Connect(endPoint); + SendData(); + Thread listen = new Thread(StartListening); + listen.IsBackground = true; + listen.Start(); + } /// /// создается одиночная комната к которой ты подключаешься