Пример #1
0
 public Battlefield(int width, int height)
 {
     Width  = width;
     Height = height;
     Places = new IBattlefieldPlace[Width, Height];
     Initialize();
     Random = new Random();
 }
Пример #2
0
        public double DistanceTo(IBattlefieldPlace place)
        {
            if (place == null)
            {
                throw new ArgumentNullException(nameof(place));
            }

            return(DistanceTo(place.X, place.Y));
        }
Пример #3
0
 public bool Equals(IBattlefieldPlace other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(X == other.X && Y == other.Y);
 }
Пример #4
0
        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);
        }
Пример #5
0
 /// <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);
Пример #6
0
 /// <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);
Пример #7
0
 internal MoveTowards(IBattlefieldPlace newPlace) =>
Пример #8
0
 public void Is(IBattlefieldPlace place) => Place.Should().Be(place);
Пример #9
0
 public BattlefieldPlaceVerification(IBattlefieldPlace place)
 {
     Place = place;
 }
Пример #10
0
 internal MoveAwayFrom(IBattlefieldPlace place)
 {
     Place = place ?? throw new ArgumentNullException(nameof(place));
 }
Пример #11
0
 public static BattlefieldPlaceVerification That(IBattlefieldPlace place) =>
     new BattlefieldPlaceVerification(place);