Exemple #1
0
        private void HandleCraftInteraction(Person actor, string itemTypeAsString, string newItemName)
        {
            var actorInventory = actor.ListInventory();
            Item itemToAdd = null;
            var listOfNeededItems = null;

            switch (itemTypeAsString)
            {
                case "weapon" :
                    if (actorInventory.Any(x => x.ItemType == ItemType.Wood) && actorInventory.Any(x => x.ItemType == ItemType.Iron))
                    {
                        itemToAdd = new Weapon(newItemName);
                    }
                    break;
                case "armor" :
                    if (actorInventory.Any(x => x.ItemType == ItemType.Iron))
                    {
                        itemToAdd = new Armor(newItemName);
                    }
                    break;
                default:
                    break;
            }

            if (itemToAdd != null)
            {
                this.AddToPerson(actor, itemToAdd);
            }
        }
 private void HandleArmorCrafting(Person actor, string itemName)
 {
     if (actor.HasItemInInvetory(ItemType.Iron))
     {
             this.AddToPerson(actor, new Armor(itemName));
     }
 }
        private void HandleCraftInteraction(Person actor, string[] commandWords)
        {
            var inventory = actor.ListInventory();

            bool hasIron = false;
            bool hasWood = false;

            foreach (var item in inventory)
            {
                if (item is Iron)
                {
                    hasIron = true;
                }
                else if (item is Wood)
                {
                    hasWood = true;
                }
            }

            if (commandWords[2] == "armor" && hasIron)
            {
                this.AddToPerson(actor, new Armor(commandWords[3], actor.Location));
            }
            else if (commandWords[2] == "weapon" && hasIron && hasWood)
            {
                this.AddToPerson(actor, new Weapon(commandWords[3], "weapon", actor.Location));
            }
        }
 protected virtual void HandlePersonCommand(string[] commandWords, Person actor)
 {
     switch (commandWords[1])
     {
         case "drop":
             HandleDropInteraction(actor);
             break;
         case "pickup":
             HandlePickUpInteraction(actor);
             break;
         case "sell":
             this.HandleSellInteraction(commandWords, actor);
             break;
         case "buy":
             HandleBuyInteraction(commandWords, actor);
             break;
         case "inventory":
             HandleListInventoryInteraction(actor);
             break;
         case "money":
             Console.WriteLine(moneyByPerson[actor]);
             break;
         case "travel":
             HandleTravelInteraction(commandWords, actor);
             break;
         default:
             break;
     }
 }
        private void HandleCraftInteraction(string[] commandWords, Person actor)
        {
            var craftedItemType = commandWords[2];
            string craftedItemName = commandWords[3];
            Item theNewCraftedItem = null;
            var actorInventory = actor.ListInventory();

            if (craftedItemType == "weapon")
            {
                bool hasWood = PossessTheRequiredItem(actorInventory, ItemType.Wood);
                bool hasIron = PossessTheRequiredItem(actorInventory, ItemType.Iron);

                if (hasWood && hasIron)
                {
                    theNewCraftedItem = new Weapon(craftedItemName);
                    this.AddToPerson(actor, theNewCraftedItem);
                    theNewCraftedItem.UpdateWithInteraction("craft");
                }
            }
            else if (craftedItemType == "armor")
            {
                bool hasIron = PossessTheRequiredItem(actorInventory, ItemType.Iron);

                if (hasIron)
                {
                    theNewCraftedItem = new Armor(craftedItemName);
                    this.AddToPerson(actor, theNewCraftedItem);
                    theNewCraftedItem.UpdateWithInteraction("craft");
                }
            }
        }
 private void HandleGatherInteraction(string itemNameString, Person actor)
 {
     var gatherLoc = actor.Location as IGatheringLocation;   
     if (gatherLoc != null && actor.ListInventory().Any(item => item.ItemType == gatherLoc.RequiredItem))
     {
         this.AddToPerson(actor, gatherLoc.ProduceItem(itemNameString));
     }
 }
 private void CraftArmor(Person actor, string craftedItemName)
 {
     var actorInventory = actor.ListInventory();
     if (actorInventory.Any((item) => item.ItemType == ItemType.Iron))
     {
         this.AddToPerson(actor, new Armor(craftedItemName));
     }
 }
 private void HandleArmorCrafting(Person actor, string itemName)
 {
     var itemRequired = ItemType.Iron;
     if (actor.HasItemInInventory(itemRequired))
     {
         this.AddToPerson(actor, new Armor(itemName));
     }
 }
 private void HandleWeaponCrafting(Person actor, string itemName)
 {
     var requiredItems = new List<ItemType> { ItemType.Iron, ItemType.Wood };
     if (requiredItems.All(i => actor.HasItemInInventory(i)))
     {
         this.AddToPerson(actor, new Weapon(itemName));
     }
 }
 protected override void HandlePersonCommand(string[] commandWords, Person actor)
 {
     switch (commandWords[1])
     {
         case "gather": this.HandleGatherInteraction(commandWords, actor); break;
         case "craft": this.HandleCraftInteraction(commandWords, actor); break;
         default: base.HandlePersonCommand(commandWords, actor); break;
     }
 }
        private void HandleCraftInteraction(Person actor, string crafteedItemType, string craftedItemName)
        {

            switch (crafteedItemType)
            {
                default:
                    break;
            }

        }
 private void HandleGatherInteraction(string[] commandWords, Person actor)
 {
     if (actor.Location is Forest && actor.ListInventory().Any(item => item is Weapon))
     {
        this.AddToPerson(actor, new Wood(commandWords[2]));
     }
     else if (actor.Location is Mine && actor.ListInventory().Any(item => item is Armor))
     {
         this.AddToPerson(actor, new Iron(commandWords[2]));
     }
 }
 private void HandleGatherInteraction(Person actor, string name)
 {
     if (actor.Location is IGatheringLocation)
     {
         var gatheringLocation = actor.Location as IGatheringLocation;
         if (actor.HasItem(gatheringLocation.RequiredItem))
         {
             this.AddToPerson(actor, gatheringLocation.ProduceItem(name));
         }
     }
 }
        private void HandleGatherInteraction(string name, Person actor)
        {
            if (actor.Location is IGatheringLocation)
            {
                var location = actor.Location as IGatheringLocation;

                if (actor.ListInventory().Any(i => i.ItemType == location.RequiredItem))
                {
                    AddToPerson(actor, location.ProduceItem(name));
                }
            }
        }
        private void HandleCraftInteraction(Person actor, string type, string name)
        {
            if (type == "armor" && actor.HasItem(ItemType.Iron))
            {
                this.AddToPerson(actor, new Armor(name));
            }

            if (type == "weapon" && actor.HasItem(ItemType.Iron) && actor.HasItem(ItemType.Wood))
            {
                this.AddToPerson(actor, new Weapon(name));
            }
        }
        protected void HandleGatherInteraction(Person actor, string newName)
        {
            if (actor.Location is IGatheringLocation)
            { 
                var gatheringLocation = actor.Location as IGatheringLocation;

                if (actor.ListInventory().Any(x => x.ItemType == gatheringLocation.RequiredItem))
                {
                    this.AddToPerson(actor, gatheringLocation.ProduceItem(newName));
                }
            }
        }
 private void HandleGatherInteraction(Person actor, string itemName)
 {
     if (actor.Location is IGatheringLocation)
     {
         var location = actor.Location as IGatheringLocation;
         if (actor.InventorryContains(location.RequiredItem))
         {
             var gatheredItem = location.ProduceItem(itemName);
             this.AddToPerson(actor, gatheredItem);
         }
     }
 }
 private void CraftArmor(string newItemName, Person actor) 
 {
     var ironItems = actor.ListInventory().Where(x => x.ItemType == ItemType.Iron);          
     if (ironItems != null && ironItems.Count() > 0 )
     {
        
         var item = new Armor(newItemName, null);
         actor.AddToInventory(item);
         ownerByItem.Add(item, actor);
         item.UpdateWithInteraction("craft");
     }         
 }        
        private void HandleCraftInteraction(string itemNameString, string itemTypeString, Person actor)
        {
            if (itemTypeString == "weapon" && actor.ListInventory().Any(item => item is Iron) && (actor.ListInventory().Any(item => item is Wood)))
            {
                this.AddToPerson(actor, new Weapon(itemNameString));
            }

            if (itemTypeString == "armor" && actor.ListInventory().Any(item => item is Iron))
            {
                this.AddToPerson(actor, new Armor(itemNameString));
            }
        }
 private void HandleCraftInteraction(Person actor, string craftItem, string itemName)
 {
     switch (craftItem)
     {
         case "weapon":
             this.HandleWeaponCrafting(actor, itemName);
             break;
         case "armor":
             this.HandleArmorCrafting(actor, itemName);
             break;
     }
 }
        private void HandleCraftInteraction(string[] commandWords, Person actor)
        {
            string craftItemType = commandWords[2];
            string craftItemName = commandWords[3];

            if (craftItemType == "armor")
            {
                bool hasIron = false;

                foreach (var item in actor.ListInventory())
                {
                    if (item.ItemType == ItemType.Iron)
                    {
                        hasIron = true;
                        break;
                    }
                }

                if (hasIron)
                {
                    var addedItem = new Armor(craftItemName);
                    this.AddToPerson(actor, addedItem);
                    addedItem.UpdateWithInteraction("craft");
                }
            }

            if (craftItemType == "weapon")
            {
                bool hasWood = false;
                bool hasIron = false;

                foreach (var item in actor.ListInventory())
                {
                    if (item.ItemType == ItemType.Wood)
                    {
                        hasWood = true;
                    }
                    else if (item.ItemType == ItemType.Iron)
                    {
                        hasIron = true;
                    }
                }

                if (hasWood && hasIron)
                {
                    var addedItem = new Weapon(craftItemName);
                    this.AddToPerson(actor, addedItem);
                    addedItem.UpdateWithInteraction("craft");
                }
            }
        }
 private void HandleCraftInteraction(Person actor, string itemTypeString, string itemName)
 {
     switch (itemTypeString)
     {
         case "weapon":
             this.HandleWeaponCrafting(actor, itemName);
             break;
         case "armor":
             this.HandleArmorCrafting(actor, itemName);
             break;
         default:
             break;
     }
 }
 private void HandleCraftInteraction(Person actor, string craftedItemType, string craftedItemName)
 {
     switch (craftedItemType)
     {
         case "armor":
             this.CraftArmor(actor, craftedItemName);
             break;
         case "weapon":
             this.CraftWeapon(actor, craftedItemName);
             break;
         default:
             throw new ArgumentException("Invalid command", craftedItemType);
     }
 }
 private void HandleCraftInteraction(string[] commandWords, Person actor)
 {
     if (actor.ListInventory().Any(item => item is Iron))
     {
         if (commandWords[2] == "weapon" && actor.ListInventory().Any(item => item is Wood))
         {
             this.AddToPerson(actor, new Weapon(commandWords[3]));
         }
         else if (commandWords[2] == "armor")
         {
             this.AddToPerson(actor, new Armor(commandWords[3]));
         }
     }
 }
 private void HandleCraftInteraction(Person actor, string itemType, string itemName)
 {
     Item newItem;
     if (itemType == "weapon" && actor.InventorryContains(ItemType.Wood, ItemType.Iron))
     {
         newItem=new Weapon(itemName);
         this.AddToPerson(actor, newItem);
     }
     else if (itemType == "armor" && actor.InventorryContains(ItemType.Iron))
     {
         newItem =new Armor(itemName);
         this.AddToPerson(actor, newItem);
     }
 }
Exemple #26
0
        private void HandleCraftInteraction(string[] commandWords, Person actor)
        {
            Item craftedItem = null;
            string itemType = commandWords[2];
            string itemName = commandWords[3];
            switch (itemType)
            {
                case "armor" :
                    foreach (var item in actor.ListInventory())
                    {
                        if (item.ItemType == ItemType.Iron)
                        {
                            craftedItem = new Armor(itemName);
                            this.AddToPerson(actor, craftedItem);
                            return;
                        }
                    }

                    break;
                case "weapon" :
                    bool hasIron = new bool();
                    bool hasWood = new bool();

                    foreach (var item in actor.ListInventory())
                    {
                        if (item.ItemType == ItemType.Iron)
                        {
                            hasIron = true;
                        }
                        else if (item.ItemType == ItemType.Wood)
                        {
                            hasWood = true;
                        }

                        if (hasIron && hasWood)
                        {
                            craftedItem = new Weapon(itemName);
                            this.AddToPerson(actor, craftedItem);
                            return;
                        }
                    }

                    break;
                default:
                    break;
            }

        }
 private void HandleCraftInteraction(string[] commandWords, Person actor)
 {
     string typeToCraft = commandWords[2];
     string newItemName = commandWords[3];
   
     switch (typeToCraft)
     {
         case "weapon": this.CraftWeapon(newItemName, actor);
             break;
         case "armor":this.CraftArmor(newItemName, actor);
             break;
         default:
             break;
     }
    
 }
        private void HandleTravelInteraction(string[] commandWords, Person actor)
        {
            var traveller = actor as ITraveller;
            if (traveller != null)
            {
                var targetLocation = this.locationByName[commandWords[2]];
                peopleByLocation[traveller.Location].Remove(actor);
                traveller.TravelTo(targetLocation);
                peopleByLocation[traveller.Location].Add(actor);

                foreach (var item in actor.ListInventory())
                {
                    item.UpdateWithInteraction("travel");
                }
            }
        }
 public void HandleGatherInteraction(Person person, string newItemName)
 {
     if (person.Location.LocationType == LocationType.Forest)
     {
         if (person.ListInventory().Exists(x => x.ItemType == ItemType.Weapon))
         {
             this.AddToPerson(person, new Wood(newItemName, null));
         }
     }
     else if (person.Location.LocationType == LocationType.Mine)
     {
         if (person.ListInventory().Exists(x => x.ItemType == ItemType.Armor))
         {
             this.AddToPerson(person, new Iron(newItemName, null));
         }
     }
 }
        private void HandleCraftInteraction(Person actor, string itemType, string itemName)
        {
            if (actor.ListInventory().Count > 0)
            {
                if (itemType == "weapon" && actor.ListInventory().Any(x => x.ItemType == ItemType.Iron) && actor.ListInventory().Any(x => x.ItemType == ItemType.Wood))
                {
                    var weapon = new Weapon(itemName);
                    AddToPerson(actor, weapon);
                }
                else if (itemType == "armor" && actor.ListInventory().Any(x => x.ItemType == ItemType.Iron))
                {
                    var armor = new Armor(itemName);
                    AddToPerson(actor, armor);
                }

            }
        }
 protected void RemoveFromPerson(Person actor, Item item)
 {
     actor.RemoveFromInventory(item);
     ownerByItem[item] = null;
 }
 protected void AddToPerson(Person actor, Item item)
 {
     actor.AddToInventory(item);
     ownerByItem[item] = actor;
 }