예제 #1
0
        public void Test_ThrowGrenadeAndDamage()
        {
            RoyalGameModel model   = new RoyalGameModel();
            Gamer          player  = BuilderGameObject.CreateGamer(model, new PointF(70, 100));
            Healthy        healthy = player.Components.GetComponent <Healthy>();
            float          startHp = healthy.HP;
            //player.Setup();

            var       grenade     = BuilderGameObject.CreateGrenade(model, new PointF(50, 50), new Vec2(20, 50), new GrenadeBullet());
            SolidBody bodyGrenade = grenade.Components.GetComponent <SolidBody>();
            PointF    startStep   = bodyGrenade.Shape.Location;

            //смотрим как движется граната
            for (int i = 0; i < 44; i++)
            {
                model.Field.Step(0.1f, 6, 3);
                grenade.Update(new TimeQuantPassed(100));
                player.Update(new TimeQuantPassed(100));
                PointF endStep = bodyGrenade.Shape.Location;
                Debug.WriteLine($"{endStep.X}:{endStep.Y}");
                Assert.AreEqual(startHp, healthy.HP);
            }

            model.Field.Step(0.1f, 6, 3);
            grenade.Update(new TimeQuantPassed(100));
            player.Update(new TimeQuantPassed(100));
            Assert.AreEqual(startHp - 50, healthy.HP);
        }
예제 #2
0
        public void Test_UpdateComponent_GoTo()
        {
            var model = new RoyalGameModel();
            //var model = new MockRoyalGameModel();
            //model.Field = new Box2DX.Dynamics.World()
            var player = BuilderGameObject.CreateGamer(model, new System.Drawing.PointF());

            var body = new SolidBody(player);

            player.Components.Add(body);
            player.Setup();

            float    speed    = 8;
            Movement movement = new Movement(player, speed);

            movement.Setup();
            player.Update(new GoTo(player.ID, new Direction(DirectionHorisontal.Left, DirectionVertical.Down)));

            var vector = body.Body.GetLinearVelocity();

            if (vector.X != -speed || vector.Y != -speed)
            {
                Assert.Fail();
            }
        }
예제 #3
0
        public void CreateGamerTest()
        {
            var location = new PointF(10, 10);
            var model    = new RoyalGameModel();
            var obj      = BuilderGameObject.CreateGamer(model, location);

            var solidBody     = obj.Components.GetComponent <SolidBody>();
            var healthy       = obj.Components.GetComponent <Healthy>();
            var collector     = obj.Components.GetComponent <Collector>();
            var currentWeapon = obj.Components.GetComponent <CurrentWeapon>();
            var statistics    = obj.Components.GetComponent <Statistics>();

            Assert.IsNotNull(solidBody);
            Assert.IsNotNull(healthy);
            Assert.IsNotNull(collector);
            Assert.IsNotNull(currentWeapon);
            Assert.IsNotNull(statistics);

            Assert.AreEqual(obj, model.Players.First());
            Assert.AreEqual(obj, model.gameObjects[obj.ID]);
            Assert.AreEqual(location, solidBody.Shape.Location);
            Assert.AreEqual(location, (obj as Gamer).Location);

            Assert.AreEqual(TypesGameObject.Player, obj.Type);
            Assert.AreEqual(false, (obj as Gamer).Destroyed);
            Assert.AreEqual(TypesBehaveObjects.Active, obj.TypeBehave);
        }
예제 #4
0
        public void TestRoomContactListener_Add()
        {
            var Room    = new RoyalGameModel();
            var box     = BuilderGameObject.CreateBox(Room, new PointF(55, 70));
            var player1 = BuilderGameObject.CreateGamer(Room, new PointF(50, 70));

            SolidBody solid = (SolidBody)player1.Components.GetComponent <SolidBody>();

            Room.Field.Step(1 / 60, 6, 3);
            Assert.AreEqual(1, solid.CoveredObjects.Count);
        }
예제 #5
0
        public void TestRoomContactListener_RemoveObject()
        {
            var Room = new RoyalGameModel();

            var box = BuilderGameObject.CreateBox(Room, new PointF(55, 70));

            box.Setup();
            Room.AddOrUpdateGameObject(box);

            var player1 = BuilderGameObject.CreateGamer(Room, new PointF(50, 70));

            SolidBody solid = player1.Components.GetComponent <SolidBody>();

            Room.Field.Step(1f / 60f, 6, 3);
            solid.Parent.Model.Field.DestroyBody(solid.Body);
            Assert.AreEqual(solid.CoveredObjects.Count, 0);
        }
예제 #6
0
        public void TestRoomContactListener_Remove()
        {
            var Room = new RoyalGameModel();

            var box = BuilderGameObject.CreateBox(Room, new PointF(55, 70));

            box.Setup();
            Room.AddOrUpdateGameObject(box);

            var player1 = BuilderGameObject.CreateGamer(Room, new PointF(50, 70));

            SolidBody solid = player1.Components.GetComponent <SolidBody>();

            solid.Body.SetLinearVelocity(new Vec2(0, 40f));
            Room.Field.Step(2, 6, 3);
            //только после 2 перемещения срабатывает потеря наслоения
            Room.Field.Step(1f / 60f, 6, 3);
            Assert.AreEqual(solid.CoveredObjects.Count, 0);
        }
예제 #7
0
        public void Test_PickUpWeapon()
        {
            var Room = new RoyalGameModel();

            var gun = BuilderGameObject.CreateGun(Room, new PointF(50, 70));

            var player1 = BuilderGameObject.CreateGamer(Room, new PointF(50, 70));

            Room.Players.Add(player1);

            Room.Field.Step(1f / 60f, 6, 3);

            //поднимаем оружие
            player1.Update(new TryPickUp(player1.ID));
            player1.Update(new TimeQuantPassed(1));
            var collector = player1.Components.GetComponent <Collector>();

            var received_gun = collector.GetWeapon(TypesWeapon.Gun);

            Assert.AreEqual(gun, received_gun);
        }
예제 #8
0
        public void Test_Dispose()
        {
            var Room = new RoyalGameModel();
            var gun  = BuilderGameObject.CreateGun(Room, new PointF(50, 70));

            var player1 = BuilderGameObject.CreateGamer(Room, new PointF(50, 70));

            Room.Field.Step(1f / 60f, 6, 3);

            //поднимаем оружие
            player1.Update(new TryPickUp(player1.ID));
            player1.Update(new TimeQuantPassed(1));
            var collector = player1.Components.GetComponent <Collector>();

            Assert.IsNotNull(collector.GetWeapon(TypesWeapon.Gun));
            Assert.IsNull(gun.Components.GetComponent <SolidBody>());

            int objectsInMap = Room.Field.GetBodyCount();

            //уничтожаем игрока
            player1.Update(new GotDamage(player1.ID, 100));
            player1.Dispose();

            Assert.AreEqual(objectsInMap, Room.Field.GetBodyCount());
            Assert.IsNotNull(gun.Components.GetComponent <SolidBody>());

            //отслеживаем движение
            var    bodyGun   = gun.Components.GetComponent <SolidBody>();
            PointF startStep = bodyGun.Shape.Location;

            for (int i = 0; i < 45; i++)
            {
                Room.Field.Step(0.1f, 6, 3);
                gun.Update(new TimeQuantPassed(100));
                PointF endStep = bodyGun.Shape.Location;
                Debug.WriteLine($"{endStep.X}:{endStep.Y}");
                Assert.AreNotEqual(startStep, endStep);
                startStep = endStep;
            }
        }
예제 #9
0
        public void Test_UpdateComponent_MakeShot()
        {
            //создаем коллекцию объектов для теста
            var Room = new RoyalGameModel();

            var gun     = BuilderGameObject.CreateGun(Room, new PointF(50, 70));
            var player1 = BuilderGameObject.CreateGamer(Room, new PointF(50, 70));
            var player2 = BuilderGameObject.CreateGamer(Room, new PointF(35, 75));

            Room.Field.Step(1f / 60f, 6, 3);
            //поднимаем оружие
            player1.Update(new TryPickUp(player1.ID));
            player1.Update(new TimeQuantPassed(1));
            CurrentWeapon currentWeapon = player1.Components.GetComponent <CurrentWeapon>();

            Assert.IsNotNull(currentWeapon.GetCurrentWeapon);
            //делаем выстрел
            player1.Update(new MakeShot(player1.ID, new PointF(35, 75)));
            player1.Update(new TimeQuantPassed(100));
            //проверяем
            player2.Update(new TimeQuantPassed(100));
            Healthy healtySecondGamer = player2.Components.GetComponent <Healthy>();

            Assert.AreEqual(92, healtySecondGamer.HP);

            //делаем 2 выстрел
            player1.Update(new MakeShot(player1.ID, new PointF(35, 75)));
            player1.Update(new TimeQuantPassed(401));
            //выстрел не должен произойти
            player2.Update(new TimeQuantPassed(401));
            Assert.AreEqual(92, healtySecondGamer.HP);

            Thread.Sleep(550);
            //делаем 3 выстрел
            player1.Update(new MakeShot(player1.ID, new PointF(35, 75)));
            player1.Update(new TimeQuantPassed(100));
            //выстрел должен произойти
            player2.Update(new TimeQuantPassed(100));
            Assert.AreEqual(healtySecondGamer.HP, 84);
        }
예제 #10
0
        public void Test_UpdateComponent_TimeQuantPassed()
        {
            var Room    = new RoyalGameModel();
            var player1 = BuilderGameObject.CreateGamer(Room, new PointF(50, 70));

            SolidBody  solid        = player1.Components.GetComponent <SolidBody>();
            RectangleF compareShape = solid.Shape;

            Assert.AreEqual(solid.Shape, compareShape);
            Vec2 compareVec = solid.Body.GetPosition();

            solid.Body.SetLinearVelocity(new Vec2(40f, 0));

            int quantTime = 60;

            Room.Field.Step((float)quantTime / 1000f, 8, 3);
            var A = solid.Body.GetPosition();

            Assert.AreNotEqual(A, compareVec);

            player1.Update(new TimeQuantPassed(quantTime));
            Assert.AreNotEqual(solid.Shape, compareVec);
        }