예제 #1
0
        /// <summary>
        /// Spawn worm.
        /// </summary>
        /// <param name="x">Horizontal field position</param>
        /// <param name="y">Vertical field position</param>
        /// <param name="length">Worm length</param>
        /// <param name="color">Worm color</param>
        /// <returns>Worm or null</returns>
        public Worm Spawn(int x, int y, int length, Color color)
        {
            LengthCap = 1;
            Length    = 1;
            moving    = true;

            head.Color = color;

            firstModule = modules.Enable();
            if (firstModule == null)
            {
                Disable(false);
                return(null);
            }
            firstModule.Position = new Vector2(collision.EntityX(x), collision.EntityY(y));
            firstModule.SetTarget(collision.EntityX(x), collision.EntityY(y));
            eraser.X = -size;
            eraser.Y = -size;
            head.SetPosition(firstModule.Position);

            lastModule = firstModule;
            for (int i = 1; i < length; i++)
            {
                Grow();
            }

            direction = Random.ValidDirection(collision, Position, size);
            collision.Set(this, x, y);
            return(this);
        }
예제 #2
0
        public void TestDefragment61()
        {
            Scene             scene    = new Scene();
            Settings          settings = new Settings();
            Pooler <Poolable> pooler   = new Pooler <Poolable>(settings, scene, 5);
            Poolable          p1       = pooler.Enable();
            Poolable          p2       = pooler.Enable();
            Poolable          p3       = pooler.Enable();
            Poolable          p4       = pooler.Enable();
            Poolable          p5       = pooler.Enable();

            p1.Disable();
            p3.Disable();
            Assert.AreEqual(p1, pooler[0], "in method Defragment, line 72");
            Assert.AreEqual(p2, pooler[1], "in method Defragment, line 73");
            Assert.AreEqual(p3, pooler[2], "in method Defragment, line 74");
            Assert.AreEqual(p4, pooler[3], "in method Defragment, line 75");
            Assert.AreEqual(p5, pooler[4], "in method Defragment, line 76");
            try
            {
                Assert.AreEqual(p5, pooler[5], "in method Defragment, line 77");
                Assert.Fail("Did not throw IndexOutOfRangeException in method Defragment on line 76");
            }
            catch (IndexOutOfRangeException)
            {
            }
            Assert.AreEqual(4, pooler.Index, "in method Defragment, line 78");
            Assert.AreEqual(true, pooler[pooler.Index].Active, "in method Defragment, line 79");
            pooler.Defragment();
            Assert.AreEqual(3, pooler.Index, "in method Defragment, line 81");
            Assert.AreEqual(false, pooler[pooler.Index].Active, "in method Defragment, line 82");
            Assert.AreEqual(p5, pooler[0], "in method Defragment, line 83");
            Assert.AreEqual(p2, pooler[1], "in method Defragment, line 84");
            Assert.AreEqual(p4, pooler[2], "in method Defragment, line 85");
            Assert.AreEqual(p3, pooler[3], "in method Defragment, line 86");
            Assert.AreEqual(p1, pooler[4], "in method Defragment, line 87");
        }