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


C# Thing.GetLocation方法代码示例

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


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

示例1: AddToInventory

 //===================================================================//
 //                           Protected                               //
 //===================================================================//
 /// <summary>
 /// This method allows the derived class, <see cref="Person"/>, and any
 /// other derived classes I end up making, to modify their
 /// <see cref="Inventory"/>  via other functions. For example,
 /// <see cref="Person.TakeOff"/> needs to be able to move an item of
 /// <see cref="Clothing"/> from a <see cref="Person"/>'s
 /// <see cref="Clothes"/> to their <see cref="Inventory"/>.
 /// 
 /// This method is completely unchecked, save for the checks performed
 /// by any of the functions it calls.
 /// 
 /// This method does all three parts of moving the item:
 /// it removes the item from its old location,
 /// adds the item to the new location,
 /// and updates the item's location.
 /// </summary>
 /// <param name="item">
 /// the <see cref="Thing"/> to add to the <see cref="Actor"/>'s
 /// <see cref="Inventory"/>
 /// </param>
 protected void AddToInventory(Thing item)
 {
     item.GetLocation().RemoveThing(item);
     this.inventory.AddThing(item);
     item.SetLocation(this.inventory);
 }
开发者ID:julia-ford,项目名称:Game-Engine,代码行数:29,代码来源:Actor.cs

示例2: 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() + '.'); }
        }
开发者ID:julia-ford,项目名称:Game-Engine,代码行数:44,代码来源:Actor.cs

示例3: PutInto

        /// <summary>
        /// Has the <see cref="Actor"/> try to put
        /// a given <see cref="Thing"/> into a given
        /// <see cref="Container"/>.
        /// </summary>
        /// <param name="item">the <see cref="Thing"/> to place</param>
        /// <param name="container">the <see cref="Container"/> to put it into</param>
        public void PutInto(Thing item, Thing container)
        {
            // if the actor can't see the item, throw an exception
            if(!GameManager.CanSee(this, item)) {
                throw new InteractingWithUnseenThingException(); }

            // if the actor can't see the container, throw an exception
            if(!GameManager.CanSee(this, container)) {
                throw new InteractingWithUnseenThingException(); }

            // if the container is not actually a Container, throw an exception
            if(!typeof(Container).IsAssignableFrom(container.GetType())) {
                throw new PuttingIntoNonContainerException(); }

            // if the item is already in the containter, throw an exception
            if (item.GetLocation() == container) {
                throw new PuttingItemAlreadyInsideException(); }

            // if the item is the container, throw an exception
            if (item == container) {
                throw new PuttingItemIntoItselfException(); }

            // if the actor isn't carrying the item, try taking it instead
            if(!this.Carries(item)) {
                // if the actor is the player, report the auto-correction
                if (GameManager.IsPlayer(this)) {
                    GameManager.ReportIfVisible(this, "((You aren't carrying " + item.GetSpecificName() + ". Trying to take it instead...))"); }
                this.Take(item);
                return; }

            // if the container is closed, try to open it instead
            if (typeof(OpenableContainer).IsAssignableFrom(container.GetType()) && !((OpenableContainer)container).IsOpen()) {
                // if the actor is the player, report the auto-correction
                if (GameManager.IsPlayer(this)) {
                    GameManager.ReportIfVisible(this, "((" + StringManipulator.CapitalizeFirstLetter(container.GetSpecificName()) + " is currently closed. Trying to open it instead..."); }
                this.Open(container);
                return; }

            // TODO: Should actors automatically try to unlock containers?

            // if nothing went wrong, execute normally
            item.GetLocation().RemoveThing(item);
            ((Container)container).AddThing(item);
            item.SetLocation((Container)container);
            GameManager.ReportIfVisible(this, VerbSet.ToPut, item, " into ", container);
        }
开发者ID:julia-ford,项目名称:Game-Engine,代码行数:53,代码来源:Actor.cs

示例4: Wear

        //===================================================================//
        //                            Actions                                //
        //===================================================================//
        /// <summary>
        /// Has the <see cref="Person"/> try to wear the given
        /// <see cref="Thing"/>.
        /// If the <see cref="Person"/> is not carrying the
        /// <see cref="Thing"/>, it has them try to take the
        /// <see cref="Thing"/> instead.
        /// </summary>
        /// 
        /// <param name="item">the <see cref="Thing"/> to try wearing</param>
        /// 
        /// <exception cref="InteractingWithUnseenThingException">
        /// if the <see cref="Person"/> can't see the <see cref="Thing"/>
        /// </exception>
        /// <exception cref="WearingSomethingAlreadyWornException">
        /// if the <see cref="Person"/> is already wearing the
        /// <see cref="Thing"/>
        /// </exception>
        /// <exception cref="WearingSomethingBesidesClothingException">
        /// if the <see cref="Thing"/> is not <see cref="Clothing"/>
        /// </exception>
        public void Wear(Thing item)
        {
            // if the actor can't see the item, throw an exception
            if (!GameManager.CanSee(this, item)) {
                throw new InteractingWithUnseenThingException(); }

            // if the actor is already wearing the item, throw an exception
            else if (this.Wears(item)) {
                throw new WearingSomethingAlreadyWornException(); }

            // if the item isn't actually clothing, throw an exception
            else if (!typeof(Clothing).IsAssignableFrom(item.GetType())) {
                throw new WearingSomethingBesidesClothingException(); }

            // if the actor is not carrying the item, try taking it instead
            else if (!this.Carries(item)) {
                if (GameManager.IsPlayer(this)) {
                    GameManager.ReportIfVisible(this, "((You aren't carrying "
                        + item.GetSpecificName() + "; trying to take it instead...))");
                    this.Take(item); }
                } // end "if the actor is not carrying the item"

            // "happy path"
            else {
                this.clothes.AddThing(item);
                item.GetLocation().RemoveThing(item);
                item.SetLocation(this.clothes);
                GameManager.ReportIfVisible(this, this.GetSpecificName() + ' ' + this.GetConjugatedVerb(VerbSet.ToPut) + " on " + item.GetSpecificName() + '.');
            }
        }
开发者ID:julia-ford,项目名称:Game-Engine,代码行数:53,代码来源:Person.cs

示例5: Wear

        /// <summary>
        /// Has the <see cref="Person"/> try to wear the given
        /// <see cref="Thing"/>.
        /// If the <see cref="Person"/> is not carrying the
        /// <see cref="Thing"/>, it has them try to take the
        /// <see cref="Thing"/> instead.
        /// </summary>
        /// 
        /// <param name="item">the <see cref="Thing"/> to try wearing</param>
        /// 
        /// <exception cref="InteractingWithUnseenThingException">
        /// if the <see cref="Person"/> can't see the <see cref="Thing"/>
        /// </exception>
        /// <exception cref="WearingSomethingAlreadyWornException">
        /// if the <see cref="Person"/> is already wearing the
        /// <see cref="Thing"/>
        /// </exception>
        /// <exception cref="WearingSomethingBesidesClothingException">
        /// if the <see cref="Thing"/> is not <see cref="Clothing"/>
        /// </exception>
        public void Wear(Thing item)
        {
            // if the actor can't see the item, throw an exception
            if (!GameManager.CanSee(this, item)) {
                throw new InteractingWithUnseenThingException(); }

            // if the actor is already wearing the item, throw an exception
            if (this.Wears(item)) {
                throw new WearingSomethingAlreadyWornException(); }

            // if the item isn't actually clothing, throw an exception
            if (!typeof(Clothing).IsAssignableFrom(item.GetType())) {
                throw new WearingSomethingBesidesClothingException(); }

            // if the actor is not carrying the item, try taking it instead
            if (!this.Carries(item)) {
                if (GameManager.IsPlayer(this)) {
                    GameManager.ReportIfVisible(this, "((You aren't carrying "
                        + item.GetSpecificName() +
                        "; trying to take it instead...))"); }
                this.Take(item);
                return; }

            // if thr actor is wearing something that can't be worn at the
            // same time as the item, throw an exception
            foreach(Clothing wornItem in this.clothes.GetContents()) {
                if (wornItem.CannotBeWornWith((Clothing)item)) {
                    throw new WearingWithConflictingItemException(wornItem,
                        item); } }

            // "happy path"
                this.clothes.AddThing(item);
                item.GetLocation().RemoveThing(item);
                item.SetLocation(this.clothes);
                GameManager.ReportIfVisible(this, this.GetSpecificName() + ' '
                    + this.GetConjugatedVerb(VerbSet.ToPut) + " on " +
                    item.GetSpecificName() + '.');
        }
开发者ID:julia-ford,项目名称:Game-Engine,代码行数:58,代码来源:Person.cs

示例6: 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() + '.'); }
        }
开发者ID:julia-ford,项目名称:Game-Engine,代码行数:67,代码来源:Person.cs


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