* 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:
parent
d857b23dee
commit
fc27d9fc22
3 changed files with 46 additions and 26 deletions
33
MudEngine/WinPC_Server/ConsoleInput.cs
Normal file
33
MudEngine/WinPC_Server/ConsoleInput.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,57 +8,43 @@ using System.Threading;
|
|||
using MudEngine.Game;
|
||||
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
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
//Setup the engines log system
|
||||
Logger.LogFilename = "StandardGame.Log";
|
||||
Logger.Enabled = true;
|
||||
Logger.ConsoleOutPut = true;
|
||||
|
||||
//Instance and start the game. This will start the server.
|
||||
StandardGame game = new StandardGame("Sample Game");
|
||||
game.Start();
|
||||
|
||||
Boolean msgReturn = false;
|
||||
ServerInput input = new ServerInput();
|
||||
//Setup our Server console input class
|
||||
ConsoleInput input = new ConsoleInput();
|
||||
|
||||
//Run the console input on its own thread.
|
||||
Thread inputThread = new Thread(input.GetInput);
|
||||
inputThread.Start();
|
||||
|
||||
//Game loops until it is disabled.
|
||||
while (game.Enabled)
|
||||
{
|
||||
//Check the queued Console Input
|
||||
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();
|
||||
}
|
||||
else if (input.Message.Equals("test") && (msgReturn == false))
|
||||
{
|
||||
Console.WriteLine("Message Works");
|
||||
else
|
||||
input.Message = String.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
//Kill the Console Input thread.
|
||||
inputThread.Abort();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ConsoleInput.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue