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


C# Thing.Add方法代码示例

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


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

示例1: Move

        // @@@ OpensClosesBehavior needs to listen for movement events and set e.Cancel if the transition object
        //     is closed at the time.
        /// <summary>
        /// Move the entity to the specified room.
        /// </summary>
        /// <param name="destination">
        /// @@@ TODO: The destination to move the entity to; if the destination has an ExitBehavior then this Thing is
        /// automatically moved to the other destination of the exit (IE an adjacent room, portal destination,
        /// or inside/outside of a vehicle, et cetera).
        /// </param>
        /// <param name="goingVia">The thing we are travelling via (IE an Exit, an Enterable thing, etc.)</param>
        /// <param name="leavingMessage">A sensory message describing this sort of 'leaving' movement.</param>
        /// <param name="arrivingMessage">A sensory message describing this sort of 'arriving' movement.</param>
        /// <returns>True if the entity was successfully moved, else false.</returns>
        public bool Move(Thing destination, Thing goingVia, SensoryMessage leavingMessage, SensoryMessage arrivingMessage)
        {
            Thing actor = this.Parent;
            Thing goingFrom = actor.Parent;

            // Prepare events to request and send (if not cancelled).
            var leaveEvent = new LeaveEvent(actor, goingFrom, destination, goingVia, leavingMessage);
            var arriveEvent = new ArriveEvent(actor, goingFrom, destination, goingVia, arrivingMessage);

            // Broadcast the Leave Request first to see if the player is allowed to leave.
            actor.Eventing.OnMovementRequest(leaveEvent, EventScope.ParentsDown);
            if (!leaveEvent.IsCancelled)
            {
                // Next see if the player is allowed to Arrive at the new location.
                destination.Eventing.OnMovementRequest(arriveEvent, EventScope.SelfDown);
                if (!arriveEvent.IsCancelled)
                {
                    actor.Eventing.OnMovementEvent(leaveEvent, EventScope.ParentsDown);
                    actor.RemoveFromParents();
                    destination.Add(actor);

                    // @@@ TODO: Ensure these automatically enqueue a save.
                    destination.Eventing.OnMovementEvent(arriveEvent, EventScope.SelfDown);
                    return true;
                }
            }

            return false;
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:43,代码来源:MovableBehavior.cs

示例2: TestMultipleParentingBehavior

        public void TestMultipleParentingBehavior()
        {
            // Verify we can add and retrieve the MultipleParentsBehavior of a Thing.
            this.child.Behaviors.Add(this.multipleParentsBehavior);
            Verify.IsTrue(this.child.Behaviors.FindFirst<MultipleParentsBehavior>() == this.multipleParentsBehavior);

            // Verify it can now be a child of multiple parents, and one of those can be found as the primary Parent.
            this.parent1.Add(this.child);
            this.parent2.Add(this.child);
            Verify.IsTrue(this.parent1.Children.Contains(this.child));
            Verify.IsTrue(this.parent2.Children.Contains(this.child));
            Verify.IsTrue(this.child.Parent == this.parent1 || this.child.Parent == this.parent2);

            // Verify we can remove the item from a secondary parent, and still be attached well to the primary.
            this.parent2.Remove(this.child);
            Verify.IsTrue(this.parent1.Children.Contains(this.child));
            Verify.IsTrue(!this.parent2.Children.Contains(this.child));
            Verify.IsTrue(this.child.Parent == this.parent1);
            this.parent2.Add(this.child);

            // Verify we can remove the item from a primary parent, and a secondary parent becomes the primary.
            this.parent1.Remove(this.child);
            Verify.IsTrue(!this.parent1.Children.Contains(this.child));
            Verify.IsTrue(this.parent2.Children.Contains(this.child));
            Verify.IsTrue(this.child.Parent == this.parent2);
            this.parent1.Add(this.child);

            // Verify we can be attached to more than 2 parents.
            Thing parent3 = new Thing() { Name = "Thing3", ID = TestThingID.Generate("testthing") };
            parent3.Add(this.child);
            Verify.IsTrue(this.parent1.Children.Contains(this.child));
            Verify.IsTrue(this.parent2.Children.Contains(this.child));
            Verify.IsTrue(parent3.Children.Contains(this.child));
            Verify.IsTrue(this.child.Parent != null);
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:35,代码来源:TestMultipleParentsBehavior.cs

示例3: TestOpeningClosingAndMovementForExits

        public void TestOpeningClosingAndMovementForExits()
        {
            // Create two one-way exits and two rooms to attach them to.
            var openableExitA = new Thing() { Name = "OpenableExitA", ID = TestThingID.Generate("testthing") };
            var openableExitB = new Thing() { Name = "OpenableExitB", ID = TestThingID.Generate("testthing") };
            var roomA = new Thing(new RoomBehavior()) { Name = "Room A", ID = TestThingID.Generate("testroom") };
            var roomB = new Thing(new RoomBehavior()) { Name = "Room B", ID = TestThingID.Generate("testroom") };
            roomA.Add(openableExitA);
            roomB.Add(openableExitB);

            // Attach ExitBehavior and OpensClosesBehaviors in different orders though, to verify in test that
            // eventing and such work correctly regardless of attachment order.
            var exitBehaviorA = new ExitBehavior();
            var exitBehaviorB = new ExitBehavior();
            var opensClosesBehaviorB = new OpensClosesBehavior();
            openableExitA.Behaviors.Add(exitBehaviorA);
            openableExitA.Behaviors.Add(this.opensClosesBehavior);
            openableExitB.Behaviors.Add(opensClosesBehaviorB);
            openableExitB.Behaviors.Add(exitBehaviorB);

            // Rig up behaviors so the actor can move, and move from one A to B, and from B to A.
            this.actingThing.Behaviors.Add(new MovableBehavior());
            exitBehaviorA.AddDestination("toB", roomB.ID);
            exitBehaviorB.AddDestination("toA", roomA.ID);

            // Ensure that the actingThing cannot move through either exit while it is in default (closed) state.
            roomA.Add(this.actingThing);
            exitBehaviorA.MoveThrough(this.actingThing);
            Verify.AreSame(roomA, this.actingThing.Parent);

            roomB.Add(this.actingThing);
            exitBehaviorB.MoveThrough(this.actingThing);
            Verify.AreSame(roomB, this.actingThing.Parent);

            // Ensure that the actingThing can open and move through each openable exit to get between rooms.
            opensClosesBehaviorB.Open(this.actingThing);
            exitBehaviorB.MoveThrough(this.actingThing);
            Verify.AreSame(roomA, this.actingThing.Parent);

            this.opensClosesBehavior.Open(this.actingThing);
            exitBehaviorA.MoveThrough(this.actingThing);
            Verify.AreSame(roomB, this.actingThing.Parent);
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:43,代码来源:TestOpensClosesBehavior.cs


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