Beispiel #1
0
        private void HandleCraftInteraction(Person actor, string itemType, string itemName)
        {
            switch (itemType.ToLower())
            {
            case "weapon":
                var ironForWeapon = actor.ListInventory().FirstOrDefault(i => i is Iron) as Iron;
                var woodForWeapon = actor.ListInventory().FirstOrDefault(w => w is Wood) as Wood;
                if (ironForWeapon != null && woodForWeapon != null)
                {
                    Weapon weapon = new Weapon(itemName);
                    actor.AddToInventory(weapon);
                    this.ownerByItem[weapon] = actor;
                }
                break;

            case "armor":
                var ironForArmor = actor.ListInventory().FirstOrDefault(i => i is Iron) as Iron;
                if (ironForArmor != null)
                {
                    Armor armor = new Armor(itemName);
                    actor.AddToInventory(armor);
                    this.ownerByItem[armor] = actor;
                }
                break;

            default:
                break;
            }
        }
Beispiel #2
0
        private void HandleGatherInteraction(Person actor, string itemName)
        {
            switch (actor.Location.LocationType)
            {
            case LocationType.Forest:
                var weapon = actor.ListInventory().FirstOrDefault(w => w is Weapon) as Weapon;
                if (weapon != null)
                {
                    Wood wood = new Wood(itemName);
                    actor.AddToInventory(wood);
                    this.ownerByItem[wood] = actor;
                }
                break;

            case LocationType.Mine:
                var armor = actor.ListInventory().FirstOrDefault(a => a is Armor) as Armor;
                if (armor != null)
                {
                    Iron iron = new Iron(itemName);
                    actor.AddToInventory(iron);
                    this.ownerByItem[iron] = actor;
                }
                break;

            default:
                break;
            }
        }
Beispiel #3
0
 private void Craft(string[] commandWords, Person actor)
 {
     if (commandWords[2] == "armor" && actor.ListInventory().Any(x => x is Iron))
     {
         Armor newArmor = new Armor(commandWords[3]);
         actor.AddToInventory(newArmor);
         this.AddToPerson(actor, newArmor);
     }
     else if (commandWords[2] == "weapon" && actor.ListInventory().Any(x => x is Iron) && actor.ListInventory().Any(x => x is Wood))
     {
         Weapon newWeapon = new Weapon(commandWords[3]);
         actor.AddToInventory(newWeapon);
         this.AddToPerson(actor, newWeapon);
     }
 }
Beispiel #4
0
 private void Gather(string[] commandWords, Person actor)
 {
     if (actor.ListInventory().Any(x => x is Weapon) && (actor.Location is Forest))
     {
         Wood newWood = new Wood(commandWords[2]);
         actor.AddToInventory(newWood);
         this.AddToPerson(actor, newWood);
     }
     else if (actor.ListInventory().Any(x => x is Armor) && (actor.Location is Mine))
     {
         Iron newIron = new Iron(commandWords[2]);
         actor.AddToInventory(newIron);
         this.AddToPerson(actor, newIron);
     }
 }
Beispiel #5
0
        private void HandleCraftInteraction(string type, string name, Person actor)
        {
            bool isItemFound  = false;
            bool isItemFound1 = false;

            if (type == "weapon")
            {
                foreach (Item item in actor.ListInventory())
                {
                    if (item.ItemType == ItemType.Iron)
                    {
                        isItemFound = true;
                    }
                    if (item.ItemType == ItemType.Wood)
                    {
                        isItemFound1 = true;
                    }
                }

                if (isItemFound && isItemFound1)
                {
                    Item item = null;
                    item = CreateItem("weapon", name, actor.Location, item);
                    actor.AddToInventory(item);
                    ownerByItem[item] = actor;
                    strayItemsByLocation[actor.Location].Add(item);
                }
            }
            else if (type == "armor")
            {
                foreach (Item item in actor.ListInventory())
                {
                    if (item.ItemType == ItemType.Iron)
                    {
                        isItemFound = true;
                    }
                }

                if (isItemFound)
                {
                    Item item = null;
                    item = CreateItem("armor", name, actor.Location, item);
                    actor.AddToInventory(item);
                    ownerByItem[item] = actor;
                    strayItemsByLocation[actor.Location].Add(item);
                }
            }
        }
 private void HandleCraftInteraction(Person actor, string itemType, string itemName)
 {
     if (actor.ListInventory().Find(i => i is Iron) != null)
     {
         if (itemType == "weapon" && actor.ListInventory().Find(i => i is Wood) != null)
         {
             var item = new Weapon(itemName);
             actor.AddToInventory(item);
             this.ownerByItem.Add(item, actor);
         }
         else if (itemType == "armor")
         {
             var item = new Armor(itemName);
             actor.AddToInventory(item);
             this.ownerByItem.Add(item, actor);
         }
     }
 }
Beispiel #7
0
        private void HandleGatherInteraction(string name, Person actor)
        {
            bool isItemFound = false;

            if (actor.Location.LocationType == LocationType.Forest)
            {
                foreach (Item item in actor.ListInventory())
                {
                    if (item.ItemType == ItemType.Weapon)
                    {
                        isItemFound = true;
                    }
                }

                if (isItemFound)
                {
                    Item item = null;
                    item = CreateItem("wood", name, actor.Location, item);
                    actor.AddToInventory(item);
                    ownerByItem[item] = actor;
                    strayItemsByLocation[actor.Location].Add(item);
                }
            }
            else if (actor.Location.LocationType == LocationType.Mine)
            {
                foreach (Item item in actor.ListInventory())
                {
                    if (item.ItemType == ItemType.Armor)
                    {
                        isItemFound = true;
                    }
                }

                if (isItemFound)
                {
                    Item item = null;
                    item = CreateItem("iron", name, actor.Location, item);
                    actor.AddToInventory(item);
                    ownerByItem[item] = actor;
                    strayItemsByLocation[actor.Location].Add(item);
                }
            }
        }
 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");
     }         
 }        
Beispiel #9
0
 private void  HandleCraftInteraction(Person actor, string[] commandWords)
 {
     if (commandWords[2] == "weapon")
     {
         if (actor.ListInventory().Any(x => x is Iron) && actor.ListInventory().Any(x => x is Wood))
         {
             Weapon item = new Weapon(commandWords[3]);
             actor.AddToInventory(item);
             this.ownerByItem.Add(item, actor);
         }
     }
     else
     if (commandWords[2] == "armor")
     {
         if (actor.ListInventory().Any(x => x is Iron))
         {
             Armor item = new Armor(commandWords[3]);
             actor.AddToInventory(item);
             this.ownerByItem.Add(item, actor);
         }
     }
 }
Beispiel #10
0
 private void  HandleGatherInteraction(Person actor, string[] commandWords)
 {
     if (actor.Location is Forest)
     {
         if (actor.ListInventory().Any(x => x is Weapon))
         {
             Wood item = new Wood(commandWords[2]);
             actor.AddToInventory(item);
             this.ownerByItem.Add(item, actor);
         }
     }
     else
     if (actor.Location is Mine)
     {
         if (actor.ListInventory().Any(x => x is Armor))
         {
             Iron item = new Iron(commandWords[2]);
             actor.AddToInventory(item);
             this.ownerByItem.Add(item, actor);
         }
     }
 }
        private void HandleGatherInteraction(Person actor, string itemName)
        {
            var actorItems = actor.ListInventory();

            for (int i = 0; i < actorItems.Count; i++)
            {
                if (actorItems[i] is Weapon && actor.Location is Forest)
                {
                    var item = new Wood(itemName);
                    actor.AddToInventory(item);
                    this.ownerByItem.Add(item, actor);
                    return;
                }
                else if (actorItems[i] is Armor && actor.Location is Mine)
                {
                    var item = new Iron(itemName);
                    actor.AddToInventory(item);
                    this.ownerByItem.Add(item, actor);
                    return;
                }
            }
        }
Beispiel #12
0
        private void HandleGatherInteraction(Person actor, string gatheredItemName)
        {
            var location = actor.Location;


            if (location is GatheringLocation)
            {
                var locationAsGatheringLocation = location as GatheringLocation;
                if (actor.ListInventory().Any(x => x.ItemType == locationAsGatheringLocation.RequiredItem))
                {
                    var item = locationAsGatheringLocation.ProduceItem(gatheredItemName);
                    actor.AddToInventory(item);
                }
            }
        }
 private void HandleCraftInteraction(Person actor, string name)
 {
     if (actor.ListInventory().Exists(x => x is Iron))
     {
         if (actor.ListInventory().Exists(x => x is Weapon))
         {
             var item = new Weapon(name);
             actor.AddToInventory(item);
             this.AddToPerson(actor, item);
             return;
         }
         else
         {
             var item = new Armor(name);
             actor.AddToInventory(item);
             this.AddToPerson(actor, item);
         }
     }
 }
 protected void AddToPerson(Person actor, Item item)
 {
     actor.AddToInventory(item);
     ownerByItem[item] = actor;
 }
 protected void AddToPerson(Person actor, Item item)
 {
     actor.AddToInventory(item);
     this.ownerByItem[item] = actor;
 }
        private void HandleGatherInteraction(Person actor, string itemName)
        {
            //Gathering means a Person takes an item from a special location
            //A Person should be able to gather from mines and from forests
            //A Person can gather from a forest only if he has a Weapon in his inventory
            //Gathering from a forests results in adding a Wood item in the Person’s inventory
            //A Person can gather from a mine only if he has an Armor in his inventory
            //Gathering from a mine results in adding an Iron item in the Person’s inventory
            //Syntax: Joro gather newItemName – gathers an item, naming it newItemName if the Person Joro is at a mine or forest, and respectively has an Armor or Weapon

            if (actor.Location.LocationType == LocationType.Forest && actor.ListInventory().Any(a => a.GetType() == typeof(Weapon)))
            {
                Wood a = new Wood(itemName);
                base.AddToPerson(actor, a);
                actor.AddToInventory(new Wood(itemName));
            }

            if (actor.Location.LocationType == LocationType.Mine && actor.ListInventory().Any(a => a.GetType() == typeof(Armor)))
            {
                Iron a = new Iron(itemName);
                base.AddToPerson(actor, a);
                actor.AddToInventory(new Iron(itemName));
            }
        }
 private void HandleCraftInteraction(Person actor, string itemToCraft, string itemName)
 {
     //A Person can craft items, provided he has some items in his inventory
     //A Person should be able to craft Weapons and Armor
     //Crafting an Armor requires that the Person has Iron in his inventory
     //Results in adding an Armor item in the Person’s inventory
     //Crafting a Weapon requires that the Person has Iron and Wood in his inventory
     //Syntax: Joro craft weapon/armor newItemName - gathers an item, naming it newItemName if the Person Joro has the necessary
     switch (itemToCraft)
     {
         case "armor":
             if (actor.ListInventory().Any(a => a.GetType() == typeof(Iron)))
             {
                 Armor armor = new Armor(itemName);
                 base.AddToPerson(actor, armor);
                 actor.AddToInventory(new Armor(itemName));
             }
             break;
         case "weapon":
             if (actor.ListInventory().Any(a => a.GetType() == typeof(Iron)) && actor.ListInventory().Any(a => a.GetType() == typeof(Wood)))
             {
                 Weapon weapon = new Weapon(itemName);
                 base.AddToPerson(actor, weapon);
                 actor.AddToInventory(new Weapon(itemName));
             }
             break;
         default:
             break;
     }
 }
        private void HandleGatherInteraction(Person actor, string name)
        {
            var locationForest = actor.Location as Forest;
            if (locationForest is Forest)
            {
                if (actor.ListInventory().Exists(x => x is Weapon))
                {
                    var item = new Wood(name, actor.Location);
                    actor.AddToInventory(item);
                    this.AddToPerson(actor, item);
                }
            }

            var locationMine = actor.Location as Mine;
            if (locationMine is Mine)
            {
                if (actor.ListInventory().Exists(x => x is Armor))
                {
                    var item = new Iron(name, actor.Location);
                    actor.AddToInventory(item);
                    this.AddToPerson(actor, item);
                }
            }
        }
        private void HandleGatherInteraction(Person actor, string itemName)
        {
            var actorItems = actor.ListInventory();

            for (int i = 0; i < actorItems.Count; i++)
            {
                if (actorItems[i] is Weapon && actor.Location is Forest)
                {
                    var item = new Wood(itemName);
                    actor.AddToInventory(item);
                    this.ownerByItem.Add(item, actor);
                    return;
                }
                else if (actorItems[i] is Armor && actor.Location is Mine)
                {
                    var item = new Iron(itemName);
                    actor.AddToInventory(item);
                    this.ownerByItem.Add(item, actor);
                    return;
                }
            }
        }
 private void HandleCraftInteraction(Person actor, string itemType, string itemName)
 {
     if (actor.ListInventory().Find(i => i is Iron) != null)
     {
         if (itemType == "weapon" && actor.ListInventory().Find(i => i is Wood) != null)
         {
             var item = new Weapon(itemName);
             actor.AddToInventory(item);
             this.ownerByItem.Add(item, actor);
         }
         else if (itemType == "armor")
         {
             var item = new Armor(itemName);
             actor.AddToInventory(item);
             this.ownerByItem.Add(item, actor);
         }
     }
 }
        private void HandleGatherInteraction(string[] commandWords, Person actor)
        {
            if (actor.Location.LocationType == LocationType.Forest)
            {
                var inventoryItems = actor.ListInventory().Where(x => x.ItemType == ItemType.Weapon);
                if (inventoryItems != null && inventoryItems.Count() > 0)
                {
                    var item = new Wood(commandWords[2], null);
                    actor.AddToInventory(item);
                    ownerByItem.Add(item, actor);
                    item.UpdateWithInteraction("gather");
                }
            }
            else if (actor.Location.LocationType == LocationType.Mine)
            {
                var inventoryItems = actor.ListInventory().Where(x => x.ItemType == ItemType.Armor);
                if (inventoryItems != null && inventoryItems.Count() > 0)
                {
                    var item = new Iron(commandWords[2], null);
                    actor.AddToInventory(item);
                    ownerByItem.Add(item, actor);
                }
            }

        }