public void CreateGunTest()
        {
            var location = new PointF(10, 10);
            var model    = new RoyalGameModel();
            var obj      = BuilderGameObject.CreateGun(model, location);

            var solidBody = obj.Components.GetComponent <SolidBody>();
            var shot      = obj.Components.GetComponent <Shot>();
            var magazin   = obj.Components.GetComponent <Magazin>();

            Assert.IsNotNull(solidBody);
            Assert.IsNotNull(shot);
            Assert.IsNotNull(magazin);

            Assert.AreEqual(location, solidBody.Shape.Location);
            Assert.AreEqual(obj, model.gameObjects[obj.ID]);
            Assert.AreEqual(TypesGameObject.Weapon, obj.Type);
            Assert.AreEqual(TypesWeapon.Gun, (obj as IWeapon).TypeWeapon);
            Assert.AreEqual(TypesBehaveObjects.Active, obj.TypeBehave);
        }
Beispiel #2
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);
        }
Beispiel #3
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;
            }
        }
Beispiel #4
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);
        }