public Battlefield(int width, int height) { Width = width; Height = height; Places = new IBattlefieldPlace[Width, Height]; Initialize(); Random = new Random(); }
public double DistanceTo(IBattlefieldPlace place) { if (place == null) { throw new ArgumentNullException(nameof(place)); } return(DistanceTo(place.X, place.Y)); }
public bool Equals(IBattlefieldPlace other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(X == other.X && Y == other.Y); }
private Direction GetDirectionTo(IBattlefieldPlace newPlace) { var direction = Direction.None; if (newPlace.X == Position.X && newPlace.Y == Position.Y - 1) { direction = Direction.South; } if (newPlace.X == Position.X && newPlace.Y == Position.Y + 1) { direction = Direction.North; } if (newPlace.X == Position.X + 1 && newPlace.Y == Position.Y) { direction = Direction.East; } if (newPlace.X == Position.X - 1 && newPlace.Y == Position.Y) { direction = Direction.West; } if (newPlace.X == Position.X - 1 && newPlace.Y == Position.Y - 1) { direction = Direction.SouthWest; } if (newPlace.X == Position.X + 1 && newPlace.Y == Position.Y - 1) { direction = Direction.SouthEast; } if (newPlace.X == Position.X - 1 && newPlace.Y == Position.Y + 1) { direction = Direction.NorthWest; } if (newPlace.X == Position.X + 1 && newPlace.Y == Position.Y + 1) { direction = Direction.NorthEast; } return(direction); }
/// <summary> /// Move away from a specified <paramref name="place"/>. /// Move direction is calculated to find place /// which is farthest from specified <paramref name="place"/>. /// </summary> /// <param name="place">A place to move away from.</param> /// <returns> /// Turn action to move away from a specified <paramref name="place"/>. /// </returns> /// <exception cref="ArgumentNullException">If parameter <paramref name="place"/> is <c>null</c>.</exception> public static ITurnAction AwayFrom(IBattlefieldPlace place) => new MoveAwayFrom(place);
/// <summary> /// Move towards a specified target <paramref name="place"/>. /// Move direction is calculated to find shortest path <paramref name="place"/>. /// </summary> /// <param name="place">A target place to move.</param> /// <returns> /// Turn action to move towards a specified <paramref name="place"/>. /// </returns> /// <exception cref="ArgumentNullException">If parameter <paramref name="place"/> is <c>null</c>.</exception> public static ITurnAction Towards(IBattlefieldPlace place) => new MoveTowards(place);
internal MoveTowards(IBattlefieldPlace newPlace) =>
public void Is(IBattlefieldPlace place) => Place.Should().Be(place);
public BattlefieldPlaceVerification(IBattlefieldPlace place) { Place = place; }
internal MoveAwayFrom(IBattlefieldPlace place) { Place = place ?? throw new ArgumentNullException(nameof(place)); }
public static BattlefieldPlaceVerification That(IBattlefieldPlace place) => new BattlefieldPlaceVerification(place);