本文整理汇总了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);
}
}
示例2: AddToPerson
protected void AddToPerson(Person actor, Item item)
{
actor.AddToInventory(item);
ownerByItem[item] = actor;
}
示例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;
}
}