当前位置: 首页>>代码示例>>C#>>正文


C# Person.AddToInventory方法代码示例

本文整理汇总了C#中Person.AddToInventory方法的典型用法代码示例。如果您正苦于以下问题:C# Person.AddToInventory方法的具体用法?C# Person.AddToInventory怎么用?C# Person.AddToInventory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Person的用法示例。


在下文中一共展示了Person.AddToInventory方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleGatherInteraction

    private void HandleGatherInteraction(string[] commandWords, Person actor)
    {
        bool hasWeapon = false;
        bool hasArmor = false;

        foreach (var item in actor.ListInventory())
        {
            if (item is Weapon)
            {
                hasWeapon = true;
            }

            if (item is Armor)
            {
                hasArmor = true;
            }
        }

        Location currentLocation = DetermineActorLocation(actor);

        if (hasWeapon && actor.Location.LocationType == LocationType.Forest)
        {
            Item gatheredItem = new WoodItem(commandWords[2], currentLocation);
            actor.AddToInventory(gatheredItem);
            this.AddToPerson(actor, gatheredItem);
        }

        if (hasArmor && actor.Location.LocationType == LocationType.Mine)
        {
            Item gatheredItem = new IronItem(commandWords[2], currentLocation);
            actor.AddToInventory(gatheredItem);
            this.AddToPerson(actor, gatheredItem);
        }
    }
开发者ID:NikolovNikolay,项目名称:Exam-Tasks,代码行数:34,代码来源:Program.cs

示例2: AddToPerson

 protected void AddToPerson(Person actor, Item item)
 {
     actor.AddToInventory(item);
     ownerByItem[item] = actor;
 }
开发者ID:Producenta,项目名称:TelerikAcademy,代码行数:5,代码来源:Program.cs

示例3: HandleCraftInteraction

    private void HandleCraftInteraction(string[] commandWords, Person actor)
    {
        string targetItemType = commandWords[2];
        var itemsInActorInventory = actor.ListInventory();
        bool canCraft = false;
        bool hasIron = false;
        bool hasWood = false;
        Location currentLocation = DetermineActorLocation(actor);

        foreach (var item in itemsInActorInventory)
        {
            if (item is IronItem)
            {
                hasIron = true;
            }

            if (item is WoodItem)
            {
                hasWood = true;
            }
        }

        switch (targetItemType)
        {
            case "armor":
                if (hasIron)
                {
                    Item gatheredItem = new Armor(commandWords[3], currentLocation);
                    actor.AddToInventory(gatheredItem);
                    this.AddToPerson(actor, gatheredItem);
                }
                break;
            case "weapon":
                if (hasIron && hasWood)
                {
                    Item gatheredItem = new Weapon(commandWords[3], currentLocation);
                    actor.AddToInventory(gatheredItem);
                    this.AddToPerson(actor, gatheredItem);
                }
                break;
            default:
                break;
        }
    }
开发者ID:NikolovNikolay,项目名称:Exam-Tasks,代码行数:44,代码来源:Program.cs


注:本文中的Person.AddToInventory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。