Added SwitchStateCommand ability, Future (replace dual lists to single Dictionary)
This commit is contained in:
parent
a0c406d482
commit
ca97b9c439
7 changed files with 69 additions and 3 deletions
|
@ -8,6 +8,7 @@ namespace WinPC.Engine.Commands
|
||||||
public class InvalidCommand : ICommand
|
public class InvalidCommand : ICommand
|
||||||
{
|
{
|
||||||
private Socket Connection { get; set; }
|
private Socket Connection { get; set; }
|
||||||
|
|
||||||
public InvalidCommand(Socket connnection)
|
public InvalidCommand(Socket connnection)
|
||||||
{
|
{
|
||||||
Connection = connnection;
|
Connection = connnection;
|
||||||
|
|
22
MudEngine/WinPC.Engine/Commands/SwitchStateCommand.cs
Normal file
22
MudEngine/WinPC.Engine/Commands/SwitchStateCommand.cs
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,5 +21,10 @@ namespace WinPC.Engine.Core
|
||||||
{
|
{
|
||||||
Connection.Close();
|
Connection.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SwitchState(IState state)
|
||||||
|
{
|
||||||
|
CurrentState = state;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,6 +14,8 @@ namespace WinPC.Engine.Directors
|
||||||
|
|
||||||
public List<Thread> ConnectionThreads { get; private set; }
|
public List<Thread> ConnectionThreads { get; private set; }
|
||||||
public List<Player> ConnectedPlayers { get; private set; }
|
public List<Player> ConnectedPlayers { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
public IServer Server { get; set; }
|
public IServer Server { get; set; }
|
||||||
|
|
||||||
public ServerDirector(IServer server)
|
public ServerDirector(IServer server)
|
||||||
|
|
|
@ -38,6 +38,11 @@ namespace WinPC.Engine.States
|
||||||
|
|
||||||
var input = Director.RecieveInput(Index);
|
var input = Director.RecieveInput(Index);
|
||||||
|
|
||||||
|
if (input == "menu")
|
||||||
|
{
|
||||||
|
return new SwitchStateCommand(Director, new MainMenuState(Director), Index);
|
||||||
|
}
|
||||||
|
|
||||||
return new InvalidCommand(Connection);
|
return new InvalidCommand(Connection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
namespace WinPC.Engine.States
|
||||||
{
|
{
|
||||||
public class MainMenuState : IState
|
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)
|
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()
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -65,6 +65,7 @@
|
||||||
<Compile Include="Abstract.Networking\IServer.cs" />
|
<Compile Include="Abstract.Networking\IServer.cs" />
|
||||||
<Compile Include="Abstract.Objects\IItem.cs" />
|
<Compile Include="Abstract.Objects\IItem.cs" />
|
||||||
<Compile Include="Commands\InvalidCommand.cs" />
|
<Compile Include="Commands\InvalidCommand.cs" />
|
||||||
|
<Compile Include="Commands\SwitchStateCommand.cs" />
|
||||||
<Compile Include="Core\Logger.cs" />
|
<Compile Include="Core\Logger.cs" />
|
||||||
<Compile Include="Core\Player.cs" />
|
<Compile Include="Core\Player.cs" />
|
||||||
<Compile Include="Directors\ServerDirector.cs" />
|
<Compile Include="Directors\ServerDirector.cs" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue