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


C# ICharacter.Move方法代码示例

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


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

示例1: Input

        private void Input(ICharacter player)
        {
            var info = Console.ReadKey();

            switch (info.Key)
            {
                case ConsoleKey.Spacebar:
                    var ninja = Enemies.FirstOrDefault();

                    player.Atack(ninja);

                    if (ninja != null && ninja.Blood == 0)
                    {
                        Enemies.Remove(ninja);
                    }
                    break;

                case ConsoleKey.LeftArrow:
                    player.Move(Direction.Left);
                    break;

                case ConsoleKey.UpArrow:
                    player.Move(Direction.Up);
                    break;

                case ConsoleKey.RightArrow:
                    player.Move(Direction.Right);
                    break;

                case ConsoleKey.DownArrow:
                    player.Move(Direction.Down);
                    break;
            }
        }
开发者ID:jcrey,项目名称:Scio.CSharp.Training,代码行数:34,代码来源:TheKidnapLevel.cs

示例2: Choose

        private int Choose(ICharacter player)
        {
            ICharacter target = new Enemy();

            var random = new Random();

            ConsoleKeyInfo option = Console.ReadKey(true);

            switch (option.Key)
            {
                case ConsoleKey.Escape:
                    Environment.Exit(0);
                    break;

                case ConsoleKey.A:
                    player.Move(Direction.Up);
                    break;

                case ConsoleKey.B:
                    player.Atack(target);
                    break;
                
            }

            return random.Next(0, 1980);
        }
开发者ID:jcrey,项目名称:Scio.CSharp.Training,代码行数:26,代码来源:TheLostCavernsOfTsojcanth.cs

示例3: MoveOccupantToRoom

        /// <summary>
        /// Adds the occupant to this instance.
        /// </summary>
        /// <param name="character">The character.</param>
        /// <exception cref="System.NullReferenceException">Attempted to add a null character to the Room.</exception>
        public void MoveOccupantToRoom(ICharacter character, DefaultRoom departingRoom)
        {
            // We don't allow the user to enter a disabled room.
            if (!this.IsEnabled)
            {
                // TODO: Need to do some kind of communication back to the caller that this can't be traveled to.
                throw new InvalidOperationException("The room is disabled and can not be traveled to.");
            }

            if (character == null)
            {
                throw new NullReferenceException("Attempted to add a null character to the Room.");
            }

            // Remove the character from their previous room.
            //Find the doorway that the character traveled through
            DefaultDoorway doorwayTraveledThrough =
                departingRoom?.Doorways.FirstOrDefault(door => door.ArrivalRoom == this);

            // Get the opposite direction of the doorways travel direction. This will be the direction that they entered from
            // within this instance's available entry points.
            ITravelDirection enteredDirection = doorwayTraveledThrough?.DepartureDirection.GetOppositeDirection();

            // Handle removing the occupant from the previous room. The character might handle this for us
            // so our RemoveOccupantFromRoom implementation will try to remove safely.
            departingRoom?.TryRemoveOccupantFromRoom(character, doorwayTraveledThrough.DepartureDirection, this);

            this.Occupants.Add(character);
            character.Deleted += this.OnCharacterDeletingStarting;
            // Notify our event handles that the character has entered the room.
            this.OnEnteringRoom(character, enteredDirection, departingRoom);
            character.Move(enteredDirection, this);
        }
开发者ID:ramseur,项目名称:MudDesigner,代码行数:38,代码来源:DefaultRoom.cs


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