Ejemplo n.º 1
0
    public override string Execute()
    {
        string heroName  = InputArgs.ElementAt(1);
        IHero  heroFound = container.Heroes.FirstOrDefault(x => x.Name == heroName);

        if (heroFound is null)
        {
            throw new ArgumentException(string.Format(Constants.HeroUnfoundNameError, heroName));
        }

        string itemName          = InputArgs.ElementAt(0);
        var    strengthBonus     = long.Parse(InputArgs.ElementAt(2));
        var    agilityBonus      = long.Parse(InputArgs.ElementAt(3));
        var    intelligenceBonus = long.Parse(InputArgs.ElementAt(4));
        var    hitpointsBonus    = long.Parse(InputArgs.ElementAt(5));
        var    damageBonus       = long.Parse(InputArgs.ElementAt(6));

        IItem newItem = new CommonItem(itemName, strengthBonus, agilityBonus, intelligenceBonus, hitpointsBonus, damageBonus);

        heroFound.AddCommonItem(newItem);

        string resultMessage = string.Format(Constants.ItemCreateMessage, itemName, heroName);

        return(resultMessage);
    }
Ejemplo n.º 2
0
    public string AddItemToHero(List <String> arguments, IHero hero)
    {
        string result = null;

        string itemName          = arguments[0];
        string heroName          = arguments[1];
        int    strengthBonus     = int.Parse(arguments[2]);
        int    agilityBonus      = int.Parse(arguments[3]);
        int    intelligenceBonus = int.Parse(arguments[4]);
        int    hitPointsBonus    = int.Parse(arguments[5]);
        int    damageBonus       = int.Parse(arguments[6]);

        CommonItem newItem = new CommonItem(itemName, strengthBonus, agilityBonus, intelligenceBonus, hitPointsBonus,
                                            damageBonus);

        hero.AddCommonItem(newItem);

        result = string.Format(Constants.ItemCreateMessage, newItem.Name, heroName);
        return(result);
    }