public override string Execute(Player p, string[] text)
        {
            IHaveInventory _container = null;

            if (text.Length == 4)
            {
                if (text[0] != "put")
                {
                    return("What do you want to put?");
                }

                if (text[2] != "in")
                {
                    return("What do you want to put in?");
                }
                _container = FetchContainer(p, text[3]);

                string _itemid = text[1];

                if (_container == null)
                {
                    return("Could not find " + text[3]);
                }

                return(PutItemIn(p, _itemid, _container));
            }

            return("I don't know how to put like that");
        }
 public string LookAtIn(string thingId, IHaveInventory container)
 {
     if (container.Locate(thingId) != null)
     {
         return(container.Locate(thingId).FullDescription);
     }
     return("Could not find " + thingId);
 }
Exemplo n.º 3
0
        private string LookAtIn(string thingId, IHaveInventory container)
        {
            if (container.Locate(thingId) != null)
            {
                return(container.Locate(thingId).FullDescription);
            }

            return($"I can't find the {thingId}");
        }
Exemplo n.º 4
0
        private string LookAtIn(string thingId, IHaveInventory container)
        {
            if (container.Locate(thingId) != null)
            {
                return(container.Locate(thingId).LongDescription);
            }

            return("Could not find " + thingId + ".");
        }
        public override string Execute(Player player, string[] command)
        {
            string item = null;

            if (command.Length == 2 || command.Length == 4)
            {
                if (command.Length == 4)
                {
                    if (command[2].ToLower().Equals("from"))
                    {
                        IHaveInventory container = FetchContainer(player, command[3].ToLower());

                        if (container != null)
                        {
                            Item obj = PickUp(container, command[1].ToLower()) as Item;

                            if (obj != null)
                            {
                                player.Inventory.Put(obj);
                                return("Picked up " + command[1] + " from " + command[3]);
                            }
                            else
                            {
                                item = "I cannot find the " + command[1];
                            }
                        }
                        else
                        {
                            item = "I cannot find the " + command[3];
                        }
                    }
                    else
                    {
                        item = "Where do you want to take from?";
                    }
                }

                if (command.Length == 2)
                {
                    IHaveInventory location = player.Location as IHaveInventory;
                    Item           obj      = PickUp(location, command[1].ToLower()) as Item;
                    Console.WriteLine(player.Location.Name + " " + command[1].ToLower());
                    if (obj != null)
                    {
                        player.Inventory.Put(obj);
                        return("Picked up " + command[1]);
                    }
                    return("Couldn't find " + command[1]);
                }
            }
            else
            {
                item = "I don't know how to take like that";
            }
            return(item);
        }
Exemplo n.º 6
0
        //the player is sent here, with the array converted 'look comand'. assess whether its 3 (sent to lookatin directly) or 5 elements
        public override string Execute(Player p, List <string> text)
        {
            string invalidStr = "";

            if (text.Count == 3 || text.Count == 5)
            {
                if (text[0].ToLower() != "look")
                {
                    invalidStr = "Error in look input";
                }

                if (text[1].ToLower() != "at")
                {
                    invalidStr = "What do you want to look at?";
                }

                if (text.Count == 5 && text[3].ToLower() != "in")
                {
                    invalidStr = "What do you want to look in?";
                }

                if (text.Count == 3 && text[0].ToLower() == "look" && text[1].ToLower() == "at")
                {
                    return(LookAtIn(text[2], p as IHaveInventory));
                }

                if (text.Count == 5 && text[0].ToLower() == "look" && text[1].ToLower() == "at" && text[3].ToLower() == "in")
                {
                    IHaveInventory container = FetchContainer(p, text[4]);

                    if (container == null)
                    {
                        return("I can't find the " + text[4]);
                    }
                    else
                    {
                        return(LookAtIn(text[2], container));
                    }
                }
            }
            else if (text.Count == 1 && text[0].ToLower() == "look")
            {
                return(p.Location.FullDescription);
            }
            else if (p.AreYou(text[0].ToLower()))
            {
                return(LookAtIn(text[0], p as IHaveInventory));
            }
            else
            {
                invalidStr = "I don't know how to look for that";
            }


            return(invalidStr);
        }
Exemplo n.º 7
0
        private string LookAtIn(string thingId, IHaveInventory container)
        {
            var thing = container.Locate(thingId);

            if (thing == null)
            {
                return(null);
            }
            return(thing.FullDescription);
        }
Exemplo n.º 8
0
 private string LookAtIn(string thingId, IHaveInventory container)
 {
     if (container.Locate(thingId) != null)
     {
         return(container.Locate(thingId).FullDescription);
     }
     else
     {
         return("I can not find the " + thingId + ".");
     }
 }
Exemplo n.º 9
0
        private string PutItemIn(Player p, string thingId, IHaveInventory targetContainer)
        {
            if (p.Locate(thingId) == null)
            {
                return("You don't have a " + thingId + "\r\n");
            }
            Item itemToMove = p.Inventory.Take(thingId) as Item;

            targetContainer.Put(itemToMove);

            return("You have put away the " + thingId + "\r\n");
        }
Exemplo n.º 10
0
 //The association relationship is the oject 1 can declare an object of the object 2 to use the object 2's function for the sake of removing the duplication code
 //for example, this class command need the IHaveInventory container to provide and support for its function
 //Find the item inside the cointainer just found in the above
 private string LookAtIn(string thingId, IHaveInventory container)
 {
     //This is to check even when the container is valid, is there that item inside
     if (container.LocateSth(thingId) != null)
     {
         return(container.LocateSth(thingId).FullDescription);
     }
     else
     {
         return("There is no" + thingId);
     }
 }
        private IHaveInventory FetchContainer(Player p, string containerId)
        {
            GameObject obj = p.Locate(containerId);

            if (obj == null && p.Location.AreYou(containerId))
            {
                obj = p.Location;
            }
            IHaveInventory container = obj as IHaveInventory;

            return(container);
        }
Exemplo n.º 12
0
        private string LookAtIn(string thingId, IHaveInventory container)
        {
            var result = container.Locate(thingId);

            if (result != null)
            {
                return(result.LongDescription);
            }
            else
            {
                return("");
            }
        }
Exemplo n.º 13
0
        public string LookAtIn(string thingId, IHaveInventory container)
        {
            if (container.Locate(thingId) == null)
            {
                return("I cannot find the " + thingId);
            }
            else
            {
                GameObject obj = container.Locate(thingId) as GameObject;

                return(obj.FullDescription);
            }
        }
        private string LookAtIn(string thingId, IHaveInventory container)
        {
            GameObject obj = container.Locate(thingId);

            if (obj != null)
            {
                return(obj.FullDescription);
            }
            else
            {
                return($"I cannot find the {thingId} in the {container.Name}");
            }
        }
Exemplo n.º 15
0
        private string LookAtIn(string thingId, IHaveInventory container)
        {
            GameObject itemFound = container.Locate(thingId);

            if (itemFound != null)
            {
                return(itemFound.FullDescription);
            }
            else
            {
                return("I cannot find the " + thingId + " in the " + container.Name);
            }
        }
        private string PutIn(string thingId, Player player, IHaveInventory container)
        {
            GameObject obj = player.Locate(thingId);

            if (obj != null)
            {
                container.Inventory.Put(player.Inventory.Take(thingId) as Item);
                return($"You have put {obj.Name} in {container.Name}");
            }
            else
            {
                return($"I cannot find the {thingId} from me");
            }
        }
 public string PutItemIn(Player p, string thingId, IHaveInventory container)
 {
     if (p.Locate(thingId) != null)
     {
         Item _item = p.Take(thingId) as Item;
         if (_item == null)
         {
             return("Could not put " + thingId);
         }
         container.Put(_item);
         return("You have put the " + thingId + " in " + container.Name + ".\r\n");
     }
     return("Could not find " + thingId);
 }
Exemplo n.º 18
0
        private string LookAtIn(string thingId, IHaveInventory container)
        {
            GameObject obj = container.Locate(thingId);

            if (obj != null)
            {
                return(obj.FullDescription);
            }
            else
            {
                string result = "I cannot find the " + thingId + " in the " + container.Name;
                return(result);
            }
        }
        private string TakeFrom(string thingId, Player player, IHaveInventory container)
        {
            GameObject obj = container.Locate(thingId);

            if (obj != null)
            {
                player.Inventory.Put(container.Inventory.Take(thingId) as Item);
                return($"You have taken {obj.Name} from {container.Name}");
            }
            else
            {
                return($"I cannot find the {thingId} in the {container.Name}");
            }
        }
Exemplo n.º 20
0
        public override string Execute(Player p, string[] text)
        {
            IHaveInventory _container = null;
            string         _itemid;
            string         error = "Error in take input.";

            switch (text.Length)
            {
            case 1:
                return("Take what?");

            case 2:
                if (ContainsString(text[1].ToLower(), new string[] { "north",
                                                                     "south", "east", "west", "up", "down" }))
                {
                    return("Cannot " + text[0] + " direction!");
                }
                else
                {
                    _itemid    = text[1];
                    _container = p.Location as IHaveInventory;
                }
                break;

            case 3:
                if (text[1].ToLower() != "at")
                {
                    return("What do you want take from?");
                }
                _container = p as IHaveInventory;
                _itemid    = text[2];
                break;

            case 4:
                _container = FetchContainer(p, text[3]);     // I think this is broken
                if (_container == null)                      //  somewhere...
                {
                    return("Could not find " + text[3] + ".\r\n");
                }
                _itemid = text[1];
                break;

            default:
                _container = null;
                return(error);
            }

            return(TakeItemFrom(p, _itemid, _container));
        }
Exemplo n.º 21
0
        private string TakeAndKeep(IHaveInventory container, Player p, string thingId)
        {
            GameObject i = container.Locate(thingId);

            if (i != null)
            {
                Item takenItem = container.Inventory.Take(thingId);
                p.Inventory.Put(takenItem);
                return(string.Format("  You have taken the {0} from the {1}", thingId, container.Name));
            }
            else
            {
                return(string.Format("  I cant find {0} in the {1}", thingId, container.Name));
            }
        }
        public string TakeItemFrom(Player p, string thingId, IHaveInventory container)
        {
            if (container.Locate(thingId) != null)
            {
                Item _item = container.Take(thingId) as Item;
                if (_item == null)
                {
                    return("Could not take " + thingId);
                }
                p.Inventory.Put(_item);

                return("You have taken the " + thingId + ".\r\n");
            }
            return("Could not find " + thingId);
        }
        public override string Execute(Player p, string[] text)
        {
            if (text.Length == 3 | text.Length == 5)
            {
                if (text[0] != "look")
                {
                    return("Error in look input");
                }

                if (text[1] != "at")
                {
                    return("What do you want to look at?");
                }

                if (text.Length == 5)
                {
                    if (text[3] != "in")
                    {
                        return("What do you want to look in?");
                    }
                }
            }
            else
            {
                return("I don't know how to look like that");
            }

            IHaveInventory _container = null;

            if (text.Length == 3)
            {
                _container = p as IHaveInventory;
            }

            if (text.Length == 5)
            {
                _container = FetchContainer(p, text[4]);
            }

            if (_container == null)
            {
                return("Could not find " + text[4]);
            }

            string _ItemId = text[2];

            return(LookAtIn(_ItemId, _container));
        }
        public override string Execute(Player player, string[] text)
        {
            IHaveInventory container   = null;
            string         containerId = null;
            string         itemId      = null;
            int            textLength  = text.Length;

            //the text should have either 2 or 4 words, otherwise return "I don't know how to look like that"
            if (textLength != 2 && textLength != 4)
            {
                return("I don't know how to put like that.");
            }

            //The first word must be take/pickup
            if (!AreYou(text[0]))
            {
                return("Error in put input.");
            }

            //The container is player current location if there are 2 elements
            if (textLength == 2)
            {
                container = player.CurrentLocation as IHaveInventory;
            }

            //If there are 4 elements, then the 3th word must be "in"
            if (textLength == 4)
            {
                if (text[2] != "in")
                {
                    return("What do you want to put in?");
                }
                else
                {
                    containerId = text[3];
                    container   = FetchContainer(player, containerId);
                }
            }
            //The itemId is in the 2nd word
            itemId = text[1];

            if (container == null)
            {
                return($"I cannot find the {containerId}");
            }

            return(PutIn(itemId, player, container));
        }
Exemplo n.º 25
0
        private string Dispense(IHaveInventory container, Player p, string thingId)
        {
            GameObject i = p.Locate(thingId);

            if (i != null)
            {
                Item droppedItem = p.Inventory.Take(thingId);
                container.Inventory.Put(droppedItem);

                return(string.Format("  You have placed the {0} in the {1}", thingId, container.Name));
            }
            else
            {
                return(string.Format("  I cant find {0}", thingId));
            }
        }
Exemplo n.º 26
0
        private string PutItem(Player p, string thingId, string containerId)
        {
            IHaveInventory container = FetchContainer(p, containerId);

            if (container == null)
            {
                return("I cannot find the " + containerId);
            }
            GameObject containerThing = container.Locate(thingId);

            if (containerThing == null)
            {
                return("I cannot find the " + thingId + (containerId == null ? "" : " in the " + containerId));
            }
            return(containerThing.FullDescription);
        }
Exemplo n.º 27
0
        private string LookAtIn(string thingId, IHaveInventory container)
        {
            GameObject item = container.Locate(thingId);

            if (container.Name != "bag" && item == null)
            {
                return("I can't find the " + thingId);
            }
            else if (container.Name == "bag" && item == null)
            {
                return("I can't find the " + thingId + " in the bag");
            }
            else
            {
                return(item.FullDescription);
            }
        }
Exemplo n.º 28
0
        public override string Execute(Player p, string[] text)
        {
            if (!new[] { 3, 5 }.Contains(text.Length))
            {
                return("I don't know how to look like that\n");
            }

            if (text[0] != "look")
            {
                return("Error in look input\n");
            }

            if (text[1] != "at")
            {
                return("What do you want to look at?\n");
            }

            if (text.Length == 5)
            {
                if (text[3] != "in")
                {
                    return("What do you want to look in?\n");
                }
            }

            if (text.Length == 3)
            {
                string itemToFind = text[2];
                return(LookAtIn(itemToFind, p as IHaveInventory));
            }

            if (text.Length == 5)
            {
                string         itemToFind    = text[2];
                string         placeToLookIn = text[4];
                IHaveInventory container     = FetchContainer(p, placeToLookIn);
                if (container is null)
                {
                    return($"I cannot find the {placeToLookIn}\n");
                }
                return(LookAtIn(itemToFind, container));
            }

            return("Success");
        }
Exemplo n.º 29
0
        private String TakeItemFrom(Player p, string thingId, IHaveInventory container)
        {
            if (container.Locate(thingId) == null)
            {
                return("Could not find " + thingId + "\r\n");
            }

            GameObject _itemFound  = container.Locate(thingId);
            Item       itemGrabbed = container.Take(thingId) as Item;

            if (itemGrabbed == null)
            {
                return("You can't take " + _itemFound.ShortDescription + " with you.\r\n");
            }
            p.Inventory.Put(itemGrabbed);

            return("You have taken the " + thingId + ".\r\n");
        }
        public override string Execute(Player p, string[] text)
        {
            IHaveInventory _container = null;

            if (text.Length == 2 | text.Length == 4)
            {
                if (text[0] != "take")
                {
                    return("What do you want to take?");
                }

                if (text.Length == 4)
                {
                    if (text[2] != "from")
                    {
                        return("What do you want to take from?");
                    }
                }
            }
            else
            {
                return("I don't know how to take like that");
            }

            string _itemid = text[1];

            switch (text.Length)
            {
            case 2:
                _container = p.Location as IHaveInventory;
                break;

            case 4:
                _container = FetchContainer(p, text[3]);
                break;
            }

            if (_container == null)
            {
                return("Could not find " + text[3]);
            }

            return(TakeItemFrom(p, _itemid, _container));
        }