MbReadyMultiPlayer

This commit is contained in:
rawer470 2024-08-17 11:24:12 +03:00
parent 215b538715
commit 3849435115
3 changed files with 62 additions and 24 deletions

View file

@ -14,6 +14,8 @@ using ZoFo.GameCore.GameObjects.MapObjects.Tiles;
using System.Drawing; using System.Drawing;
using System.Reflection; using System.Reflection;
using ZoFo.GameCore.GameObjects.Entities; using ZoFo.GameCore.GameObjects.Entities;
using System.Net.Sockets;
using System.Net;
namespace ZoFo.GameCore namespace ZoFo.GameCore
{ {
@ -22,6 +24,8 @@ namespace ZoFo.GameCore
ClientNetworkManager networkManager; ClientNetworkManager networkManager;
public bool IsConnected { get { return networkManager.IsConnected; } } public bool IsConnected { get { return networkManager.IsConnected; } }
public IPEndPoint InfoConnect => networkManager.InfoConnect;
public Client() public Client()
{ {
networkManager = new ClientNetworkManager(); networkManager = new ClientNetworkManager();

View file

@ -26,7 +26,7 @@ public class SelectingServerGUI : AbstractGUI
Elements.Add(menuBackground); Elements.Add(menuBackground);
menuBackground.LoadTexture(AppManager.Instance.Content); menuBackground.LoadTexture(AppManager.Instance.Content);
Elements.Add(new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 7, (int)(width / 4), (int)(height / 20)), text = "Select server", fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts/Font"}); Elements.Add(new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 7, (int)(width / 4), (int)(height / 20)), text = "Select server", fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts/Font" });
TextBox ipBox = new TextBox(Manager) TextBox ipBox = new TextBox(Manager)
{ {
@ -38,13 +38,15 @@ public class SelectingServerGUI : AbstractGUI
textAligment = MonogameLibrary.UI.Enums.TextAligment.Left, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left,
fontName = "Fonts/Font" fontName = "Fonts/Font"
}; };
ipBox.TextChanged += input => { ipBox.TextChanged += input =>
{
if (input == "ip") if (input == "ip")
{ {
ipBox.text = ""; ipBox.fontColor = Color.White; ipBox.text = ""; ipBox.fontColor = Color.White;
} }
}; };
ipBox.StopChanging += input => { ipBox.StopChanging += input =>
{
if (input.Length == 0) if (input.Length == 0)
{ {
ipBox.fontColor = Color.White; ipBox.fontColor = Color.White;
@ -66,14 +68,25 @@ public class SelectingServerGUI : AbstractGUI
// join // join
Client client = new Client(); Client client = new Client();
var endpoint = ipBox.text.Split(':'); var endpoint = ipBox.text.Split(':');
int port; int port;
if (int.TryParse(endpoint[1], out port)) try
{ {
client.JoinRoom(endpoint[0], port); if (int.TryParse(endpoint[1], out port))
AppManager.Instance.SetClient(client); {
AppManager.Instance.SetGUI(new WaitingForPlayersGUI(false)); client.JoinRoom(endpoint[0], port);
AppManager.Instance.SetClient(client);
Server server = new Server();
AppManager.Instance.SetServer(server);
AppManager.Instance.SetGUI(new WaitingForPlayersGUI(false));
}
} }
catch (Exception)
{
// throw;
}
// ваш код здесь // ваш код здесь
}; };
Elements.Add(joinButton); Elements.Add(joinButton);
@ -101,7 +114,7 @@ public class SelectingServerGUI : AbstractGUI
Elements.Add(hostButton); Elements.Add(hostButton);
Button bTExit = new Button(Manager) Button bTExit = new Button(Manager)
{ fontName = "Fonts/Font3", scale = 0.4f, text = "<-", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width / 30, height / 30, width / 40, width / 40), textureName = "Textures/GUI/checkboxs_off"}; { fontName = "Fonts/Font3", scale = 0.4f, text = "<-", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width / 30, height / 30, width / 40, width / 40), textureName = "Textures/GUI/checkboxs_off" };
Elements.Add(bTExit); Elements.Add(bTExit);
bTExit.LeftButtonPressed += () => bTExit.LeftButtonPressed += () =>
{ {

View file

@ -31,11 +31,12 @@ public class WaitingForPlayersGUI : AbstractGUI
menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), mainColor = Color.White, textureName = "Textures\\GUI\\background\\Waiting" }; menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), mainColor = Color.White, textureName = "Textures\\GUI\\background\\Waiting" };
Elements.Add(menuBackground); Elements.Add(menuBackground);
menuBackground.LoadTexture(AppManager.Instance.Content); menuBackground.LoadTexture(AppManager.Instance.Content);
// 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);
if (isHost) 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" };
Elements.Add(ip);
Button startButton = new Button(Manager) Button startButton = new Button(Manager)
{ {
rectangle = new Rectangle(width / 2 - (width / 15) / 2, height / 2 + height / 4, (int)(width / 15), (int)(height / 20)), rectangle = new Rectangle(width / 2 - (width / 15) / 2, height / 2 + height / 4, (int)(width / 15), (int)(height / 20)),
@ -53,6 +54,26 @@ public class WaitingForPlayersGUI : AbstractGUI
}; };
Elements.Add(startButton); Elements.Add(startButton);
} }
else {
ip = new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 7, (int)(width / 4), (int)(height / 20)), text = AppManager.Instance.client.InfoConnect.ToString(), fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font3" };
Elements.Add(ip);
Button waitButton = new Button(Manager)
{
rectangle = new Rectangle(width / 2 - (width / 15) / 2, height / 2 + height / 4, (int)(width / 15), (int)(height / 20)),
text = "WAITING",
scale = 0.3f,
fontColor = Color.White,
mainColor = Color.Gray,
fontName = "Fonts/Font"
};
waitButton.LeftButtonPressed += () =>
{
// start
// ваш код здесь
};
Elements.Add(waitButton);
}
Button bTExit = new Button(Manager) Button bTExit = new Button(Manager)
{ fontName = "Fonts/Font3", scale = 0.4f, text = "<-", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width / 30, height / 30, width / 40, width / 40), textureName = "Textures/GUI/checkboxs_off"}; { fontName = "Fonts/Font3", scale = 0.4f, text = "<-", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width / 30, height / 30, width / 40, width / 40), textureName = "Textures/GUI/checkboxs_off"};