MudEngine:
- Player movement command now fully implemented. - Game.GetRealm() added to retrieve a Realm within the games RealmCollection property - Game.End() added to perform game ending duties and shut down the Server - Server now loses opened threads. - Player.Move() added to move the player from Room to Room. - Room.DoorwayExist() tweaked to work with the new way Environments are managed. MudGame: - Now executes the Look command on startup so the player can see where they are located at. - Implements the new Game.End() method and fixes the game hanging upon exit.
This commit is contained in:
parent
19e3ec0936
commit
70533582a6
7 changed files with 57 additions and 10 deletions
|
@ -68,6 +68,12 @@ namespace MUDGame
|
||||||
Console.WriteLine(game.Story);
|
Console.WriteLine(game.Story);
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
|
|
||||||
|
//Simple Help info
|
||||||
|
Console.WriteLine("Available Commands are\n Look\n Exit\n Walk 'direction' where direction = north/south/east/west/up/down\n");
|
||||||
|
|
||||||
|
//Invoke the Look command so the player knows whats around him/her
|
||||||
|
Console.WriteLine(player.ExecuteCommand("Look").Result[0]);
|
||||||
|
|
||||||
while (game.IsRunning)
|
while (game.IsRunning)
|
||||||
{
|
{
|
||||||
Console.Write("Command: ");
|
Console.Write("Command: ");
|
||||||
|
@ -88,6 +94,7 @@ namespace MUDGame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
game.End();
|
||||||
Console.WriteLine("Press Enter to exit.");
|
Console.WriteLine("Press Enter to exit.");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,9 @@ namespace MudEngine.Commands
|
||||||
if (door.TravelDirection == direction)
|
if (door.TravelDirection == direction)
|
||||||
{
|
{
|
||||||
//TODO: Player.Move() method needed so room loading is handled by player code.
|
//TODO: Player.Move() method needed so room loading is handled by player code.
|
||||||
player.CurrentRoom = (Room)player.CurrentRoom.Load(door.ConnectedRoom);
|
//Old Code: player.CurrentRoom = (Room)player.CurrentRoom.Load(door.ConnectedRoom);
|
||||||
|
|
||||||
|
player.Move(direction);
|
||||||
|
|
||||||
CommandResults cmd = CommandEngine.ExecuteCommand("Look", player);
|
CommandResults cmd = CommandEngine.ExecuteCommand("Look", player);
|
||||||
string lookValue = "";
|
string lookValue = "";
|
||||||
|
|
|
@ -230,6 +230,13 @@ namespace MudEngine.GameManagement
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void End()
|
||||||
|
{
|
||||||
|
//Place ending code here for game shut down.
|
||||||
|
//TODO: Save content on shutdown.
|
||||||
|
Server.EndServer();
|
||||||
|
}
|
||||||
|
|
||||||
public void Save(string filename)
|
public void Save(string filename)
|
||||||
{
|
{
|
||||||
string directory = Path.GetDirectoryName(filename);
|
string directory = Path.GetDirectoryName(filename);
|
||||||
|
@ -270,6 +277,17 @@ namespace MudEngine.GameManagement
|
||||||
InitialRealm = realm;
|
InitialRealm = realm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Realm GetRealm(string realmName)
|
||||||
|
{
|
||||||
|
foreach (Realm realm in RealmCollection)
|
||||||
|
{
|
||||||
|
if (realm.Name == realmName)
|
||||||
|
return realm;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: This should be internal only; C# property using get; internal set; so only MudEngine.dll may edit this collection
|
//TODO: This should be internal only; C# property using get; internal set; so only MudEngine.dll may edit this collection
|
||||||
public List<BaseCharacter> PlayerCollection;
|
public List<BaseCharacter> PlayerCollection;
|
||||||
|
|
||||||
|
|
|
@ -42,13 +42,31 @@ namespace MudEngine.GameObjects.Characters
|
||||||
CurrentRoom = game.InitialRealm.InitialZone.InitialRoom;
|
CurrentRoom = game.InitialRealm.InitialZone.InitialRoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Moves the player from one Room to another if the supplied direction contains a doorway.
|
||||||
|
/// Returns false if no doorway is available.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="travelDirection"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool Move(AvailableTravelDirections travelDirection)
|
||||||
|
{
|
||||||
|
//Check if the current room has a doorway in the supplied direction of travel.
|
||||||
|
if (!CurrentRoom.DoorwayExist(travelDirection))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//We have a doorway, lets move to the next room.
|
||||||
|
CurrentRoom = Game.GetRealm(CurrentRoom.Realm).GetZone(CurrentRoom.Zone).GetRoom(CurrentRoom.GetDoor(travelDirection).ConnectedRoom);
|
||||||
|
|
||||||
|
OnTravel(travelDirection);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void OnTravel(AvailableTravelDirections travelDirection)
|
public virtual void OnTravel(AvailableTravelDirections travelDirection)
|
||||||
{
|
{
|
||||||
if (CurrentRoom.DoorwayExist(travelDirection.ToString()))
|
//TODO: Check the Room/Zone/Realm to see if anything needs to occure during travel.
|
||||||
{
|
|
||||||
string connectedRoom = CurrentRoom.GetDoor(travelDirection).ConnectedRoom;
|
|
||||||
CurrentRoom = (Room)CurrentRoom.Load(connectedRoom);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandResults ExecuteCommand(string command)
|
public CommandResults ExecuteCommand(string command)
|
||||||
|
|
|
@ -40,11 +40,11 @@ namespace MudEngine.GameObjects.Environment
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="zoneName"></param>
|
/// <param name="zoneName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Zone GetZone(string filename)
|
public Zone GetZone(string name)
|
||||||
{
|
{
|
||||||
foreach (Zone zone in ZoneCollection)
|
foreach (Zone zone in ZoneCollection)
|
||||||
{
|
{
|
||||||
if (zone.Filename == filename)
|
if (zone.Name == name)
|
||||||
return zone;
|
return zone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,11 +116,11 @@ namespace MudEngine.GameObjects.Environment
|
||||||
IsSafe = false;
|
IsSafe = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool DoorwayExist(string travelDirection)
|
public bool DoorwayExist(AvailableTravelDirections travelDirection)
|
||||||
{
|
{
|
||||||
foreach (Door door in Doorways)
|
foreach (Door door in Doorways)
|
||||||
{
|
{
|
||||||
if (door.TravelDirection.ToString().ToLower() == travelDirection.ToLower())
|
if (door.TravelDirection == travelDirection)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,8 @@ namespace MudEngine.Networking
|
||||||
public void EndServer()
|
public void EndServer()
|
||||||
{
|
{
|
||||||
stage = 0;
|
stage = 0;
|
||||||
|
serverThread.Abort();
|
||||||
|
|
||||||
if (server.type == ProtocolType.Tcp)
|
if (server.type == ProtocolType.Tcp)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < numberOfClients; i++)
|
for (int i = 0; i < numberOfClients; i++)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue