Пример #1
0
        public void MultiSpatialMapCreate()
        {
            var mySpatialMap = new MultiSpatialMap <MyIDImpl>();

            Assert.AreEqual(0, mySpatialMap.Count);
            bool retVal = mySpatialMap.Remove(new MyIDImpl(0));

            Assert.AreEqual(false, retVal);

            retVal = false;
            foreach (var item in mySpatialMap.Remove(Coord.Get(1, 2)))
            {
                retVal = true;
            }
            Assert.AreEqual(false, retVal);

            retVal = false;
            foreach (var item in mySpatialMap.Items)
            {
                retVal = true;
            }
            Assert.AreEqual(false, retVal);

            retVal = mySpatialMap.Move(new MyIDImpl(0), Coord.Get(5, 6));
            Assert.AreEqual(false, retVal);

            retVal = false;
            foreach (var item in mySpatialMap.Move(Coord.Get(1, 2), Coord.Get(5, 6)))
            {
                retVal = true;
            }
            Assert.AreEqual(false, retVal);
        }
Пример #2
0
        public void MultiSpatialMapMove()
        {
            var mySpatialMap = new MultiSpatialMap <MyIDImpl>();

            var myId1 = new MyIDImpl(0);
            var myId2 = new MyIDImpl(1);

            mySpatialMap.Add(myId1, (1, 2));
            mySpatialMap.Add(myId2, (2, 3));

            mySpatialMap.Move(myId1, (5, 6));
            Assert.Equal(new Point(5, 6), mySpatialMap.GetPositionOf(myId1));

            var retVal = mySpatialMap.Contains((5, 6));

            Assert.True(retVal);

            retVal = mySpatialMap.Contains((1, 2));
            Assert.False(retVal);

            retVal = mySpatialMap.Contains((2, 3));
            Assert.True(retVal);

            mySpatialMap.Move(myId2, (5, 6));


            Assert.False(mySpatialMap.Contains((2, 3)));
            Assert.True(mySpatialMap.Contains((5, 6)));

            Assert.Equal(2, mySpatialMap.GetItemsAt((5, 6)).Count());
        }
Пример #3
0
        public void MultiSpatialMapMove()
        {
            var mySpatialMap = new MultiSpatialMap <MyIDImpl>();

            var myId1 = new MyIDImpl(0);
            var myId2 = new MyIDImpl(1);

            mySpatialMap.Add(myId1, (1, 2));
            mySpatialMap.Add(myId2, (2, 3));

            bool retVal = mySpatialMap.Move(myId1, (5, 6));

            Assert.AreEqual(true, retVal);
            Assert.AreEqual(new Coord(5, 6), mySpatialMap.GetPosition(myId1));

            retVal = mySpatialMap.Contains((5, 6));
            Assert.AreEqual(true, retVal);

            retVal = mySpatialMap.Contains((1, 2));
            Assert.AreEqual(false, retVal);

            retVal = mySpatialMap.Contains((2, 3));
            Assert.AreEqual(true, retVal);

            retVal = mySpatialMap.Move(myId2, (5, 6));
            Assert.AreEqual(true, retVal);

            Assert.AreEqual(false, mySpatialMap.Contains((2, 3)));
            Assert.AreEqual(true, mySpatialMap.Contains((5, 6)));

            int count = 0;

            foreach (var i in mySpatialMap.GetItems((5, 6)))
            {
                count++;
            }
            Assert.AreEqual(2, count);
        }
Пример #4
0
 // When the Entity's .Moved value changes, it triggers this event handler
 // which updates the Entity's current position in the SpatialMap
 private void OnEntityMoved(object sender, Entity.EntityMovedEventArgs args)
 {
     Entities.Move(args.Entity as Entity, args.Entity.Position);
 }