示例#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((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), (5, 6));
            Assert.AreEqual(false, retVal);

            retVal = false;
            foreach (var item in mySpatialMap.Move((1, 2), (5, 6)))
            {
                retVal = true;
            }
            Assert.AreEqual(false, retVal);
        }
示例#2
0
        public static IDGenerator IDGenerator = new IDGenerator(); // A static IDGenerator that all Entities can access

        //Build a new map with a specified width and height
        public Map(int width, int height)
        {
            _width   = width;
            _height  = height;
            Tiles    = new TileBase[width * height];
            Entities = new MultiSpatialMap <Entity>();
        }
示例#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));

            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());
        }
示例#4
0
        public void MultiSpatialMapAdd()
        {
            var mySpatialMap = new MultiSpatialMap <MyIDImpl>();

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

            mySpatialMap.Add(myId1, (1, 2));
            Assert.Equal(1, mySpatialMap.Count);

            var retVal = mySpatialMap.Contains((1, 2));

            Assert.True(retVal);

            retVal = mySpatialMap.Contains(myId1);
            Assert.True(retVal);

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

            retVal = mySpatialMap.Contains(myId2);
            Assert.False(retVal);

            var count = mySpatialMap.GetItemsAt((1, 2)).Count();

            Assert.Equal(1, count);

            count = mySpatialMap.GetItemsAt((2, 3)).Count();
            Assert.Equal(0, count);

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

            count = mySpatialMap.GetItemsAt((1, 2)).Count();
            Assert.Equal(2, count);
        }
示例#5
0
        public Chunk(int size)
        {
            Size = size;

            Terrain          = new ArrayMapOf <GameObject>(size, size);
            Entities         = new MultiSpatialMap <GameObject>();
            BackgroundColors = new ArrayMapOf <RLColor?>(size, size);
        }
示例#6
0
        public void ManualPrintMultiSpatialMap()
        {
            MultiSpatialMap <MyIDImpl> sm = new MultiSpatialMap <MyIDImpl>();

            sm.Add(new MyIDImpl(1), 1, 2);
            sm.Add(new MyIDImpl(2), 1, 2);

            sm.Add(new MyIDImpl(3), 4, 5);

            Console.WriteLine(sm);
        }
示例#7
0
        public void MultiSpatialMapCreate()
        {
            var mySpatialMap = new MultiSpatialMap <MyIDImpl>();

            Assert.Equal(0, mySpatialMap.Count);
            //mySpatialMap.Remove(new MyIDImpl(0));

            Assert.Empty(mySpatialMap.Items);

            mySpatialMap.Add(new MyIDImpl(0), (2, 2));
            Assert.Single(mySpatialMap.Items);

            Assert.Empty(mySpatialMap.Remove((1, 2)));
        }
示例#8
0
        public void MultiSpatialMapAdd()
        {
            var mySpatialMap = new MultiSpatialMap <MyIDImpl>();

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

            mySpatialMap.Add(myId1, (1, 2));
            Assert.AreEqual(1, mySpatialMap.Count);

            bool retVal = mySpatialMap.Contains((1, 2));

            Assert.AreEqual(true, retVal);

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

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

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

            int count = 0;

            foreach (var item in mySpatialMap.GetItems((1, 2)))
            {
                count++;
            }
            Assert.AreEqual(1, count);

            count = 0;
            foreach (var item in mySpatialMap.GetItems((2, 3)))
            {
                count++;
            }
            Assert.AreEqual(0, count);

            retVal = mySpatialMap.Add(myId2, (1, 2));
            Assert.AreEqual(true, retVal);

            count = 0;
            foreach (var item in mySpatialMap.GetItems((1, 2)))
            {
                count++;
            }
            Assert.AreEqual(2, count);
        }
示例#9
0
        public void MultiSpatialMapRemove()
        {
            var mySpatialMap = new MultiSpatialMap <MyIDImpl>();

            var myId1 = new MyIDImpl(0);
            var myId2 = new MyIDImpl(1);
            var myId3 = new MyIDImpl(2);
            var myId4 = new MyIDImpl(3);

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

            bool retVal = mySpatialMap.Remove(myId1);

            Assert.AreEqual(true, retVal);

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

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

            int count = 0;

            foreach (var i in mySpatialMap.Remove((2, 3)))
            {
                count++;
            }

            Assert.AreEqual(1, count);

            Assert.AreEqual(false, mySpatialMap.Contains((2, 3)));
            Assert.AreEqual(false, mySpatialMap.Contains(myId2));

            retVal = mySpatialMap.Remove(myId1);
            Assert.AreEqual(false, retVal);

            count = 0;
            foreach (var i in mySpatialMap.Remove((5, 6)))
            {
                count++;
            }
            Assert.AreEqual(0, count);
        }
示例#10
0
        public void MultiSpatialMapMoveValid()
        {
            var mySpatialMap = new MultiSpatialMap <MyIDImpl>();

            var myId1 = new MyIDImpl(0);
            var myId2 = new MyIDImpl(1);
            var myId3 = new MyIDImpl(2);
            var myId4 = new MyIDImpl(3);

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

            // Move the two items at (1, 2) to (3, 4) (already occupied location)
            var list = mySpatialMap.MoveValid((1, 2), (3, 4));

            Assert.Equal(2, list.Count);
            Assert.Contains(myId1, list);
            Assert.Contains(myId4, list);
            Assert.Equal(new Point(3, 4), mySpatialMap.GetPositionOf(myId1));
            Assert.Equal(new Point(3, 4), mySpatialMap.GetPositionOf(myId4));
            Assert.Equal(3, mySpatialMap.GetItemsAt((3, 4)).Count());

            var retVal = mySpatialMap.Contains((3, 4));

            Assert.True(retVal);

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

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

            // Move the one item at (2, 3) to (6, 7) (unoccupied location)
            list = mySpatialMap.MoveValid((2, 3), (6, 7));
            Assert.Contains(myId2, list);
            Assert.Single(list);
            Assert.False(mySpatialMap.Contains((2, 3)));
            Assert.True(mySpatialMap.Contains((6, 7)));

            Assert.Single(mySpatialMap.GetItemsAt((6, 7)));
        }
示例#11
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);
        }
示例#12
0
        public void MultiSpatialMapRemove()
        {
            var mySpatialMap = new MultiSpatialMap <MyIDImpl>();

            var myId1 = new MyIDImpl(0);
            var myId2 = new MyIDImpl(1);
            var myId3 = new MyIDImpl(2);
            var myId4 = new MyIDImpl(3);

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

            mySpatialMap.Remove(myId1);


            var retVal = mySpatialMap.Contains(myId1);

            Assert.False(retVal);

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



            Assert.Single(mySpatialMap.Remove((2, 3)));

            Assert.False(mySpatialMap.Contains((2, 3)));
            Assert.False(mySpatialMap.Contains(myId2));

            Assert.Throws <ArgumentException>(() => mySpatialMap.Remove(myId1));


            Assert.Empty(mySpatialMap.Remove((5, 6)));
        }