public void CreateSubstringOfActionInput_ShouldReturnSubstring() { const string fullCmdLineInput = "enter observatory"; const string firstWordKeyword = "enter"; const string expectedOutput = "observatory"; var result = PlayerActionHandler.CreateSubstringOfActionInput(fullCmdLineInput, firstWordKeyword); Assert.AreEqual(expectedOutput, result); }
public static bool HandlePlayerTradingItem(string fullInput, Character.Models.Character player, Room.Models.Room currentRoom, string inputWord, bool inputResolved) { if (currentRoom.RoomCharacters.Any()) { var substring = PlayerActionHandler.CreateSubstringOfActionInput(fullInput, inputWord); var character = RoomHandler.FindAnyMatchingCharacterByKeywords(substring.Trim(), currentRoom); var inventoryKeywords = GetAllInventoryItemKeywords(player); var foundItem = FindAnyMatchingItemsByKeywords(substring.Trim(), inventoryKeywords, player.CarriedItems, new List <WeaponItem> { player.WeaponItem }); if (foundItem != null && character != null) { if (GiveItemIsOk(player, character, foundItem)) { var tradedItem = HandleItemTrade(player, character, foundItem, currentRoom); if (!string.IsNullOrEmpty(tradedItem.ItemName)) { TypingAnimation.Animate("\nYou give the " + foundItem.InventoryItems.First().ItemName + " to " + character.Name + ".\n" + character.Name + " gives you the " + tradedItem.ItemName + ".\n", Color.Gold); } else { TypingAnimation.Animate("Your inventory is full... You cannot take the " + tradedItem.ItemName + ".\n", Color.DarkOliveGreen); } inputResolved = true; } else { Colorful.Console.WriteLine(); TypingAnimation.Animate(character.Name + " doesn't want that item.\n", Color.DarkOliveGreen); inputResolved = true; } } } else { Colorful.Console.WriteLine("\nThere is no one here to give that to...", Color.DarkOliveGreen); inputResolved = true; } return(inputResolved); }