From 069b62abeec69d6fd02e1ffa06d821d370573901 Mon Sep 17 00:00:00 2001 From: rawer470 Date: Fri, 16 Aug 2024 14:05:34 +0300 Subject: [PATCH 1/4] UpdateTileCreated --- ZoFo/GameCore/GUI/SelectModeMenu.cs | 8 ++++--- .../NetworkManager/Updates/IUpdateData.cs | 2 ++ .../ServerToClient/UpdateTileCreated.cs | 21 +++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateTileCreated.cs diff --git a/ZoFo/GameCore/GUI/SelectModeMenu.cs b/ZoFo/GameCore/GUI/SelectModeMenu.cs index 726a261..84290a8 100644 --- a/ZoFo/GameCore/GUI/SelectModeMenu.cs +++ b/ZoFo/GameCore/GUI/SelectModeMenu.cs @@ -64,12 +64,14 @@ public class SelectModeMenu : AbstractGUI optionButton.LeftButtonPressed += () => { // multi - Server server = new Server(); //Server Logic SinglePlayer + Server server = new Server(); //Server Logic MultiPlayer Client client = new Client(); - server.CreateRoom(1); - client.JoinYourself(); + server.CreateRoom(5); + client.JoinRoom("127.0.0.1"); //указать айпишник AppManager.Instance.SetServer(server); AppManager.Instance.SetClient(client); + string key = client.IsConnected.ToString(); + AppManager.Instance.debugHud.Set(key, "MultiPlayer"); // ваш код здесь }; Elements.Add(optionButton); diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/IUpdateData.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/IUpdateData.cs index a90aaf4..5c363d7 100644 --- a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/IUpdateData.cs +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/IUpdateData.cs @@ -17,8 +17,10 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates [JsonDerivedType(typeof(UpdateLoot))] [JsonDerivedType(typeof(UpdatePlayerParametrs))] [JsonDerivedType(typeof(UpdatePosition))] + [JsonDerivedType(typeof(UpdateTileCreated))] [JsonDerivedType(typeof(UpdateInput))] [JsonDerivedType(typeof(UpdatePlayerExit))] + public interface IUpdateData { public int IdEntity { get; set; } //Id объекта diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateTileCreated.cs b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateTileCreated.cs new file mode 100644 index 0000000..796683d --- /dev/null +++ b/ZoFo/GameCore/GameManagers/NetworkManager/Updates/ServerToClient/UpdateTileCreated.cs @@ -0,0 +1,21 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; +using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ClientToServer; + +namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient +{ + + public class UpdateTileCreated : IUpdateData + { + public int IdEntity { get; set; } + public string UpdateType { get; set; } + public Texture2D TextureTile { get; set; } + public Vector2 Position { get; set; } + } +} From 69d2c06ebe3819007ad3425c28f0b025bd894aed Mon Sep 17 00:00:00 2001 From: rawer470 Date: Fri, 16 Aug 2024 15:23:30 +0300 Subject: [PATCH 2/4] ServerChange --- ZoFo/GameCore/Server.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/ZoFo/GameCore/Server.cs b/ZoFo/GameCore/Server.cs index 48ff924..0cdf548 100644 --- a/ZoFo/GameCore/Server.cs +++ b/ZoFo/GameCore/Server.cs @@ -60,6 +60,7 @@ namespace ZoFo.GameCore } public void Update(GameTime gameTime) { + } /// From 580d9a2327952a029a76892279bb5002ae4a20b5 Mon Sep 17 00:00:00 2001 From: rawer470 Date: Fri, 16 Aug 2024 15:31:58 +0300 Subject: [PATCH 3/4] ChangeMethodUpdateServer --- ZoFo/GameCore/Server.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ZoFo/GameCore/Server.cs b/ZoFo/GameCore/Server.cs index 5385ce5..5fcb39c 100644 --- a/ZoFo/GameCore/Server.cs +++ b/ZoFo/GameCore/Server.cs @@ -16,6 +16,7 @@ namespace ZoFo.GameCore public class Server { private ServerNetworkManager networkManager; + private int ticks = 0; public Server() { networkManager = new ServerNetworkManager(); @@ -61,12 +62,20 @@ namespace ZoFo.GameCore private List entities; //entity public void Update(GameTime gameTime) { - foreach (var go in gameObjects) + if (ticks == 3) //ОБРАБАТЫВАЕТСЯ 20 РАЗ В СЕКУНДУ { - go.UpdateLogic(gameTime); + foreach (var go in gameObjects) + { + go.UpdateLogic(gameTime); + } + ticks = 0; + networkManager.SendData(); } + ticks++; } + + /// /// Регистрирует игровой объект /// From 91d15a9de5d5b6bc0dcdb6d3725431e3e212ec38 Mon Sep 17 00:00:00 2001 From: rawer470 Date: Fri, 16 Aug 2024 15:39:58 +0300 Subject: [PATCH 4/4] ClirntReadyDataSend --- ZoFo/GameCore/Client.cs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/ZoFo/GameCore/Client.cs b/ZoFo/GameCore/Client.cs index 484e82a..bb33c14 100644 --- a/ZoFo/GameCore/Client.cs +++ b/ZoFo/GameCore/Client.cs @@ -7,6 +7,8 @@ using ZoFo.GameCore.GameManagers.NetworkManager.Updates; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; +using ZoFo.GameCore.GameObjects; +using ZoFo.GameCore.GameObjects.MapObjects; namespace ZoFo.GameCore { @@ -22,21 +24,32 @@ namespace ZoFo.GameCore } public void OnDataSend(string data) - { + { List updateDatas = JsonSerializer.Deserialize>(data); // тут будет switch + foreach (var item in updateDatas) + { + /* switch (item.UpdateType) Здесь нужно отлавливать и регистрировать + { + case "Tile": + MapObject map = new MapObject(); + + break; + }*/ + } + } - public void GameEndedUnexpectedly(){ } + public void GameEndedUnexpectedly() { } public void JoinRoom(string ip) { networkManager.JoinRoom(ip); } - public void JoinYourself(){ networkManager.JoinYourself(); } + public void JoinYourself() { networkManager.JoinYourself(); } internal void Update(GameTime gameTime) { } internal void Draw(SpriteBatch spriteBatch) - { + { } } } \ No newline at end of file