diff --git a/MudEngine/WinPC.Engine/Commands/InvalidCommand.cs b/MudEngine/WinPC.Engine/Commands/InvalidCommand.cs index 3114870..d66f349 100644 --- a/MudEngine/WinPC.Engine/Commands/InvalidCommand.cs +++ b/MudEngine/WinPC.Engine/Commands/InvalidCommand.cs @@ -8,6 +8,7 @@ namespace WinPC.Engine.Commands public class InvalidCommand : ICommand { private Socket Connection { get; set; } + public InvalidCommand(Socket connnection) { Connection = connnection; diff --git a/MudEngine/WinPC.Engine/Commands/SwitchStateCommand.cs b/MudEngine/WinPC.Engine/Commands/SwitchStateCommand.cs new file mode 100644 index 0000000..ba6f1b0 --- /dev/null +++ b/MudEngine/WinPC.Engine/Commands/SwitchStateCommand.cs @@ -0,0 +1,22 @@ +using WinPC.Engine.Abstract.Core; +using WinPC.Engine.Directors; + +namespace WinPC.Engine.Commands +{ + public class SwitchStateCommand : ICommand + { + private ServerDirector Director { get; set; } + private IState NewState { get; set; } + private int Index { get; set; } + public SwitchStateCommand(ServerDirector director, IState newState, int index) + { + Director = director; + NewState = newState; + } + + public void Execute() + { + Director.ConnectedPlayers[Index].SwitchState(NewState); + } + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Core/Player.cs b/MudEngine/WinPC.Engine/Core/Player.cs index 87559b3..2da0550 100644 --- a/MudEngine/WinPC.Engine/Core/Player.cs +++ b/MudEngine/WinPC.Engine/Core/Player.cs @@ -21,5 +21,10 @@ namespace WinPC.Engine.Core { Connection.Close(); } + + public void SwitchState(IState state) + { + CurrentState = state; + } } } \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Directors/ServerDirector.cs b/MudEngine/WinPC.Engine/Directors/ServerDirector.cs index e6316e7..c500af5 100644 --- a/MudEngine/WinPC.Engine/Directors/ServerDirector.cs +++ b/MudEngine/WinPC.Engine/Directors/ServerDirector.cs @@ -14,6 +14,8 @@ namespace WinPC.Engine.Directors public List ConnectionThreads { get; private set; } public List ConnectedPlayers { get; private set; } + + public IServer Server { get; set; } public ServerDirector(IServer server) diff --git a/MudEngine/WinPC.Engine/States/ConnectState.cs b/MudEngine/WinPC.Engine/States/ConnectState.cs index 225fd6c..f3b3c2b 100644 --- a/MudEngine/WinPC.Engine/States/ConnectState.cs +++ b/MudEngine/WinPC.Engine/States/ConnectState.cs @@ -38,6 +38,11 @@ namespace WinPC.Engine.States var input = Director.RecieveInput(Index); + if (input == "menu") + { + return new SwitchStateCommand(Director, new MainMenuState(Director), Index); + } + return new InvalidCommand(Connection); } } diff --git a/MudEngine/WinPC.Engine/States/MainMenuState.cs b/MudEngine/WinPC.Engine/States/MainMenuState.cs index aa2a933..0a5f4e5 100644 --- a/MudEngine/WinPC.Engine/States/MainMenuState.cs +++ b/MudEngine/WinPC.Engine/States/MainMenuState.cs @@ -1,18 +1,48 @@ -using WinPC.Engine.Abstract.Core; +using System.Net.Sockets; +using System.Text; +using WinPC.Engine.Abstract.Core; +using WinPC.Engine.Commands; +using WinPC.Engine.Directors; namespace WinPC.Engine.States { public class MainMenuState : IState { + public ServerDirector Director { get; private set; } + private Socket Connection { get; set; } + private ASCIIEncoding Encoding { get; set; } + private int Index; + + public MainMenuState(ServerDirector director) + { + Director = director; + Encoding = new ASCIIEncoding(); + + } public void Render(int index) { - throw new System.NotImplementedException(); + Index = index; + + Connection = Director.ConnectedPlayers[index].Connection; + + Director.ConnectedPlayers[index].Connection.Send(Encoding.GetBytes("Your now in the Main Menu State Welcome!! !"+"\n\r")); + + + + } public ICommand GetCommand() { - throw new System.NotImplementedException(); + + var input = Director.RecieveInput(Index); + + if(input == "connect") + { + return new SwitchStateCommand(Director, new ConnectState(Director),Index); + } + return new InvalidCommand(Connection); } } } \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/WinPC.Engine.csproj b/MudEngine/WinPC.Engine/WinPC.Engine.csproj index 67483d7..9e824ad 100644 --- a/MudEngine/WinPC.Engine/WinPC.Engine.csproj +++ b/MudEngine/WinPC.Engine/WinPC.Engine.csproj @@ -65,6 +65,7 @@ +