Esempio n. 1
0
        /// <summary>
        /// Removes the given entity (non-terrain object) from the map, returning true if it was successfully removed, and false otherwise.
        /// </summary>
        /// <param name="entity">The entity to remove from the map.</param>
        /// <returns>True if the entity was removed successfully, false otherwise (eg, the entity was not part of this map).</returns>
        public bool RemoveEntity(IGameObject entity)
        {
            if (!_entities.Remove(entity))
            {
                return(false);
            }

            entity.OnMapChanged(null);
            return(true);
        }
        public void TestRemove()
        {
            var itemsAdded = new List <MySpatialMapItem>();
            var sm         = new LayeredSpatialMap <MySpatialMapItem>(5);

            for (int i = 0; i < 5; i++)
            {
                var item = new MySpatialMapItem(i);
                itemsAdded.Add(item);
                sm.Add(item, (1, 2));
            }

            bool result;

            var nonAddedItem = new MySpatialMapItem(2);

            result = sm.Remove(nonAddedItem);
            Assert.AreEqual(false, result);

            foreach (var i in itemsAdded)
            {
                result = sm.Remove(i);
                Assert.AreEqual(true, result);
            }


            foreach (var i in itemsAdded)
            {
                sm.Add(i, (1, 2));
            }

            List <MySpatialMapItem> itemsRemoved = sm.Remove((5, 6)).ToList();

            Assert.AreEqual(0, itemsRemoved.Count);

            itemsRemoved = sm.Remove((1, 2)).ToList();
            Assert.AreEqual(itemsAdded.Count, itemsRemoved.Count);
        }
Esempio n. 3
0
 public void RemoveEntity(Entity e)
 {
     entities.Remove(e);
 }