Esempio n. 1
0
        public void TestMonsterAttack()
        {
            GameObject Player = new GameObject();
            GameObject Monster = new GameObject();
            GameObject MonsterSword = new GameObject(false, false);
            GameTime gameTime = new GameTime();
            MonsterSword.AddBehaviour("WeaponBehaviour",new WeaponBehaviour()
            {
                Wielder = Monster
            });
            Monster.AddBehaviour("MonsterAttack", new MonsterAttack(Player));
            Monster.AddBehaviour("AttackBehaviour" ,new AttackBehaviour(MonsterSword));
            Monster.AddBehaviour("StatBehaviour",new StatBehaviour(100, 100, 0.1f));
            Monster.Position = new Vector2(100, 100);
            Monster.Rotation = MathHelper.ToRadians(180);
            Player.Position = new Vector2(100, 130);

            Monster.OnUpdate(gameTime);

            var attackBehaviour = Monster.GetBehaviourOfType("AttackBehaviour");
            var monsterAttackBehaviour = Monster.GetBehaviourOfType("MonsterAttack");
            var weaponBehaviour = MonsterSword.GetBehaviourOfType("WeaponBehaviour");

            Assert.IsTrue((monsterAttackBehaviour as MonsterAttack).CheckRange());
            Assert.AreEqual(TimeSpan.FromMilliseconds(1050), (attackBehaviour as AttackBehaviour).Cooldown);
            Assert.IsTrue((weaponBehaviour as WeaponBehaviour).SwingSword);

            Player.Position = new Vector2(300, 300);

            Monster.OnUpdate(gameTime);
            MonsterSword.OnUpdate(gameTime);

            Assert.IsFalse((monsterAttackBehaviour as MonsterAttack).CheckRange());
            Assert.IsFalse((weaponBehaviour as WeaponBehaviour).SwingSword);
        }
Esempio n. 2
0
        public void TestPlayerSwing()
        {
            GameObject Player = new GameObject();
            GameObject PlayerSword = new GameObject(false, false);
            PlayerSword.AddBehaviour("WeaponBehaviour", new WeaponBehaviour()
            {
                Wielder = Player
            });
            bool Clicked = true;
            Player.AddBehaviour("InputMovementBehaviour",new InputMovementBehaviour(5f, new FollowCamera()));
            Player.AddBehaviour("MovementBehaviour", new MovementBehaviour());
            Player.AddBehaviour("AttackBehaviour", new AttackBehaviour(PlayerSword));
            Player.AddBehaviour("StatBehaviour", new StatBehaviour(100, 100, 0.1f));
            var inputBehaviour = Player.GetBehaviourOfType("InputMovementBehaviour");
            var weaponBehaviour = PlayerSword.GetBehaviourOfType("WeaponBehaviour");
            var attackBehaviour = Player.GetBehaviourOfType("AttackBehaviour");

            if (Clicked)
            {
                (inputBehaviour as InputMovementBehaviour).SwingSword();
            }
            Assert.IsTrue((attackBehaviour as AttackBehaviour).Attack);

            Player.OnUpdate(new GameTime());

            Assert.AreEqual(TimeSpan.FromMilliseconds(700), (attackBehaviour as AttackBehaviour).Cooldown);
            Assert.IsTrue((weaponBehaviour as WeaponBehaviour).SwingSword);
        }
Esempio n. 3
0
        public void TestFindTrue()
        {
            GameObject testObject = new GameObject();
            FOVBehavior testFOV = new FOVBehavior(gameObjects);
            testFOV.ViewDistance = 300;
            testObject.AddBehaviour("FOVBehaviour", testFOV);
            testObject.Rotation = 0;
            testObject.Position = new Vector2(100, 100);
            GameObject testPlayerObject = new GameObject();
            testPlayerObject.AddBehaviour("InputMovementBehaviour",new InputMovementBehaviour(5, new FollowCamera()));
            testPlayerObject.Position = new Vector2(100, 0);

            gameObjects.Add(testObject);
            gameObjects.Add(testPlayerObject);
            testObject.CollidingGameObjects = gameObjects;
            testObject.OnUpdate(time);
            Assert.IsTrue(testFOV.DetectPlayer());
        }
Esempio n. 4
0
 public void TestFindNoPlayer()
 {
     GameObject testObject = new GameObject();
     FOVBehavior testFOV = new FOVBehavior(gameObjects);
     testObject.AddBehaviour("FOVBehaviour", testFOV);
     testObject.Rotation = 0;
     testObject.Position = new Vector2(100, 100);
     gameObjects.Add(testObject);
     testObject.CollidingGameObjects = gameObjects;
     testObject.OnUpdate(time);
     Assert.IsFalse(testFOV.DetectPlayer());
 }