* IPlayer - Connection and Buffer properties added along with SwitchState(IState) method

* Switched the ServerDirector over from using two List Collections to maintain Client Threads and Player instances into a single Dictionary.  Required adjusting the majority of the existing Types, but should now be functional.  Need to still add some safety checks for null references since we are now passing a reference Type around.
This commit is contained in:
Scionwest_cp 2012-06-06 20:56:30 -07:00
parent f977376ac3
commit 24c9fae4f5
7 changed files with 59 additions and 62 deletions

View file

@ -11,46 +11,37 @@ namespace WinPC.Engine.States
public class ConnectState : IState
{
public ServerDirector Director { get; private set; }
private Socket Connection { get; set; }
private ASCIIEncoding Encoding { get; set; }
private int Index;
private Socket connection;
private ASCIIEncoding encoding;
private IPlayer player;
public ConnectState(ServerDirector director)
{
Director = director;
Encoding = new ASCIIEncoding();
encoding = new ASCIIEncoding();
}
public void Render(int index)
public void Render(IPlayer connectedPlayer)
{
Index = index;
Connection = Director.ConnectedPlayers[index].Connection;
connection = connectedPlayer.Connection;
player = connectedPlayer;
Connection.Send(Encoding.GetBytes("Welcome to Scionwest's Mud Engine!"+"\n\r"));
Connection.Send(Encoding.GetBytes("Please enter your name" + "\n\r"));
//Just used for testing ServerDirector.GetPlayer method
IPlayer player = null;
bool validPlayer = Director.GetPlayer("Player", out player);
//player = player ?? new IPlayer().Create();
if (validPlayer)
Connection.Send(Encoding.GetBytes("Welcome " + player.Name));
connection.Send(encoding.GetBytes("Welcome to Scionwest's Mud Engine!" + "\n\r"));
connection.Send(encoding.GetBytes("Please enter your name" + "\n\r"));
}
public ICommand GetCommand()
{
var input = Director.RecieveInput(Index);
var input = Director.RecieveInput(player);
if (input == "menu")
{
return new SwitchStateCommand(Director, new MainMenuState(Director), Index);
return new SwitchStateCommand(Director, new MainMenuState(Director), player);
}
return new InvalidCommand(Connection);
return new InvalidCommand(connection);
}
}
}