Ejemplo n.º 1
0
        public void MarkArea(MapLocation from, MapLocation to, long fillValue, bool inclusive)
        {
            var difference = from - to;

            // Check where we need to fill in the gap
            if (difference.Abs() > 1)
            {
                var incrementor = difference.Normalized().Abs();

                // If the requested location is going in the negative direction then we need our incrementor
                // to also be pointing in the negative direction.
                if (difference > 0)
                {
                    incrementor *= -1;
                }

                // If we're not inclusive then we want to step back one more (chances are our actual position is out of bounds)
                if (!inclusive)
                {
                    to -= incrementor;
                }

                // We do not want to mark the current location "to" because that's our new headlocation
                for (MapLocation i = from + incrementor; !i.SameAs(to); i += incrementor)
                {
                    Debug.WriteLine("Marking: " + i + " with " + fillValue);
                    _map[i.Row, i.Column] = fillValue;
                }
            }
        }
Ejemplo n.º 2
0
 public long this[MapLocation i]
 {
     get
     {
         return _map[i.Row, i.Column];
     }
     set
     {
         _map[i.Row, i.Column] = value;
     }
 }
Ejemplo n.º 3
0
        private MapLocation validateCycleCollisions(MapLocation headLocation, MapLocation requestedLocation)
        {
            var difference = headLocation - requestedLocation;
            var newLocation = requestedLocation; // No need to clone because we do not change individual members

            // If we have a gap greater than 1 then we need to fill it in
            if (difference.Abs() > 1)
            {
                var incrementor = difference.Normalized().Abs();

                // If the requested location is going in the negative direction then we need our incrementor
                // to also be pointing in the negative direction.
                if (difference > 0)
                {
                    incrementor *= -1;
                }

                var incrementorAbs = incrementor.Abs();
                // We set i = the headlocation + incrementor, the headLocation * incrementor^2 is to ensure that either the row or column is 0'd out
                int start = (headLocation * incrementorAbs + incrementor).NonZeroValue(); // Start one ahead of head location
                int end = (newLocation * incrementorAbs).NonZeroValue(); // End at new location
                int singleIncrementor = incrementor.NonZeroValue(); // Convert incrementer to single value
                var startLocation = headLocation + incrementor;
                int totalIncrements = 0;

                for (int i = start; i != end; i += singleIncrementor)
                {
                    // Add how far we are along to the headlocation and use that as the checking point
                    var checkLocation = startLocation + incrementor * totalIncrements;

                    // Check if the location we're checking is already occupied.  If it is then we had a collision and we've found a new Position
                    if (_map[checkLocation] != 0)
                    {
                        return checkLocation;
                    }

                    totalIncrements++;
                }
            }

            // Everything was ok with the position, return it!
            return newLocation;
        }
Ejemplo n.º 4
0
        public void MarksMapSpaceFillsMapCorrectlyInclusive()
        {
            var headLocation = new MapLocation(50, 50);
            var newLocation = new MapLocation(50, 54);
            var fillValue = 1;
            var inclusive = true;
            var map = new Map(gameConfig.MapConfig);
            var mapMarker = new MapMarker(map);
            var incrementor = new MapLocation(0, 1);

            map[headLocation] = -1;

            mapMarker.MarkArea(headLocation, newLocation, fillValue, inclusive);
            Assert.Equal(map[newLocation], 0);
            Assert.Equal(map[headLocation], -1);

            for (MapLocation i = headLocation + incrementor; !i.SameAs(newLocation); i += incrementor)
            {
                Assert.Equal(map[i], fillValue);
            }
        }
Ejemplo n.º 5
0
 public bool Empty(MapLocation location)
 {
     return !Utilities.OutOfBounds(location) && _map[location.Row, location.Column] == 0;
 }
Ejemplo n.º 6
0
 public bool SameAs(MapLocation mapLocation)
 {
     return Row == mapLocation.Row && Column == mapLocation.Column;
 }
Ejemplo n.º 7
0
 public PendingMovement(MapLocation currentMapLocation, Vector3 startLocation, MovementFlag direction)
 {
     CurrentMapLocation = currentMapLocation;
     StartLocation = startLocation;
     Direction = direction;
 }
Ejemplo n.º 8
0
        private MapLocation validateOutOfBounds(MapLocation headLocation, MapLocation requestedLocation)
        {
            var difference = headLocation - requestedLocation;
            var newLocation = requestedLocation; // No need to clone because we do not change individual members

            if (_utilities.OutOfBounds(newLocation))
            {
                var incrementor = difference.Normalized().Abs();

                // If the requested location is going in the negative direction then we need our incrementor
                // to also be pointing in the negative direction.
                if (difference > 0)
                {
                    incrementor *= -1;
                }

                // Decrement movement position until it is no longer out of bounds
                do
                {
                    newLocation = newLocation - incrementor;
                }
                while (_utilities.OutOfBounds(newLocation));

                // If we're back at our head location then we need to set the position to be out of bounds (by one) (collision)
                if (newLocation.SameAs(headLocation))
                {
                    newLocation += incrementor;
                }
            }

            return newLocation;
        }
Ejemplo n.º 9
0
 public bool OutOfBounds(MapLocation location)
 {
     return RowOutOfBounds(location.Row) || ColumnOutOfBounds(location.Column);
 }
Ejemplo n.º 10
0
 public Vector3 ToPosition(MapLocation position, double y)
 {
     return new Vector3(position.Column * _floorTileSize.Width - _halfMapSize.Width, y, position.Row * _floorTileSize.Height - _halfMapSize.Height);
 }