diff --git a/MonogameLibrary/UI/Base/UIManager.cs b/MonogameLibrary/UI/Base/UIManager.cs
index 826a0a1..125df25 100644
--- a/MonogameLibrary/UI/Base/UIManager.cs
+++ b/MonogameLibrary/UI/Base/UIManager.cs
@@ -59,8 +59,8 @@ namespace MonogameLibrary.UI.Base
{
keyboardState = Keyboard.GetState();
mouseState = Mouse.GetState();
- mouseState = new MouseState((int)(mouseState.X*(float)resolutionInGame.X/resolution.X),
- (int)(mouseState.Y * (float)resolutionInGame.Y / resolution.Y), mouseState.ScrollWheelValue, mouseState.LeftButton, mouseState.MiddleButton, mouseState.RightButton, mouseState.XButton1, mouseState.XButton2);
+ //mouseState = new MouseState((int)(mouseState.X*(float)resolutionInGame.X/resolution.X),
+ // (int)(mouseState.Y * (float)resolutionInGame.Y / resolution.Y), mouseState.ScrollWheelValue, mouseState.LeftButton, mouseState.MiddleButton, mouseState.RightButton, mouseState.XButton1, mouseState.XButton2);
}
catch
{
diff --git a/ZoFo/Content/Content.mgcb b/ZoFo/Content/Content.mgcb
index ddc4c36..4390819 100644
--- a/ZoFo/Content/Content.mgcb
+++ b/ZoFo/Content/Content.mgcb
@@ -13,3 +13,29 @@
#---------------------------------- Content ---------------------------------#
+#begin Fonts/Font.spritefont
+/importer:FontDescriptionImporter
+/processor:FontDescriptionProcessor
+/processorParam:PremultiplyAlpha=True
+/processorParam:TextureFormat=Compressed
+/build:Fonts/Font.spritefont
+
+#begin Fonts/Font2.spritefont
+/importer:FontDescriptionImporter
+/processor:FontDescriptionProcessor
+/processorParam:PremultiplyAlpha=True
+/processorParam:TextureFormat=Compressed
+/build:Fonts/Font2.spritefont
+
+#begin Textures/GUI/MenuBackground.jpg
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:Textures/GUI/MenuBackground.jpg
+
diff --git a/ZoFo/Content/Fonts/CarltineRegular-K7z5l.ttf b/ZoFo/Content/Fonts/CarltineRegular-K7z5l.ttf
new file mode 100644
index 0000000..1496983
Binary files /dev/null and b/ZoFo/Content/Fonts/CarltineRegular-K7z5l.ttf differ
diff --git a/ZoFo/Content/Fonts/Debrosee-ALPnL.ttf b/ZoFo/Content/Fonts/Debrosee-ALPnL.ttf
new file mode 100644
index 0000000..311dd61
Binary files /dev/null and b/ZoFo/Content/Fonts/Debrosee-ALPnL.ttf differ
diff --git a/ZoFo/Content/Fonts/Font.spritefont b/ZoFo/Content/Fonts/Font.spritefont
new file mode 100644
index 0000000..754d1ee
--- /dev/null
+++ b/ZoFo/Content/Fonts/Font.spritefont
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+ Debrosee-ALPnL.ttf
+
+
+ 100
+
+
+ 0
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+ ~
+
+
+
+
diff --git a/ZoFo/Content/Fonts/Font2.spritefont b/ZoFo/Content/Fonts/Font2.spritefont
new file mode 100644
index 0000000..3aaf8e7
--- /dev/null
+++ b/ZoFo/Content/Fonts/Font2.spritefont
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+ CarltineRegular-K7z5l.ttf
+
+
+ 15
+
+
+ 0
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+ ~
+
+
+
+
diff --git a/ZoFo/Content/Textures/GUI/MenuBackground.jpg b/ZoFo/Content/Textures/GUI/MenuBackground.jpg
new file mode 100644
index 0000000..79b0abe
Binary files /dev/null and b/ZoFo/Content/Textures/GUI/MenuBackground.jpg differ
diff --git a/ZoFo/GameCore/Client.cs b/ZoFo/GameCore/Client.cs
index f8a9288..5ee0546 100644
--- a/ZoFo/GameCore/Client.cs
+++ b/ZoFo/GameCore/Client.cs
@@ -1,14 +1,42 @@
+using System.Collections.Generic;
+using System.Text.Json;
+using ZoFo.GameCore.GameManagers.NetworkManager;
+using ZoFo.GameCore.GameManagers.NetworkManager.Updates;
+
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using System;
+
namespace ZoFo.GameCore
{
public class Client
{
- public void OnDataSend(string Data){ }
+ ClientNetworkManager networkManager;
+ public Client()
+ {
+ networkManager = new ClientNetworkManager();
+ networkManager.GetDataSent += OnDataSend;
+ }
+
+ public void OnDataSend(string data)
+ {
+ List updateDatas = JsonSerializer.Deserialize>(data);
+ // тут будет switch
+ }
public void GameEndedUnexpectedly(){ }
public void JoinRoom(){ }
public void JoinYourself(){ }
+
+ internal void Update(GameTime gameTime)
+ {
+ }
+
+ internal void Draw(SpriteBatch spriteBatch)
+ {
+ }
}
}
\ No newline at end of file
diff --git a/ZoFo/GameCore/GUI/AbstractGUI.cs b/ZoFo/GameCore/GUI/AbstractGUI.cs
index d2b69ce..2c2d7f6 100644
--- a/ZoFo/GameCore/GUI/AbstractGUI.cs
+++ b/ZoFo/GameCore/GUI/AbstractGUI.cs
@@ -9,6 +9,7 @@ using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonogameLibrary.UI.Base;
using MonogameLibrary.UI.Elements;
+using ZoFo.GameCore.GameManagers;
namespace ZoFo.GameCore.GUI;
@@ -29,22 +30,27 @@ public abstract class AbstractGUI
private GraphicsDevice graphicsDevice;
public virtual void Initialize()
{
- // Manager.Initialize(AppManager.Instance.GraphicsDevice);
+ Manager.Initialize(AppManager.Instance.GraphicsDevice);
CreateUI();
}
public virtual void LoadContent()
{
-
+ Manager.LoadContent(AppManager.Instance.Content, "Font");
}
public virtual void Update(GameTime gameTime)
{
-
+ Manager.Update(gameTime);
}
public virtual void Draw(SpriteBatch spriteBatch)
{
Manager.Draw(spriteBatch);
}
+
+ public virtual void ResolutioChenges()
+ {
+
+ }
}
\ No newline at end of file
diff --git a/ZoFo/GameCore/GUI/DebugHUD.cs b/ZoFo/GameCore/GUI/DebugHUD.cs
new file mode 100644
index 0000000..de4a587
--- /dev/null
+++ b/ZoFo/GameCore/GUI/DebugHUD.cs
@@ -0,0 +1,72 @@
+using System.Collections.Generic;
+using System.Linq;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using MonogameLibrary.UI.Elements;
+using static System.String;
+using ZoFo.GameCore.GameManagers;
+
+namespace ZoFo.GameCore.GUI;
+
+public class DebugHUD
+{
+ private SpriteFont _spriteFont;
+ private Dictionary _text = new();
+ private List _log = new();
+
+ public void Initialize()
+ {
+ }
+
+ public void LoadContent()
+ {
+ _spriteFont = AppManager.Instance.Content.Load("Fonts\\Font2");
+ }
+
+ public void Update(GameTime gameTime)
+ {
+ }
+
+ public void Draw(SpriteBatch spriteBatch)
+ {
+ var keysString = Join("\n", _text.Select(el => el.Key + ": " + el.Value).ToList());
+ spriteBatch.Begin();
+ spriteBatch.DrawString(
+ _spriteFont,
+ keysString,
+ new Vector2(10, 10),
+ Color.Cyan,
+ 0,
+ Vector2.Zero,
+ 1,
+ SpriteEffects.None,
+ 0
+ );
+ spriteBatch.DrawString(
+ _spriteFont,
+ Join("\n", _log),
+ new Vector2(10, 10 + _spriteFont.MeasureString(keysString).Y),
+ Color.Green,
+ 0,
+ Vector2.Zero,
+ 1,
+ SpriteEffects.None,
+ 0
+ );
+ spriteBatch.End();
+ }
+
+ public void Set(string key, string value)
+ {
+ _text[key] = value;
+ }
+
+ public void Log(string value)
+ {
+ _log.Add(value);
+ if (_log.Count > 30)
+ {
+ _log.RemoveAt(0);
+ }
+ }
+}
\ No newline at end of file
diff --git a/ZoFo/GameCore/GUI/MainMenuGUI.cs b/ZoFo/GameCore/GUI/MainMenuGUI.cs
index 850181d..cb259c7 100644
--- a/ZoFo/GameCore/GUI/MainMenuGUI.cs
+++ b/ZoFo/GameCore/GUI/MainMenuGUI.cs
@@ -9,19 +9,74 @@ using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonogameLibrary.UI.Base;
using MonogameLibrary.UI.Elements;
+using ZoFo.GameCore.GameManagers;
namespace ZoFo.GameCore.GUI;
public class MainMenuGUI : AbstractGUI
{
+ private DrawableUIElement menuBackground;
+ Color mainBackgroundColor = Color.White;
protected override void CreateUI()
{
- // int width = AppManager.Instance.inGameHUDHelperResolution.X;
- // int height = AppManager.Instance.inGameHUDHelperResolution.Y;
+ int width = AppManager.Instance.CurentScreenResolution.X;
+ int height = AppManager.Instance.CurentScreenResolution.Y;
+
+ menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), mainColor = mainBackgroundColor, textureName = "Textures\\GUI\\MenuBackground" };
+ Elements.Add(menuBackground);
+ menuBackground.LoadTexture(AppManager.Instance.Content);
+
+ Elements.Add(new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 5, (int)(width / 4), (int)(height / 20)), text = "ZoFo", fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font"});
+
+
+ Button playButton = new Button(Manager)
+ {
+ rectangle = new Rectangle(width / 2 - (int)(width / 10), height / 3 + height / 20 + height / 40, (int)(width / 5), (int)(height / 20)),
+ text = "Play",
+ scale = 0.2f,
+ fontColor = Color.White,
+ mainColor = Color.Gray,
+ fontName = "Fonts\\Font"
+ };
+ playButton.LeftButtonPressed += () =>
+ {
+
+ };
+ Elements.Add(playButton);
+ Button optionButton = new Button(Manager)
+ {
+ rectangle = new Rectangle(width / 2 - (int)(width / 10), height / 3 + (height / 20 + height / 40) * 2, (int)(width / 5), (int)(height / 20)),
+ text = "Options",
+ scale = 0.2f,
+ fontColor = Color.White,
+ mainColor = Color.Gray,
+ fontName = "Fonts\\Font"
+ };
+ optionButton.LeftButtonPressed += () =>
+ {
+
+ };
+ Elements.Add(optionButton);
+ Button exitButton = new Button(Manager)
+ {
+ rectangle = new Rectangle(width / 2 - (int)(width / 10), height / 3 + (height / 20 + height / 40) * 3, (int)(width / 5), (int)(height / 20)),
+ text = "Exit",
+ scale = 0.2f,
+ fontColor = Color.White,
+ mainColor = Color.Gray,
+ fontName = "Fonts\\Font"
+ };
+ exitButton.LeftButtonPressed += () =>
+ {
+ AppManager.Instance.Exit();
+ };
+ Elements.Add(exitButton);
+
+
}
public override void Update(GameTime gameTime)
{
-
+ base.Update(gameTime);
}
}
\ No newline at end of file
diff --git a/ZoFo/GameCore/GameManagers/AppManager.cs b/ZoFo/GameCore/GameManagers/AppManager.cs
index 495a618..2cb6d1d 100644
--- a/ZoFo/GameCore/GameManagers/AppManager.cs
+++ b/ZoFo/GameCore/GameManagers/AppManager.cs
@@ -8,8 +8,10 @@ using DangerousD.GameCore.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
+using ZoFo.GameCore.GameManagers.ItemManager;
using ZoFo.GameCore.GUI;
using static System.Collections.Specialized.BitVector32;
+using MonogameLibrary.UI.Base;
namespace ZoFo.GameCore.GameManagers
{
@@ -18,18 +20,22 @@ namespace ZoFo.GameCore.GameManagers
{
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
-
+
+
public static AppManager Instance { get; private set; }
public GameState gamestate;
public AbstractGUI currentGUI;
- //public Client client;
- //public Server server;
+ public DebugHUD debugHud;
+ public Point CurentScreenResolution = new Point(1920, 1080);
+ public Client client;
+ public Server server;
#region Managers
public InputManager InputManager;
+ public ItemManager.ItemManager ItemManager;
public AnimationBuilder animationBuilder{get;set; }
@@ -38,20 +44,28 @@ namespace ZoFo.GameCore.GameManagers
public AppManager()
{
_graphics = new GraphicsDeviceManager(this);
+ SetResolution(CurentScreenResolution.X, CurentScreenResolution.Y);
+ FulscrreenSwitch();
+
+
Content.RootDirectory = "Content";
IsMouseVisible = true;
Instance = this;
InputManager = new InputManager();
+
+
-
-
+ currentGUI = new MainMenuGUI();
+ debugHud = new DebugHUD();
}
protected override void Initialize()
{
-
+ currentGUI.Initialize();
+ debugHud.Initialize();
+
base.Initialize();
@@ -60,7 +74,8 @@ namespace ZoFo.GameCore.GameManagers
protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
-
+ debugHud.LoadContent();
+ currentGUI.LoadContent();
@@ -71,19 +86,21 @@ namespace ZoFo.GameCore.GameManagers
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
-
+
+ debugHud.Set("key", "value");
+
InputManager.Update();
- //currentGUI.Update();
+ currentGUI.Update(gameTime);
switch (gamestate)
{
case GameState.NotPlaying:
break;
case GameState.HostPlaying:
- //server.Update(GameTime gameTime);
- //client.Update(GameTime gameTime);
+ server.Update(gameTime);
+ client.Update(gameTime);
break;
case GameState.ClientPlaying:
- //server.Update(GameTime gameTime);
+ server.Update(gameTime);
break;
default:
break;
@@ -96,13 +113,15 @@ namespace ZoFo.GameCore.GameManagers
{
GraphicsDevice.Clear(Color.CornflowerBlue);
+
- //currentGUI.Draw(_spriteBatch);
+ debugHud.Draw(_spriteBatch);
+ currentGUI.Draw(_spriteBatch);
switch (gamestate)
{
case GameState.ClientPlaying:
case GameState.HostPlaying:
- //client.Draw(_spriteBatch);
+ client.Draw(_spriteBatch);
break;
case GameState.NotPlaying:
default:
@@ -118,13 +137,22 @@ namespace ZoFo.GameCore.GameManagers
public void SetGUI(AbstractGUI gui)
{
currentGUI = gui;
-
- //TODO
}
public void GameEnded(Dictionary lootIGot)
{
//TODO
}
+
+ public void SetResolution(int x, int y)
+ {
+ _graphics.PreferredBackBufferWidth = x;
+ _graphics.PreferredBackBufferHeight = y;
+ }
+
+ public void FulscrreenSwitch()
+ {
+ _graphics.IsFullScreen = !_graphics.IsFullScreen;
+ }
}
}
diff --git a/ZoFo/GameCore/GameManagers/ItemManager/EquippableItemInfo.cs b/ZoFo/GameCore/GameManagers/ItemManager/EquippableItemInfo.cs
new file mode 100644
index 0000000..5bffce5
--- /dev/null
+++ b/ZoFo/GameCore/GameManagers/ItemManager/EquippableItemInfo.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ZoFo.GameCore.GameManagers.ItemManager
+{
+ class EquippableItemInfo : ItemInfo
+ {
+ bool IsEquiped; //экипирован ли предмет
+ public EquippableItemInfo(string tag) : base(tag)
+ {
+
+ }
+ }
+}
diff --git a/ZoFo/GameCore/GameManagers/ItemManager/ItemInfo.cs b/ZoFo/GameCore/GameManagers/ItemManager/ItemInfo.cs
index 68873e4..375d745 100644
--- a/ZoFo/GameCore/GameManagers/ItemManager/ItemInfo.cs
+++ b/ZoFo/GameCore/GameManagers/ItemManager/ItemInfo.cs
@@ -15,10 +15,23 @@ namespace ZoFo.GameCore.GameManagers.ItemManager
Texture2D itemTexture;
bool isCraftable;
Dictionary resourcesNeededToCraft;
+ public ItemInfo (string tag)
+ {
+ this.tag = tag;
+ }
+ public ItemInfo(string tag,string textureName,bool isCraftable, Dictionary resourcesNeededToCraft)
+ {
+ this.tag = tag;
+ this.textureName = textureName;
+
+ this.isCraftable = isCraftable;
+ this.resourcesNeededToCraft = resourcesNeededToCraft;
+ }
//методы
- private void LoadTexture()
+ public void LoadTexture()
{
//я что-то хз как это
+ itemTexture=AppManager.Instance.Content.Load(textureName);
}
}
}
diff --git a/ZoFo/GameCore/GameManagers/ItemManager/ItemManager.cs b/ZoFo/GameCore/GameManagers/ItemManager/ItemManager.cs
index 3585ec4..6d00e0c 100644
--- a/ZoFo/GameCore/GameManagers/ItemManager/ItemManager.cs
+++ b/ZoFo/GameCore/GameManagers/ItemManager/ItemManager.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers.ItemManager
{
- class ItemManager
+ public class ItemManager
{
//поля
Dictionary tagItemPairs;
@@ -15,9 +15,18 @@ namespace ZoFo.GameCore.GameManagers.ItemManager
{
return tagItemPairs.GetValueOrDefault(tag);
}
- void LoadItemTexture()
+ void LoadItemTextures()
{
-
+ foreach (var item in tagItemPairs)
+ {
+ item.Value.LoadTexture();
+ }
+ }
+ void Initialize()
+ {
+ tagItemPairs.Add("wood", new ItemInfo("wood","wood",false,null));
+ tagItemPairs.Add("rock", new ItemInfo("rock", "rock", false, null));
+ tagItemPairs.Add("steel", new ItemInfo("steel", "steel", false, null));
}
}
diff --git a/ZoFo/GameCore/GameManagers/ItemManager/PlayerData.cs b/ZoFo/GameCore/GameManagers/ItemManager/PlayerData.cs
new file mode 100644
index 0000000..1dfc351
--- /dev/null
+++ b/ZoFo/GameCore/GameManagers/ItemManager/PlayerData.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ZoFo.GameCore.GameManagers.ItemManager
+{
+ ///
+ /// Класс хранит информацю о количестве ресурсов у игрока
+ ///
+ internal class PlayerData
+ {
+ Dictionary items;
+ ///
+ /// Принимает тэг и крафтит этот объект
+ ///
+ ///
+ public void CraftItem(string itemTag)
+ {
+ //TODO
+ }
+ }
+}
diff --git a/ZoFo/GameCore/GameManagers/ItemManager/WeaponItemInfo.cs b/ZoFo/GameCore/GameManagers/ItemManager/WeaponItemInfo.cs
index dcea75f..3917575 100644
--- a/ZoFo/GameCore/GameManagers/ItemManager/WeaponItemInfo.cs
+++ b/ZoFo/GameCore/GameManagers/ItemManager/WeaponItemInfo.cs
@@ -6,9 +6,13 @@ using System.Threading.Tasks;
namespace ZoFo.GameCore.GameManagers.ItemManager
{
- class WeaponItemInfo:ItemInfo
+ class WeaponItemInfo: EquippableItemInfo
{
//поля
float damage;
+
+ public WeaponItemInfo(string tag) : base(tag)
+ {
+ }
}
}
diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs
index 033cc30..ea57f60 100644
--- a/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs
+++ b/ZoFo/GameCore/GameManagers/NetworkManager/ClientNetworkManager.cs
@@ -1,55 +1,85 @@
using System;
+using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
+using System.Threading.Tasks;
+using ZoFo.GameCore.GameManagers.NetworkManager.Updates;
namespace ZoFo.GameCore.GameManagers.NetworkManager
{
public class ClientNetworkManager
{
- private IPAddress iPAddress = IPAddress.Any;
private int port = 7632;
private EndPoint endPoint;
private Socket socket;
- delegate void OnDataSent(string Data);
- event OnDataSent GetDataSent; // event
+ List updates = new List();
+ public delegate void OnDataSent(string Data);
+ public event OnDataSent GetDataSent; // event
public void Init() //create endPoint, socket
{
- endPoint = new IPEndPoint(iPAddress, port);
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
}
public void SendData()
{
-
+ while(socket.Connected)
+ {
+ byte[] bytes = Encoding.UTF8.GetBytes(updates.ToString());
+ socket.Send(bytes);
+ }
}
- public void JoinRoom() // multyplayer
+ public void StopConnection()
+ {
+ socket.Shutdown(SocketShutdown.Both);
+ socket.Close();
+ }
+
+ ///
+ /// приложение пытается подключиться к комнате
+ ///
+ ///
+ ///
+ public void JoinRoom(string ip) // multyplayer
{
+ endPoint = new IPEndPoint(IPAddress.Parse(ip), port);
+
+ socket.Connect(endPoint);
+
SendData();
- StartListening();
+ Thread listen = new Thread(StartListening);
+ listen.Start();
}
+ ///
+ /// создается
+ ///
public void JoinYourself() // single player
{
+ endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port);
+
+ socket.Connect(endPoint);
+
SendData();
- StartListening();
+ Thread listen = new Thread(StartListening);
+ listen.Start();
}
//поток 2
public void StartListening()
{
- socket.Connect(endPoint);
-
- byte[] bytes = new byte[2048];
-
- var countAnsw = socket.Receive(bytes);
-
- string updates = Encoding.UTF8.GetString(bytes, 0, countAnsw); // обновления отосланные сервером
+ while(socket.Connected)
+ {
+ byte[] bytes = new byte[2048];
+ var countAnsw = socket.Receive(bytes);
+ string update = Encoding.UTF8.GetString(bytes, 0, countAnsw); // обновление отосланные сервером
+ GetDataSent(update);
+ }
}
}
}
\ No newline at end of file
diff --git a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs
index 899f610..1e013a1 100644
--- a/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs
+++ b/ZoFo/GameCore/GameManagers/NetworkManager/ServerNetworkManager.cs
@@ -1,4 +1,5 @@
-using Microsoft.Xna.Framework.Graphics.PackedVector;
+using Microsoft.Xna.Framework.Graphics;
+using Microsoft.Xna.Framework.Graphics.PackedVector;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -21,44 +22,79 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
private Socket socket;
private List clients;
private List updates;
- delegate void OnDataSend(string data); //
+ public delegate void OnDataSend(string data);
+ public event OnDataSend GetDataSend; // event
+ Dictionary managerThread;
+
public void Init() //create Socket
{
endPoint = new IPEndPoint(ip, port);
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+ managerThread = new Dictionary();
}
-
- public void SendData()
+ public void SendData() //отправляет клиенту Data
{
-
+ string data = JsonSerializer.Serialize(updates);
+ var databytes = Encoding.UTF8.GetBytes(data);
+ foreach (var item in clients)
+ {
+ item.SendAsync(databytes);
+ }
+ }
+ public void AddData(IUpdateData data)//добавляет в лист updates новую data
+ {
+ updates.Add(data);
}
- public void AddData(IUpdateData data) { }
-
+ public void CloseConnection()
+ {
+ foreach (var item in clients)
+ {
+ item.Shutdown(SocketShutdown.Both);
+ item.Close();
+ }
+ foreach (var item in managerThread)
+ {
+ foreach (var socket in clients)
+ {
+ managerThread[socket].Interrupt();
+ }
+ }
+ managerThread.Clear();
+ clients.Clear();
+ }
//Поток 2
- public void StartWaitingForPlayers()//Слушает игроков, которые хотят подключиться
+
+ public void StartWaitingForPlayers(object players)//Слушает игроков, которые хотят подключиться
{
+ int playNumber = (int)players;
socket.Bind(endPoint);
- socket.Listen(10);
- for (int i = 0; i < 10; i++)
+ socket.Listen(playNumber);
+ for (int i = 0; i < playNumber; i++)
{
Socket client = socket.Accept();
+ Thread thread = new Thread(StartListening);
+ thread.Start(client);
+ managerThread.Add(client, thread);
clients.Add(client); //добавляем клиентов в лист
}
- StartListening();
}
- public void StartListening()//начать слушать клиентов в самой игре активируют Ивент
+ private void StartListening(object socket)//начать слушать клиентов в самой игре активируют Ивент
{
- var buff = new byte[1024];
- foreach (var client in clients)
+ // obj to Socket
+ Socket client = (Socket)socket;
+ while (client.Connected)
{
+ var buff = new byte[1024];
var answ = client.Receive(buff);
string response = Encoding.UTF8.GetString(buff, 0, answ);
- // List updateDatas =
+ GetDataSend(response);
}
+ Thread.Sleep(-1);
+
}
}
}
diff --git a/ZoFo/GameCore/GameObjects/Bullet.cs b/ZoFo/GameCore/GameObjects/AttackEntities/Bullet.cs
similarity index 100%
rename from ZoFo/GameCore/GameObjects/Bullet.cs
rename to ZoFo/GameCore/GameObjects/AttackEntities/Bullet.cs
diff --git a/ZoFo/GameCore/GameObjects/GunAttack.cs b/ZoFo/GameCore/GameObjects/AttackEntities/GunAttack.cs
similarity index 100%
rename from ZoFo/GameCore/GameObjects/GunAttack.cs
rename to ZoFo/GameCore/GameObjects/AttackEntities/GunAttack.cs
diff --git a/ZoFo/GameCore/GameObjects/HandAttack.cs b/ZoFo/GameCore/GameObjects/AttackEntities/HandAttack.cs
similarity index 100%
rename from ZoFo/GameCore/GameObjects/HandAttack.cs
rename to ZoFo/GameCore/GameObjects/AttackEntities/HandAttack.cs
diff --git a/ZoFo/GameCore/GameObjects/Rock.cs b/ZoFo/GameCore/GameObjects/AttackEntities/Rock.cs
similarity index 100%
rename from ZoFo/GameCore/GameObjects/Rock.cs
rename to ZoFo/GameCore/GameObjects/AttackEntities/Rock.cs
diff --git a/ZoFo/GameCore/GameObjects/SwordAttack.cs b/ZoFo/GameCore/GameObjects/AttackEntities/SwordAttack.cs
similarity index 100%
rename from ZoFo/GameCore/GameObjects/SwordAttack.cs
rename to ZoFo/GameCore/GameObjects/AttackEntities/SwordAttack.cs
diff --git a/ZoFo/GameCore/GameObjects/Collectable.cs b/ZoFo/GameCore/GameObjects/BaseClasses/Collectable.cs
similarity index 100%
rename from ZoFo/GameCore/GameObjects/Collectable.cs
rename to ZoFo/GameCore/GameObjects/BaseClasses/Collectable.cs
diff --git a/ZoFo/GameCore/GameObjects/Entity.cs b/ZoFo/GameCore/GameObjects/BaseClasses/Entity.cs
similarity index 100%
rename from ZoFo/GameCore/GameObjects/Entity.cs
rename to ZoFo/GameCore/GameObjects/BaseClasses/Entity.cs
diff --git a/ZoFo/GameCore/GameObjects/GameObject.cs b/ZoFo/GameCore/GameObjects/BaseClasses/GameObject.cs
similarity index 100%
rename from ZoFo/GameCore/GameObjects/GameObject.cs
rename to ZoFo/GameCore/GameObjects/BaseClasses/GameObject.cs
diff --git a/ZoFo/GameCore/GameObjects/LivingEntity.cs b/ZoFo/GameCore/GameObjects/BaseClasses/LivingEntity.cs
similarity index 100%
rename from ZoFo/GameCore/GameObjects/LivingEntity.cs
rename to ZoFo/GameCore/GameObjects/BaseClasses/LivingEntity.cs
diff --git a/ZoFo/GameCore/GameObjects/IPlayerWeaponAttack.cs b/ZoFo/GameCore/GameObjects/Player/IPlayerWeaponAttack.cs
similarity index 100%
rename from ZoFo/GameCore/GameObjects/IPlayerWeaponAttack.cs
rename to ZoFo/GameCore/GameObjects/Player/IPlayerWeaponAttack.cs
diff --git a/ZoFo/GameCore/GameObjects/LootData.cs b/ZoFo/GameCore/GameObjects/Player/LootData.cs
similarity index 100%
rename from ZoFo/GameCore/GameObjects/LootData.cs
rename to ZoFo/GameCore/GameObjects/Player/LootData.cs
diff --git a/ZoFo/GameCore/GameObjects/Player.cs b/ZoFo/GameCore/GameObjects/Player/Player.cs
similarity index 100%
rename from ZoFo/GameCore/GameObjects/Player.cs
rename to ZoFo/GameCore/GameObjects/Player/Player.cs
diff --git a/ZoFo/GameCore/GameObjects/StopObject.cs b/ZoFo/GameCore/GameObjects/Tiles/StopObject.cs
similarity index 100%
rename from ZoFo/GameCore/GameObjects/StopObject.cs
rename to ZoFo/GameCore/GameObjects/Tiles/StopObject.cs
diff --git a/ZoFo/GameCore/GameObjects/Tile.cs b/ZoFo/GameCore/GameObjects/Tiles/Tile.cs
similarity index 100%
rename from ZoFo/GameCore/GameObjects/Tile.cs
rename to ZoFo/GameCore/GameObjects/Tiles/Tile.cs
diff --git a/ZoFo/GameCore/Server.cs b/ZoFo/GameCore/Server.cs
index 948ee0e..8be4c50 100644
--- a/ZoFo/GameCore/Server.cs
+++ b/ZoFo/GameCore/Server.cs
@@ -1,8 +1,13 @@
-using System;
+using Microsoft.Xna.Framework;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using System.Text.Json;
using System.Threading.Tasks;
+using ZoFo.GameCore.GameManagers.NetworkManager;
+using ZoFo.GameCore.GameManagers.NetworkManager.Updates;
+using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient;
using ZoFo.GameCore.GameObjects;
namespace ZoFo.GameCore
@@ -10,13 +15,35 @@ namespace ZoFo.GameCore
public class Server
{
private List gameObjects;
- // private List<> entity; //entity
+ private ServerNetworkManager networkManager;
+ // private List<> entity; //entity
+ public Server()
+ {
+ networkManager = new ServerNetworkManager();
+ networkManager.GetDataSend += OnDataSend;
+ }
- public void OnDataSend(string data) { }
- public void CreateRoom() { }
- public void StartGame() { }
- public void EndGame() { }
+ public void OnDataSend(string data)
+ {
+ List updateDatas = JsonSerializer.Deserialize>(data);
+ //ТУТ Switch case будет честное слово
+ }
+ public void CreateRoom(int players) {
+ networkManager.StartWaitingForPlayers(players);
+ }
+ // public void StartGame() { } принудительный запуск
+ public void EndGame() {
+ UpdateGameEnded gameEnded = new UpdateGameEnded();
+ networkManager.AddData(gameEnded);
+ }
+ internal void Update(GameTime gameTime)
+ {
+ }
+ public void RegisterEntity(GameObject gameObject)
+ {
+ gameObjects.Add(gameObject);
+ }
}
}
diff --git a/ZoFo/ZoFo.csproj b/ZoFo/ZoFo.csproj
index afb5dfe..747eafe 100644
--- a/ZoFo/ZoFo.csproj
+++ b/ZoFo/ZoFo.csproj
@@ -26,6 +26,9 @@
+
+
+