本文整理汇总了C#中Thing.CanBeTaken方法的典型用法代码示例。如果您正苦于以下问题:C# Thing.CanBeTaken方法的具体用法?C# Thing.CanBeTaken怎么用?C# Thing.CanBeTaken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thing
的用法示例。
在下文中一共展示了Thing.CanBeTaken方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Take
/// <summary>
/// Has the <see cref="Actor"/> try to take a <see cref="Thing"/>
/// that they can see.
/// </summary>
/// <param name="item">the <see cref="Thing"/> to take</param>
/// <exception cref="TakingItemFlaggedUntakeableException">
/// if the <see cref="Thing"/> has been flagged as untakeable
/// </exception>
/// <exception cref="TakingThingNotVisibleException">
/// if the <see cref="Actor"/> cannot see the <see cref="Thing"/>
/// </exception>
public void Take(Thing item)
{
// if the actor can't see the item, throw an exception
if (!GameManager.CanSee(this, item)) {
throw new InteractingWithUnseenThingException(); }
// if the item can never be taken, throw an exception
else if (!item.CanBeTaken()) {
throw new TakingItemFlaggedUntakeableException(); }
// if the actor is already carrying the item, throw an exception
else if (this.Carries(item)) {
throw new TakingItemAlreadyHeldException(); }
// if the actor is a person who is wearing the item,
// throw an exception for now
else if (typeof(Person).IsAssignableFrom(this.GetType())
&& ((Person)this).Wears(item)) {
throw new Exception("Taking off is not coded for yet."); }
// if the item is worn by someone else or is inside something
// worn by someone else, throw an exception, for now
else if (typeof(Clothes) == GameManager.GetTopMostVisibleContainer(item.GetLocation()).GetType()) {
throw new Exception("Theft has not been coded yet."); }
// The actor can see the item, and it is not being worn or carried.
// This is the "happy path." Execute as normal.
else {
item.GetLocation().RemoveThing(item);
item.SetLocation(this.inventory);
this.inventory.AddThing(item);
GameManager.ReportIfVisible(this, StringManipulator.CapitalizeFirstLetter(this.GetQualifiedName()) + ' ' + VerbSet.GetForm(VerbSet.ToTake, this.pronouns) + ' ' + item.GetSpecificName() + '.'); }
}
示例2: Take
//===================================================================//
// Actions //
//===================================================================//
/// <summary>
/// Has the <see cref="Person"/> try to take a <see cref="Thing"/>
/// that they can see.
/// </summary>
///
/// <param name="item">the <see cref="Thing"/> to take</param>
///
/// <exception cref="InteractingWithUnseenThingException">
/// if the <see cref="Person"/> cannot see the <see cref="Thing"/>
/// </exception>
///
/// <exception cref="TakingItemFlaggedUntakeableException">
/// if the <see cref="Thing"/> has been flagged as untakeable
/// </exception>
///
/// <exception cref="TakingWithHandsFullException">
/// if the <see cref="Person"/>'s hands are too full
/// </exception>
public override void Take(Thing item)
{
// if the person can't see the item, throw an exception
if (!GameManager.CanSee(this, item)) {
throw new InteractingWithUnseenThingException(); }
// if the item can never be taken, throw an exception
else if (!item.CanBeTaken()) {
throw new TakingItemFlaggedUntakeableException(); }
// if the person is already carrying the item, throw an exception
else if (this.Carries(item)) {
throw new TakingItemAlreadyHeldException(); }
// if the personis wearing the item, try taking it off instead
else if (this.Wears(item)) {
// if the person is the player, report the auto-correction
if(GameManager.IsPlayer(this)) {
GameManager.ReportIfVisible(this,
"((I think you meant \"take off\" instead of " +
"\"take.\" Trying that instead...))"); }
this.TakeOff(item); }
// if the item is worn by someone else or is inside something
// worn by someone else, throw an exception, for now
else if (typeof(Clothes) == GameManager.GetTopMostVisibleContainer(
item.GetLocation()).GetType()) {
throw new Exception("Theft has not been coded yet."); }
// if neither hand is free or if only one hand is free and the item
// requires two hands, throw an exception
else if (!hands.HasFreeHand() ||
(item.IsTwoHanded() && !hands.IsEmpty())) {
throw new TakingWithHandsFullException(); }
// No problems encountered; execute normally.
else {
item.GetLocation().RemoveThing(item);
this.hands.AddThing(item);
item.SetLocation(this.hands);
GameManager.ReportIfVisible(this,
StringManipulator.CapitalizeFirstLetter(
this.GetQualifiedName()) + ' ' +
this.GetConjugatedVerb(VerbSet.ToPickUp) + ' ' +
item.GetSpecificName() + '.'); }
}