public void TestCreateWorld() { // create dir if it doesn't already exist, for testing with json Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\.textadventure\Logs\"); var entireWorld = new GameContainer(); entireWorld.Name = "Entire World"; var bedroom = new GameLocation("Bedroom"); bedroom.Description = "An untidy bedroom"; entireWorld.AddRelationship(RelationshipType.Contains, RelationshipDirection.ParentToChild, bedroom); var mainCharacter = new GameCharacter("Alfie Drever"); mainCharacter.Description = "Lazy but deeply lovable"; mainCharacter.Gender = "Male"; bedroom.AddRelationship(RelationshipType.Contains, RelationshipDirection.ParentToChild, mainCharacter); var bed = new GameObject("Bed"); bedroom.AddRelationship(RelationshipType.Contains, RelationshipDirection.ParentToChild, bed); var wallet = new GameObject("Wallet"); wallet.IsOpenable = true; wallet.AddRelationship(RelationshipType.IsUnder, RelationshipDirection.ChildToParent, bed); var money = new GameCurrencyObject("Money", 10); wallet.AddRelationship(RelationshipType.Contains, RelationshipDirection.ParentToChild, money); var bedroomDoor = new GameObject("Bedroom Door"); bedroom.AddRelationship(RelationshipType.Contains, RelationshipDirection.ParentToChild, bedroomDoor); var landing = new GameLocation("The landing"); landing.Description = "Area of carpeted land outside bedroom door"; bedroomDoor.AddRelationship(RelationshipType.LeadsTo, RelationshipDirection.ParentToChild, landing); var parser = new Parser(new CommandCoordinator(new CommandExecutor(), new ObjectRepository())); var lo = new LocationRepository(); lo.SaveCurrentLocation(mainCharacter, bedroom); var takestatus = parser.ParseInput(mainCharacter.ID, "take Wallet"); Assert.AreEqual(takestatus, "Alfie Drever took Wallet"); }
public CommandOperationStatus Drop(GameObject gameObject, GameCharacter gameCharacter, GameLocation location) { var status = new CommandOperationStatus(); try { RemoveDirectPossessionRelationships(gameObject); if (!gameCharacter.HasIndirectRelationshipWith(gameObject, RelationshipType.IsHeldBy, RelationshipDirection.ParentToChild)) { status.Message = gameCharacter.Name + " doesn't have " + gameObject.Name; status.Status = false; return(status); } location.AddRelationship(RelationshipType.Contains, RelationshipDirection.ParentToChild, gameObject); status.Message = gameCharacter.Name + " dropped " + gameObject.Name; status.Status = true; } catch (Exception e) { status.Message = e.Message; status.Status = false; } return(status); }