Esempio n. 1
0
        public static List<Item> GetCommandItems(string[] words, Room currentRoom, Inventory playerInventory)
        {
            List<string> tryWordCombinations = allWordCombinations(words);
            tryWordCombinations.Sort(
                delegate(string a, string b) {
                    //return a.Length.CompareTo(b.Length);
                    // longest first
                    return b.Length.CompareTo(a.Length);
                }
            );

            List<Item> matches = new List<Item>();
            foreach (string phrase in tryWordCombinations) {
                //Console.WriteLine("trying combination: {0}", phrase);
                Item foundItem = playerInventory.GetItem(phrase);
                if (foundItem != null && !matches.Contains(foundItem)) {
                    matches.Add(foundItem);
                }

                if (currentRoom != null) {
                    foundItem = currentRoom.GetItem(phrase);
                    if (foundItem != null && !matches.Contains(foundItem)) {
                        matches.Add(foundItem);
                    }
                }
            }

            return matches;
        }