Merge branch 'Development' into Collision
This commit is contained in:
commit
9e4a14a92e
35 changed files with 564 additions and 66 deletions
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
BIN
ZoFo/Content/Fonts/CarltineRegular-K7z5l.ttf
Normal file
BIN
ZoFo/Content/Fonts/CarltineRegular-K7z5l.ttf
Normal file
Binary file not shown.
BIN
ZoFo/Content/Fonts/Debrosee-ALPnL.ttf
Normal file
BIN
ZoFo/Content/Fonts/Debrosee-ALPnL.ttf
Normal file
Binary file not shown.
60
ZoFo/Content/Fonts/Font.spritefont
Normal file
60
ZoFo/Content/Fonts/Font.spritefont
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
This file contains an xml description of a font, and will be read by the XNA
|
||||
Framework Content Pipeline. Follow the comments to customize the appearance
|
||||
of the font in your game, and to change the characters which are available to draw
|
||||
with.
|
||||
-->
|
||||
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
|
||||
<Asset Type="Graphics:FontDescription">
|
||||
|
||||
<!--
|
||||
Modify this string to change the font that will be imported.
|
||||
-->
|
||||
<FontName>Debrosee-ALPnL.ttf</FontName>
|
||||
|
||||
<!--
|
||||
Size is a float value, measured in points. Modify this value to change
|
||||
the size of the font.
|
||||
-->
|
||||
<Size>100</Size>
|
||||
|
||||
<!--
|
||||
Spacing is a float value, measured in pixels. Modify this value to change
|
||||
the amount of spacing in between characters.
|
||||
-->
|
||||
<Spacing>0</Spacing>
|
||||
|
||||
<!--
|
||||
UseKerning controls the layout of the font. If this value is true, kerning information
|
||||
will be used when placing characters.
|
||||
-->
|
||||
<UseKerning>true</UseKerning>
|
||||
|
||||
<!--
|
||||
Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",
|
||||
and "Bold, Italic", and are case sensitive.
|
||||
-->
|
||||
<Style>Regular</Style>
|
||||
|
||||
<!--
|
||||
If you uncomment this line, the default character will be substituted if you draw
|
||||
or measure text that contains characters which were not included in the font.
|
||||
-->
|
||||
<!-- <DefaultCharacter>*</DefaultCharacter> -->
|
||||
|
||||
<!--
|
||||
CharacterRegions control what letters are available in the font. Every
|
||||
character from Start to End will be built and made available for drawing. The
|
||||
default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
|
||||
character set. The characters are ordered according to the Unicode standard.
|
||||
See the documentation for more information.
|
||||
-->
|
||||
<CharacterRegions>
|
||||
<CharacterRegion>
|
||||
<Start> </Start>
|
||||
<End>~</End>
|
||||
</CharacterRegion>
|
||||
</CharacterRegions>
|
||||
</Asset>
|
||||
</XnaContent>
|
60
ZoFo/Content/Fonts/Font2.spritefont
Normal file
60
ZoFo/Content/Fonts/Font2.spritefont
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
This file contains an xml description of a font, and will be read by the XNA
|
||||
Framework Content Pipeline. Follow the comments to customize the appearance
|
||||
of the font in your game, and to change the characters which are available to draw
|
||||
with.
|
||||
-->
|
||||
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
|
||||
<Asset Type="Graphics:FontDescription">
|
||||
|
||||
<!--
|
||||
Modify this string to change the font that will be imported.
|
||||
-->
|
||||
<FontName>CarltineRegular-K7z5l.ttf</FontName>
|
||||
|
||||
<!--
|
||||
Size is a float value, measured in points. Modify this value to change
|
||||
the size of the font.
|
||||
-->
|
||||
<Size>15</Size>
|
||||
|
||||
<!--
|
||||
Spacing is a float value, measured in pixels. Modify this value to change
|
||||
the amount of spacing in between characters.
|
||||
-->
|
||||
<Spacing>0</Spacing>
|
||||
|
||||
<!--
|
||||
UseKerning controls the layout of the font. If this value is true, kerning information
|
||||
will be used when placing characters.
|
||||
-->
|
||||
<UseKerning>true</UseKerning>
|
||||
|
||||
<!--
|
||||
Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",
|
||||
and "Bold, Italic", and are case sensitive.
|
||||
-->
|
||||
<Style>Regular</Style>
|
||||
|
||||
<!--
|
||||
If you uncomment this line, the default character will be substituted if you draw
|
||||
or measure text that contains characters which were not included in the font.
|
||||
-->
|
||||
<!-- <DefaultCharacter>*</DefaultCharacter> -->
|
||||
|
||||
<!--
|
||||
CharacterRegions control what letters are available in the font. Every
|
||||
character from Start to End will be built and made available for drawing. The
|
||||
default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
|
||||
character set. The characters are ordered according to the Unicode standard.
|
||||
See the documentation for more information.
|
||||
-->
|
||||
<CharacterRegions>
|
||||
<CharacterRegion>
|
||||
<Start> </Start>
|
||||
<End>~</End>
|
||||
</CharacterRegion>
|
||||
</CharacterRegions>
|
||||
</Asset>
|
||||
</XnaContent>
|
BIN
ZoFo/Content/Textures/GUI/MenuBackground.jpg
Normal file
BIN
ZoFo/Content/Textures/GUI/MenuBackground.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 592 KiB |
|
@ -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<IUpdateData> updateDatas = JsonSerializer.Deserialize<List<IUpdateData>>(data);
|
||||
// тут будет switch
|
||||
}
|
||||
|
||||
public void GameEndedUnexpectedly(){ }
|
||||
|
||||
public void JoinRoom(){ }
|
||||
|
||||
public void JoinYourself(){ }
|
||||
|
||||
internal void Update(GameTime gameTime)
|
||||
{
|
||||
}
|
||||
|
||||
internal void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
72
ZoFo/GameCore/GUI/DebugHUD.cs
Normal file
72
ZoFo/GameCore/GUI/DebugHUD.cs
Normal file
|
@ -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<string, string> _text = new();
|
||||
private List<string> _log = new();
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
}
|
||||
|
||||
public void LoadContent()
|
||||
{
|
||||
_spriteFont = AppManager.Instance.Content.Load<SpriteFont>("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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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<string, int> lootIGot)
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
public void SetResolution(int x, int y)
|
||||
{
|
||||
_graphics.PreferredBackBufferWidth = x;
|
||||
_graphics.PreferredBackBufferHeight = y;
|
||||
}
|
||||
|
||||
public void FulscrreenSwitch()
|
||||
{
|
||||
_graphics.IsFullScreen = !_graphics.IsFullScreen;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
17
ZoFo/GameCore/GameManagers/ItemManager/EquippableItemInfo.cs
Normal file
17
ZoFo/GameCore/GameManagers/ItemManager/EquippableItemInfo.cs
Normal file
|
@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,10 +15,23 @@ namespace ZoFo.GameCore.GameManagers.ItemManager
|
|||
Texture2D itemTexture;
|
||||
bool isCraftable;
|
||||
Dictionary<string, int> resourcesNeededToCraft;
|
||||
public ItemInfo (string tag)
|
||||
{
|
||||
this.tag = tag;
|
||||
}
|
||||
public ItemInfo(string tag,string textureName,bool isCraftable, Dictionary<string, int> resourcesNeededToCraft)
|
||||
{
|
||||
this.tag = tag;
|
||||
this.textureName = textureName;
|
||||
|
||||
this.isCraftable = isCraftable;
|
||||
this.resourcesNeededToCraft = resourcesNeededToCraft;
|
||||
}
|
||||
//методы
|
||||
private void LoadTexture()
|
||||
public void LoadTexture()
|
||||
{
|
||||
//я что-то хз как это
|
||||
itemTexture=AppManager.Instance.Content.Load<Texture2D>(textureName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace ZoFo.GameCore.GameManagers.ItemManager
|
||||
{
|
||||
class ItemManager
|
||||
public class ItemManager
|
||||
{
|
||||
//поля
|
||||
Dictionary<string, ItemInfo> 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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
24
ZoFo/GameCore/GameManagers/ItemManager/PlayerData.cs
Normal file
24
ZoFo/GameCore/GameManagers/ItemManager/PlayerData.cs
Normal file
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс хранит информацю о количестве ресурсов у игрока
|
||||
/// </summary>
|
||||
internal class PlayerData
|
||||
{
|
||||
Dictionary<string, int> items;
|
||||
/// <summary>
|
||||
/// Принимает тэг и крафтит этот объект
|
||||
/// </summary>
|
||||
/// <param name="itemTag"></param>
|
||||
public void CraftItem(string itemTag)
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<IUpdateData> updates = new List<IUpdateData>();
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// приложение пытается подключиться к комнате
|
||||
/// </summary>
|
||||
/// <param name="ip"></param>
|
||||
/// <param name="port"></param>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// создается
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<Socket> clients;
|
||||
private List<IUpdateData> updates;
|
||||
delegate void OnDataSend(string data); //
|
||||
public delegate void OnDataSend(string data);
|
||||
public event OnDataSend GetDataSend; // event
|
||||
Dictionary<Socket, Thread> managerThread;
|
||||
|
||||
|
||||
public void Init() //create Socket
|
||||
{
|
||||
endPoint = new IPEndPoint(ip, port);
|
||||
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
managerThread = new Dictionary<Socket, Thread>();
|
||||
}
|
||||
|
||||
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<IUpdateData> updateDatas =
|
||||
GetDataSend(response);
|
||||
}
|
||||
Thread.Sleep(-1);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<GameObject> 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<IUpdateData> updateDatas = JsonSerializer.Deserialize<List<IUpdateData>>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,9 @@
|
|||
<ItemGroup>
|
||||
<ProjectReference Include="..\MonogameLibrary\MonogameLibrary.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Content\Textures\GUI\" />
|
||||
</ItemGroup>
|
||||
<Target Name="RestoreDotnetTools" BeforeTargets="Restore">
|
||||
<Message Text="Restoring dotnet tools" Importance="High" />
|
||||
<Exec Command="dotnet tool restore" />
|
||||
|
|
Loading…
Add table
Reference in a new issue