merge
|
@ -21,7 +21,7 @@ namespace MonogameLibrary.UI.Elements
|
|||
public int indentation = 5;
|
||||
|
||||
Texture2D texture2;
|
||||
public Rectangle sliderRect = new Rectangle(0, 0, 30, 30);
|
||||
public Rectangle sliderRect = new Rectangle(0, 0, 40, 40);
|
||||
private float sliderValue = 0;
|
||||
private float minValue = 0, maxValue = 1;
|
||||
SliderState sliderState = SliderState.None;
|
||||
|
@ -56,7 +56,7 @@ namespace MonogameLibrary.UI.Elements
|
|||
|
||||
public override void LoadTexture(ContentManager content)
|
||||
{
|
||||
texture2 = content.Load<Texture2D>("Textures\\GUI\\checkboxs_off");
|
||||
texture2 = content.Load<Texture2D>("Textures\\GUI\\switch");
|
||||
base.LoadTexture(content);
|
||||
}
|
||||
|
||||
|
@ -73,11 +73,11 @@ namespace MonogameLibrary.UI.Elements
|
|||
sliderRect.X += (int)(sliderValue * (rectangle.Width - sliderRect.Width - indentation * 2) + indentation);
|
||||
sliderRect.Y -= sliderRect.Height / 2 - rectangle.Height / 2;
|
||||
if (sliderState == SliderState.Moving)
|
||||
_spriteBatch.Draw(texture2, sliderRect, Color.DarkRed);
|
||||
_spriteBatch.Draw(texture2, sliderRect, Color.Gray);
|
||||
else if(sliderState == SliderState.HoveringOverSliderButton)
|
||||
_spriteBatch.Draw(texture2, sliderRect, new Color(200,0 ,0));
|
||||
_spriteBatch.Draw(texture2, sliderRect, Color.DarkGray);
|
||||
else
|
||||
_spriteBatch.Draw(texture2, sliderRect, Color.Red);
|
||||
_spriteBatch.Draw(texture2, sliderRect, Color.White);
|
||||
DrawText(_spriteBatch);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,13 @@
|
|||
/processorParam:TextureFormat=Compressed
|
||||
/build:Fonts/Font2.spritefont
|
||||
|
||||
#begin Fonts/Font3.spritefont
|
||||
/importer:FontDescriptionImporter
|
||||
/processor:FontDescriptionProcessor
|
||||
/processorParam:PremultiplyAlpha=True
|
||||
/processorParam:TextureFormat=Compressed
|
||||
/build:Fonts/Font3.spritefont
|
||||
|
||||
#begin Textures/GUI/checkboxs_off-on.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
|
@ -75,3 +82,39 @@
|
|||
/processorParam:TextureFormat=Color
|
||||
/build:Textures/GUI/MenuBackground.jpg
|
||||
|
||||
#begin Textures/GUI/mouse.png
|
||||
/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/mouse.png
|
||||
|
||||
#begin Textures/GUI/Switch_backgrownd.png
|
||||
/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/Switch_backgrownd.png
|
||||
|
||||
#begin Textures/GUI/switch.png
|
||||
/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/switch.png
|
||||
|
||||
|
|
60
ZoFo/Content/Fonts/Font3.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>MouldyCheeseRegular-WyMWG.ttf</FontName>
|
||||
|
||||
<!--
|
||||
Size is a float value, measured in points. Modify this value to change
|
||||
the size of the font.
|
||||
-->
|
||||
<Size>50</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/Fonts/MouldyCheeseRegular-WyMWG.ttf
Normal file
BIN
ZoFo/Content/Textures/GUI/Switch_backgrownd.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 5.1 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 2 KiB |
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.9 KiB |
BIN
ZoFo/Content/Textures/GUI/mouse.png
Normal file
After Width: | Height: | Size: 234 KiB |
BIN
ZoFo/Content/Textures/GUI/switch.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
|
@ -27,10 +27,12 @@ namespace ZoFo.GameCore
|
|||
|
||||
public void GameEndedUnexpectedly(){ }
|
||||
|
||||
public void JoinRoom(){ }
|
||||
|
||||
public void JoinYourself(){ }
|
||||
public void JoinRoom(string ip)
|
||||
{
|
||||
networkManager.JoinRoom(ip);
|
||||
}
|
||||
|
||||
public void JoinYourself(){ networkManager.JoinYourself(); }
|
||||
internal void Update(GameTime gameTime)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ public abstract class AbstractGUI
|
|||
protected DrawableUIElement SelectedElement;
|
||||
private bool isStartedPrint = false;
|
||||
private bool isPressed = false;
|
||||
private Texture2D mouse;
|
||||
private MouseState mouseState;
|
||||
|
||||
public AbstractGUI()
|
||||
{
|
||||
|
@ -37,20 +39,20 @@ public abstract class AbstractGUI
|
|||
public virtual void LoadContent()
|
||||
{
|
||||
Manager.LoadContent(AppManager.Instance.Content, "Font");
|
||||
mouse = AppManager.Instance.Content.Load<Texture2D>("Textures\\GUI\\mouse");
|
||||
}
|
||||
|
||||
public virtual void Update(GameTime gameTime)
|
||||
{
|
||||
Manager.Update(gameTime);
|
||||
mouseState = Mouse.GetState();
|
||||
}
|
||||
|
||||
public virtual void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
Manager.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
public virtual void ResolutioChenges()
|
||||
{
|
||||
|
||||
spriteBatch.Begin();
|
||||
spriteBatch.Draw(mouse, new Rectangle(mouseState.Position.X, mouseState.Position.Y, 20, 40), Color.Red);
|
||||
spriteBatch.End();
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Xml;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
|
@ -39,7 +40,7 @@ public class MainMenuGUI : AbstractGUI
|
|||
};
|
||||
playButton.LeftButtonPressed += () =>
|
||||
{
|
||||
|
||||
AppManager.Instance.SetGUI(new SelectModeMenu());
|
||||
};
|
||||
Elements.Add(playButton);
|
||||
Button optionButton = new Button(Manager)
|
||||
|
@ -73,7 +74,6 @@ public class MainMenuGUI : AbstractGUI
|
|||
|
||||
|
||||
}
|
||||
|
||||
public override void Update(GameTime gameTime)
|
||||
{
|
||||
base.Update(gameTime);
|
||||
|
|
|
@ -30,11 +30,11 @@ public class OptionsGUI : AbstractGUI
|
|||
|
||||
|
||||
Label label_OverallVolume = new Label(Manager)
|
||||
{ fontName = "Fonts\\Font", scale = 0.2f, text = "All Volume", fontColor = Color.White, rectangle = new Rectangle(width / 3, height / 3, 50, 50), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left };
|
||||
{ fontName = "Fonts\\Font", scale = 0.2f, text = "All Volume", fontColor = Color.White, rectangle = new Rectangle(width / 3, height / 3, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left };
|
||||
Elements.Add(label_OverallVolume);
|
||||
|
||||
var slider_OverallVolume = new Slider(Manager)
|
||||
{ rectangle = new Rectangle(width / 2, height / 3, width / 10, height / 20), indentation = 4, textureName = "Textures\\GUI\\checkbox_on", MinValue = 0, MaxValue = 1 };
|
||||
{ rectangle = new Rectangle(width / 2, height / 3, width / 10, height / 20), indentation = 4, textureName = "Textures\\GUI\\Switch_backgrownd", MinValue = 0, MaxValue = 1 };
|
||||
slider_OverallVolume.SliderChanged += (newVal) =>
|
||||
{
|
||||
|
||||
|
@ -42,11 +42,11 @@ public class OptionsGUI : AbstractGUI
|
|||
Elements.Add(slider_OverallVolume);
|
||||
|
||||
Label label_MusicVolume = new Label(Manager)
|
||||
{ fontName = "Fonts\\Font", scale = 0.2f, text = "Music Volume", fontColor = Color.White, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 1, 50, 50), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left };
|
||||
{ fontName = "Fonts\\Font", scale = 0.2f, text = "Music Volume", fontColor = Color.White, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 1, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left };
|
||||
Elements.Add(label_MusicVolume);
|
||||
|
||||
var slider_MusicVolume = new Slider(Manager)
|
||||
{ rectangle = new Rectangle(width / 2, height / 3 + (height / 20 + height / 40) * 1, width / 10, height / 20), indentation = 4, textureName = "Textures\\GUI\\checkboxs_on", MinValue = 0, MaxValue = 1 };
|
||||
{ rectangle = new Rectangle(width / 2, height / 3 + (height / 20 + height / 40) * 1, width / 10, height / 20), indentation = 4, textureName = "Textures\\GUI\\Switch_backgrownd", MinValue = 0, MaxValue = 1 };
|
||||
slider_MusicVolume.SliderChanged += (newVal) =>
|
||||
{
|
||||
|
||||
|
@ -55,11 +55,11 @@ public class OptionsGUI : AbstractGUI
|
|||
|
||||
|
||||
Label label_EffectsVolume = new Label(Manager)
|
||||
{ fontName = "Fonts\\Font", scale = 0.2f, text = "Effects Volume", fontColor = Color.White, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 2, 50, 50), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left };
|
||||
{ fontName = "Fonts\\Font", scale = 0.2f, text = "Effects Volume", fontColor = Color.White, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 2, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left };
|
||||
Elements.Add(label_EffectsVolume);
|
||||
|
||||
var slider_EffectsVolume = new Slider(Manager)
|
||||
{ rectangle = new Rectangle(width / 2, height / 3 + (height / 20 + height / 40) * 2, width / 10, height / 20), indentation = 4, textureName = "Textures\\GUI\\checkboxs_on", MinValue = 0, MaxValue = 1 };
|
||||
{ rectangle = new Rectangle(width / 2, height / 3 + (height / 20 + height / 40) * 2, width / 10, height / 20), indentation = 4, textureName = "Textures\\GUI\\Switch_backgrownd", MinValue = 0, MaxValue = 1 };
|
||||
slider_EffectsVolume.SliderChanged += (newVal) =>
|
||||
{
|
||||
|
||||
|
@ -67,7 +67,7 @@ public class OptionsGUI : AbstractGUI
|
|||
Elements.Add(slider_EffectsVolume);
|
||||
|
||||
Label lblSwitchMode = new Label(Manager)
|
||||
{ fontName = "Fonts\\Font", scale = 0.2f, text = "Left/Right Mode", fontColor = Color.White, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 3, 50, 50), mainColor = Color.Transparent};
|
||||
{ fontName = "Fonts\\Font", scale = 0.2f, text = "Resolution set", fontColor = Color.White, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 3, width / 40, height / 20), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left };
|
||||
Elements.Add(lblSwitchMode);
|
||||
|
||||
//var button_left_right_mode = new CheckBox(Manager) { rectangle = new Rectangle(rightBorder - checkboxlength, lblSwitchMode.rectangle.Y - 12, checkboxlength, checkboxlength) };
|
||||
|
@ -76,10 +76,10 @@ public class OptionsGUI : AbstractGUI
|
|||
|
||||
|
||||
Label label_IsFullScreen = new Label(Manager)
|
||||
{ fontName = "Fonts\\Font", scale = 0.2f, text = "Full Screen", fontColor = Color.White, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 4, 50, 50), mainColor = Color.Transparent};
|
||||
{ fontName = "Fonts\\Font", scale = 0.2f, text = "Full Screen", fontColor = Color.White, rectangle = new Rectangle(width / 3, height / 3 + (height / 20 + height / 40) * 4, width / 40, width / 40), mainColor = Color.Transparent, textAligment = MonogameLibrary.UI.Enums.TextAligment.Left };
|
||||
Elements.Add(label_IsFullScreen);
|
||||
|
||||
var button_FullScreen = new CheckBox(Manager) { rectangle = new Rectangle(width / 2, height / 3 + (height / 20 + height / 40) * 4, width / 30, width / 30) };
|
||||
var button_FullScreen = new CheckBox(Manager) { rectangle = new Rectangle(width / 2, height / 3 + (height / 20 + height / 40) * 4, width / 40, width / 40) };
|
||||
button_FullScreen.Checked += (newCheckState) =>
|
||||
{
|
||||
|
||||
|
@ -88,11 +88,11 @@ public class OptionsGUI : AbstractGUI
|
|||
|
||||
|
||||
Button bTExit = new Button(Manager)
|
||||
{ fontName = "Fonts\\Font", scale = 0.2f, text = "<-", rectangle = new Rectangle(width / 30, height / 30, 40, 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);
|
||||
bTExit.LeftButtonPressed += () =>
|
||||
{
|
||||
|
||||
AppManager.Instance.SetGUI(new MainMenuGUI());
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -9,19 +9,60 @@ 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 SelectModeMenu : AbstractGUI
|
||||
{
|
||||
private DrawableUIElement menuBackground;
|
||||
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 = Color.White, 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 / 6, (int)(width / 4), (int)(height / 20)), text = "Select mode", fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font"});
|
||||
|
||||
Button playButton = new Button(Manager)
|
||||
{
|
||||
rectangle = new Rectangle(width / 4 - (width / 7) / 2, height / 2, (int)(width / 7), (int)(height / 20)),
|
||||
text = "singleplayer",
|
||||
scale = 0.3f,
|
||||
fontColor = Color.White,
|
||||
mainColor = Color.Gray,
|
||||
fontName = "Fonts\\Font"
|
||||
};
|
||||
playButton.LeftButtonPressed += () =>
|
||||
{
|
||||
// single
|
||||
|
||||
// ваш код здесь
|
||||
};
|
||||
Elements.Add(playButton);
|
||||
Button optionButton = new Button(Manager)
|
||||
{
|
||||
rectangle = new Rectangle(width / 2 + width / 4 - (width / 7) / 2, height / 2, (int)(width / 7), (int)(height / 20)),
|
||||
text = "multiplayer",
|
||||
scale = 0.3f,
|
||||
fontColor = Color.White,
|
||||
mainColor = Color.Gray,
|
||||
fontName = "Fonts\\Font"
|
||||
};
|
||||
optionButton.LeftButtonPressed += () =>
|
||||
{
|
||||
// multi
|
||||
|
||||
// ваш код здесь
|
||||
};
|
||||
Elements.Add(optionButton);
|
||||
}
|
||||
|
||||
public override void Update(GameTime gameTime)
|
||||
{
|
||||
|
||||
base.Update(gameTime);
|
||||
}
|
||||
}
|
|
@ -45,7 +45,7 @@ namespace ZoFo.GameCore.GameManagers
|
|||
{
|
||||
_graphics = new GraphicsDeviceManager(this);
|
||||
SetResolution(CurentScreenResolution.X, CurentScreenResolution.Y);
|
||||
FulscrreenSwitch();
|
||||
// FulscrreenSwitch();
|
||||
|
||||
|
||||
Content.RootDirectory = "Content";
|
||||
|
@ -58,6 +58,7 @@ namespace ZoFo.GameCore.GameManagers
|
|||
|
||||
currentGUI = new MainMenuGUI();
|
||||
debugHud = new DebugHUD();
|
||||
IsMouseVisible = false;
|
||||
|
||||
}
|
||||
|
||||
|
@ -67,7 +68,6 @@ namespace ZoFo.GameCore.GameManagers
|
|||
debugHud.Initialize();
|
||||
|
||||
|
||||
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
|
@ -115,8 +115,8 @@ namespace ZoFo.GameCore.GameManagers
|
|||
|
||||
|
||||
|
||||
debugHud.Draw(_spriteBatch);
|
||||
currentGUI.Draw(_spriteBatch);
|
||||
debugHud.Draw(_spriteBatch);
|
||||
switch (gamestate)
|
||||
{
|
||||
case GameState.ClientPlaying:
|
||||
|
@ -158,5 +158,8 @@ namespace ZoFo.GameCore.GameManagers
|
|||
{
|
||||
_graphics.IsFullScreen = !_graphics.IsFullScreen;
|
||||
}
|
||||
|
||||
public void SetServer(Server server) { this.server = server; }
|
||||
public void SetClient(Client client) { this.client = client; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ using System.Net;
|
|||
using System.Net.Sockets;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ZoFo.GameCore.GameManagers.NetworkManager.Updates;
|
||||
|
@ -20,6 +21,12 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
List<IUpdateData> updates = new List<IUpdateData>();
|
||||
public delegate void OnDataSent(string Data);
|
||||
public event OnDataSent GetDataSent; // event
|
||||
|
||||
public ClientNetworkManager()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
public void Init() //create endPoint, socket
|
||||
{
|
||||
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
|
@ -27,11 +34,13 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
|
||||
public void SendData()
|
||||
{
|
||||
while(socket.Connected)
|
||||
{
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(updates.ToString());
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(updates)); //нужно сериализовать
|
||||
socket.Send(bytes);
|
||||
}
|
||||
|
||||
public void AddData(IUpdateData UpdateData)
|
||||
{
|
||||
updates.Add(UpdateData);
|
||||
}
|
||||
|
||||
public void StopConnection()
|
||||
|
@ -47,10 +56,9 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
/// <param name="port"></param>
|
||||
public void JoinRoom(string ip) // multyplayer
|
||||
{
|
||||
|
||||
endPoint = new IPEndPoint(IPAddress.Parse(ip), port);
|
||||
|
||||
socket.Connect(endPoint);
|
||||
|
||||
SendData();
|
||||
Thread listen = new Thread(StartListening);
|
||||
listen.Start();
|
||||
|
@ -62,9 +70,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
public void JoinYourself() // single player
|
||||
{
|
||||
endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port);
|
||||
|
||||
socket.Connect(endPoint);
|
||||
|
||||
SendData();
|
||||
Thread listen = new Thread(StartListening);
|
||||
listen.Start();
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
{
|
||||
public class ServerNetworkManager
|
||||
{
|
||||
private IPAddress ip = IPAddress.Any;
|
||||
private IPAddress ip =IPAddress.Parse("127.0.0.1"); //IPAddress.Any
|
||||
private int port = 7632;
|
||||
private IPEndPoint endPoint;
|
||||
private Socket socket;
|
||||
|
@ -25,12 +25,18 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
public delegate void OnDataSend(string data);
|
||||
public event OnDataSend GetDataSend; // event
|
||||
Dictionary<Socket, Thread> managerThread;
|
||||
Thread serverTheread;
|
||||
|
||||
public ServerNetworkManager() { Init(); }
|
||||
|
||||
public void Init() //create Socket
|
||||
{
|
||||
endPoint = new IPEndPoint(ip, port);
|
||||
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
managerThread = new Dictionary<Socket, Thread>();
|
||||
clients = new List<Socket>();
|
||||
updates = new List<IUpdateData>();
|
||||
managerThread = new Dictionary<Socket, Thread>();
|
||||
}
|
||||
/// <summary>
|
||||
/// отправляет клиенту Data
|
||||
|
@ -52,7 +58,6 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
{
|
||||
updates.Add(data);
|
||||
}
|
||||
|
||||
public void CloseConnection() //По сути коне игры и отключение игроков
|
||||
{
|
||||
foreach (var item in clients)
|
||||
|
@ -74,6 +79,12 @@ namespace ZoFo.GameCore.GameManagers.NetworkManager
|
|||
clients.Clear();
|
||||
}
|
||||
|
||||
public void Start(object players)
|
||||
{
|
||||
serverTheread = new Thread(StartWaitingForPlayers);
|
||||
serverTheread.Start(players);
|
||||
}
|
||||
|
||||
//Потоки Клиентов
|
||||
public void StartWaitingForPlayers(object players)//Слушает игроков, которые хотят подключиться
|
||||
{
|
||||
|
|
|
@ -37,20 +37,26 @@ namespace ZoFo.GameCore
|
|||
{
|
||||
networkManager.AddData(data);
|
||||
}
|
||||
public void CreateRoom(int players) //Создает комнату и запускает ожидание подключений
|
||||
/// <summary>
|
||||
/// Создает комнату и запускает ожидание подключений
|
||||
/// </summary>
|
||||
/// <param name="players"></param>
|
||||
public void CreateRoom(int players)
|
||||
{
|
||||
networkManager.StartWaitingForPlayers(players);
|
||||
networkManager.Start(players);
|
||||
}
|
||||
|
||||
// public void StartGame() { } принудительный запуск
|
||||
public void EndGame() //Добавляет UpdateGameEnded и отключает игроков
|
||||
|
||||
/// <summary>
|
||||
/// Добавляет UpdateGameEnded и отключает игроков
|
||||
/// </summary>
|
||||
public void EndGame()
|
||||
{
|
||||
UpdateGameEnded gameEnded = new UpdateGameEnded();
|
||||
networkManager.AddData(gameEnded);
|
||||
networkManager.CloseConnection();
|
||||
}
|
||||
|
||||
|
||||
public void Update(GameTime gameTime)
|
||||
{
|
||||
}
|
||||
|
|