Exemple #1
0
    public Item CreateItem(string[] args)
    {
        string typeOfItem = args[0];

        Item newlyCreatedItem = null;

        try
        {
            switch (typeOfItem)
            {
            case "ArmorRepairKit":
                newlyCreatedItem = new ArmorRepairKit();
                return(newlyCreatedItem);

            case "HealthPotion":
                newlyCreatedItem = new HealthPotion();
                return(newlyCreatedItem);

            case "PoisonPotion":
                newlyCreatedItem = new PoisonPotion();
                return(newlyCreatedItem);

            default: throw new ArgumentException($"Invalid item \"{typeOfItem}\"!");
            }
        }
        catch (InvalidOperationException oe) {
            throw new InvalidOperationException(oe.Message);
        }
    }
Exemple #2
0
        public string AddItemToPool(string[] args)
        {
            var  itemName = args[0];
            Item item;

            switch (itemName)
            {
            case "HealthPotion":
                item = new HealthPotion();
                break;

            case "PoisonPotion":
                item = new PoisonPotion();
                break;

            case "ArmorRepairKit":
                item = new ArmorRepairKit();
                break;

            default:
                throw new ArgumentException($"Invalid item \"{itemName}\"");
            }

            itemPool.Push(item);

            return($"{itemName} added to pool!");
        }
Exemple #3
0
        public Item CreateItem(string itemName)
        {
            if (itemName != "ArmorRepairKit" && itemName != "HealthPotion" && itemName != "PoisonPotion")
            {
                throw new ArgumentException(string.Format(ExceptionMessages.InvalidItemException, itemName));
            }

            Item item = null;

            if (itemName == "ArmorRepairKit")
            {
                item = new ArmorRepairKit();
            }
            else if (itemName == "HealthPotion")
            {
                item = new HealthPotion();
            }
            else if (itemName == "PoisonPotion")
            {
                item = new PoisonPotion();
            }
            else
            {
                throw new ArgumentException(string.Format(ExceptionMessages.InvalidItemException, itemName));
            }

            return(item);
        }
Exemple #4
0
    public string AddItemToPool(string[] args)
    {
        if (args[0] != nameof(ArmorRepairKit) && args[0] != nameof(PoisonPotion) && args[0] != nameof(HealthPotion))
        {
            throw new ArgumentException($"Invalid item \"{args[0]}\"!");
        }

        Item temp = null;

        switch (args[0])
        {
        case nameof(ArmorRepairKit):
            temp = new ArmorRepairKit();
            break;

        case nameof(PoisonPotion):
            temp = new PoisonPotion();
            break;

        case nameof(HealthPotion):
            temp = new HealthPotion();
            break;
        }

        itemPool.Push(temp);
        return($"{args[0]} added to pool!");
    }
        public string AddItemToPool(string[] args)
        {
            string itemName = args[0];

            Item item;

            if (itemName == "ArmorRepairKit")
            {
                item = new ArmorRepairKit();
            }
            else if (itemName == "HealthPotion")
            {
                item = new HealthPotion();
            }
            else if (itemName == "PoisonPotion")
            {
                item = new PoisonPotion();
            }
            else
            {
                throw new ArgumentException("Invalid item \"{ name }\"!");
            }

            itemsPool.Push(item);
            return($"{itemName} added to pool.");
        }
        public Item CreateItem(string type)
        {
            Item item = null;

            if (type == "ArmorRepairKit")
            {
                item = new ArmorRepairKit();
                return(item);
            }

            else if (type == "HealthPotions")
            {
                item = new HealthPotion();
                return(item);
            }

            else if (type == "PosionPotion")
            {
                item = new PoisonPotion();
                return(item);
            }


            throw new ArgumentException(string.Format(ErrorMessages.InvalidItem, type));
        }
        public Item CreateItem(string itemName)
        {
            Item item;

            switch (itemName)
            {
            case "HealthPotion":
                item = new HealthPotion();
                break;

            case "PoisonPotion":
                item = new PoisonPotion();
                break;

            case "ArmorRepairKit":
                item = new ArmorRepairKit();
                break;

            default:
                throw new ArgumentException(string.Format(OutputMessages.IvalidItemType, itemName));
            }

            return(item);

            //Second way - reflection:
            //var type = this.GetType()
            //    .Assembly
            //    .GetTypes()
            //    .FirstOrDefault(x => x.Name == itemName);

            //if(type == null || itemName == "Item" || String.IsNullOrWhiteSpace(itemName))
            //{
            //    throw new ArgumentException(string.Format(OutputMessages.IvalidItemType, itemName));
            //}

            //try
            //{
            //    var item = (Item)Activator.CreateInstance(type, new object[] { });
            //    return item;
            //}
            //catch (Exception ex)
            //{
            //    throw new InvalidOperationException(ex.Message);
            //}
        }
Exemple #8
0
        public Item CreateItem(string name)
        {
            Item item = null;

            switch (name)
            {
            case "HealthPotion": item = new HealthPotion(); break;

            case "PoisonPotion": item = new PoisonPotion(); break;

            case "ArmorRepairKit": item = new ArmorRepairKit(); break;

            default:
                throw new ArgumentException($"Invalid item \"{name}\"!");
            }

            return(item);
        }
Exemple #9
0
        public Item CreateItem(string itemType)
        {
            Item item = null;

            switch (itemType)
            {
            case "HealthPotion":
                return(item = new HealthPotion());

            case "PoisonPotion":
                return(item = new PoisonPotion());

            case "ArmorRepairKit":
                return(item = new ArmorRepairKit());

            default:
                throw new ArgumentException(string.Format(OutputMessages.InvalidItemType), itemType);
            }
        }
Exemple #10
0
    public Item ProduceItem(string itemType)
    {
        Item item = null;

        switch (itemType)
        {
        case "ArmorRepairKit":
            item = new ArmorRepairKit();
            break;

        case "HealthPotion":
            item = new HealthPotion();
            break;

        case "PoisonPotion":
            item = new PoisonPotion();
            break;
        }

        return(item);
    }
Exemple #11
0
        public Item CreateItem(string itemName)
        {
            Item item;

            if (itemName == "HealthPotion")
            {
                item = new HealthPotion();
            }
            else if (itemName == "PoisonPotion")
            {
                item = new PoisonPotion();
            }
            else if (itemName == "ArmorRepairKit")
            {
                item = new ArmorRepairKit();
            }
            else
            {
                throw new ArgumentException($"Invalid item \"{itemName}\"!");
            }
            return(item);
        }
Exemple #12
0
 public Item createItem(string name)
 {
     if (name == "HealthPotion")
     {
         HealthPotion healthPotion = new HealthPotion();
         return(healthPotion);
     }
     else if (name == "PoisonPotion")
     {
         PoisonPotion poisonPotion = new PoisonPotion();
         return(poisonPotion);
     }
     else if (name == "ArmorRepairKit")
     {
         ArmorRepairKit armorRepairKit = new ArmorRepairKit();
         return(armorRepairKit);
     }
     else
     {
         throw new ArgumentException($"Invalid item \"{name}\"!");
     }
 }
Exemple #13
0
    public Item CreateItem(string[] args)
    {
        string itemName = args[0];

        Item item = null;

        if (itemName == "ArmorRepairKit")
        {
            item = new ArmorRepairKit();
            return(item);
        }
        else if (itemName == "HealthPotion")
        {
            item = new HealthPotion();
            return(item);
        }
        else if (itemName == "PoisonPotion")
        {
            item = new PoisonPotion();
            return(item);
        }
        throw new ArgumentException($"Invalid item \"{ itemName }\"");
    }
Exemple #14
0
    public Item CreateItem(string itemName)
    {
        Item item = null;

        switch (itemName)
        {
        case "ArmorRepairKit":
            item = new ArmorRepairKit();
            break;

        case "HealthPotion":
            item = new HealthPotion();
            break;

        case "PoisonPotion":
            item = new PoisonPotion();
            break;

        default:
            throw new ArgumentException(string.Format(Messages.InvalidItemName, itemName));
        }
        return(item);
    }
        public Item CreateItem(string nameParam)
        {
            var name = nameParam;

            if (name != "HealthPotion" && name != "PoisonPotion" && name != "ArmorRepairKit")
            {
                throw new ArgumentException(/*string.Format(Inputs.InvalidItemType, name)*/ $"Invalid item \"{name}\"!");
            }
            if (name == "HealthPotion")
            {
                var healthPotion = new HealthPotion();
                return(healthPotion);
            }
            else if (name == "PoisonPotion")
            {
                var poisonPotion = new PoisonPotion();
                return(poisonPotion);
            }
            else
            {
                var armorRepairKit = new ArmorRepairKit();
                return(armorRepairKit);
            }
        }
Exemple #16
0
        public Item CreateItem(string name)
        {
            Item currentItem = null;

            switch (name)
            {
            case "ArmorRepairKit":
                currentItem = new ArmorRepairKit();
                break;

            case "HealthPotion":
                currentItem = new HealthPotion();
                break;

            case "PoisonPotion":
                currentItem = new PoisonPotion();
                break;

            default:
                Error.InvalidItemType(name);
                break;
            }
            return(currentItem);
        }