* Provided better commenting of the Server application.

* Performed some Refactoring.  ConsoleInput file created to store the ConsoleInput class instead of it being held within the Program.cs file.
This commit is contained in:
Scionwest_cp 2012-02-28 20:44:59 -08:00
parent d857b23dee
commit fc27d9fc22
3 changed files with 46 additions and 26 deletions

View file

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WinPC_Server
{
class ConsoleInput
{
/// <summary>
/// Current queued console message entered by the user
/// </summary>
public String Message { get; set; }
public ConsoleInput()
{
Message = String.Empty;
}
/// <summary>
/// Retrieves input from the user and queues it in ConsoleInput.Message
/// </summary>
public void GetInput()
{
while (true)
{
Console.WriteLine("Enter a Server Command: ");
//Accept input from the user and store it for use.
Message = Console.ReadLine();
}
}
}
}

View file

@ -8,57 +8,43 @@ using System.Threading;
using MudEngine.Game; using MudEngine.Game;
using MudEngine.Core; using MudEngine.Core;
namespace SimpleMUD namespace WinPC_Server
{ {
public class ServerInput
{
public String Message;
public ServerInput()
{
Message = String.Empty;
}
public void GetInput()
{
while (true)
{
Console.WriteLine("Enter a test message: ");
Message = Console.ReadLine();
}
}
}
class Program class Program
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
//Setup the engines log system
Logger.LogFilename = "StandardGame.Log"; Logger.LogFilename = "StandardGame.Log";
Logger.Enabled = true; Logger.Enabled = true;
Logger.ConsoleOutPut = true; Logger.ConsoleOutPut = true;
//Instance and start the game. This will start the server.
StandardGame game = new StandardGame("Sample Game"); StandardGame game = new StandardGame("Sample Game");
game.Start(); game.Start();
Boolean msgReturn = false; //Setup our Server console input class
ServerInput input = new ServerInput(); ConsoleInput input = new ConsoleInput();
//Run the console input on its own thread.
Thread inputThread = new Thread(input.GetInput); Thread inputThread = new Thread(input.GetInput);
inputThread.Start(); inputThread.Start();
//Game loops until it is disabled.
while (game.Enabled) while (game.Enabled)
{ {
//Check the queued Console Input
if (input.Message.Equals("exit")) if (input.Message.Equals("exit"))
{ {
//If the server console has a exit command entered.
//stop the game. This will set game.Enabled to false.
game.Stop(); game.Stop();
} }
else if (input.Message.Equals("test") && (msgReturn == false)) else
{
Console.WriteLine("Message Works");
input.Message = String.Empty; input.Message = String.Empty;
}
} }
//Kill the Console Input thread.
inputThread.Abort(); inputThread.Abort();
} }
} }

View file

@ -49,6 +49,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="ConsoleInput.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>