本文整理汇总了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;
}
}
示例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);
}
示例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);
}