diff --git a/MUDGame/Program.cs b/MUDGame/Program.cs index 31e7c06..1987683 100644 --- a/MUDGame/Program.cs +++ b/MUDGame/Program.cs @@ -68,6 +68,12 @@ namespace MUDGame Console.WriteLine(game.Story); 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) { Console.Write("Command: "); @@ -88,6 +94,7 @@ namespace MUDGame } } + game.End(); Console.WriteLine("Press Enter to exit."); Console.ReadKey(); } diff --git a/MudEngine/Commands/CommandWalk.cs b/MudEngine/Commands/CommandWalk.cs index c29d48a..d2d3091 100644 --- a/MudEngine/Commands/CommandWalk.cs +++ b/MudEngine/Commands/CommandWalk.cs @@ -33,7 +33,9 @@ namespace MudEngine.Commands if (door.TravelDirection == direction) { //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); string lookValue = ""; diff --git a/MudEngine/GameManagement/Game.cs b/MudEngine/GameManagement/Game.cs index 75c737b..45c003d 100644 --- a/MudEngine/GameManagement/Game.cs +++ b/MudEngine/GameManagement/Game.cs @@ -230,6 +230,13 @@ namespace MudEngine.GameManagement 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) { string directory = Path.GetDirectoryName(filename); @@ -270,6 +277,17 @@ namespace MudEngine.GameManagement 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 public List PlayerCollection; diff --git a/MudEngine/GameObjects/Characters/BaseCharacter.cs b/MudEngine/GameObjects/Characters/BaseCharacter.cs index 86ccd5c..ea6cce1 100644 --- a/MudEngine/GameObjects/Characters/BaseCharacter.cs +++ b/MudEngine/GameObjects/Characters/BaseCharacter.cs @@ -42,13 +42,31 @@ namespace MudEngine.GameObjects.Characters CurrentRoom = game.InitialRealm.InitialZone.InitialRoom; } + /// + /// Moves the player from one Room to another if the supplied direction contains a doorway. + /// Returns false if no doorway is available. + /// + /// + /// + 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) { - if (CurrentRoom.DoorwayExist(travelDirection.ToString())) - { - string connectedRoom = CurrentRoom.GetDoor(travelDirection).ConnectedRoom; - CurrentRoom = (Room)CurrentRoom.Load(connectedRoom); - } + //TODO: Check the Room/Zone/Realm to see if anything needs to occure during travel. } public CommandResults ExecuteCommand(string command) diff --git a/MudEngine/GameObjects/Environment/Realm.cs b/MudEngine/GameObjects/Environment/Realm.cs index b3f98db..ce7b250 100644 --- a/MudEngine/GameObjects/Environment/Realm.cs +++ b/MudEngine/GameObjects/Environment/Realm.cs @@ -40,11 +40,11 @@ namespace MudEngine.GameObjects.Environment /// /// /// - public Zone GetZone(string filename) + public Zone GetZone(string name) { foreach (Zone zone in ZoneCollection) { - if (zone.Filename == filename) + if (zone.Name == name) return zone; } diff --git a/MudEngine/GameObjects/Environment/Room.cs b/MudEngine/GameObjects/Environment/Room.cs index 6e15c66..3d537db 100644 --- a/MudEngine/GameObjects/Environment/Room.cs +++ b/MudEngine/GameObjects/Environment/Room.cs @@ -116,11 +116,11 @@ namespace MudEngine.GameObjects.Environment IsSafe = false; } - public bool DoorwayExist(string travelDirection) + public bool DoorwayExist(AvailableTravelDirections travelDirection) { foreach (Door door in Doorways) { - if (door.TravelDirection.ToString().ToLower() == travelDirection.ToLower()) + if (door.TravelDirection == travelDirection) return true; } diff --git a/MudEngine/Networking/Server.cs b/MudEngine/Networking/Server.cs index b6eb39b..4981ecc 100644 --- a/MudEngine/Networking/Server.cs +++ b/MudEngine/Networking/Server.cs @@ -80,6 +80,8 @@ namespace MudEngine.Networking public void EndServer() { stage = 0; + serverThread.Abort(); + if (server.type == ProtocolType.Tcp) { for (int i = 0; i < numberOfClients; i++)