Beispiel #1
0
        public void OnMoveDistanceShouldBeCalculatedAccordingBodySpeed()
        {
            //Arrange
            var collisionManager = Substitute.For <IShapeCollisionManager>();

            collisionManager.CheckCollision(Arg.Any <Shape>(), Arg.Any <Shape>()).Returns(false);

            IMapEngine me = Substitute.For <IMapEngine>();

            me.GetBodiesForCollision(Arg.Any <ActiveBody>()).Returns(new List <Body>());

            IPhysicsEngine pe = new PhysicsEngine(collisionManager, me);

            int        playerSpeed         = 10;
            Point      playerStartPosition = new Point(0, 0);
            PlayerBody player = new PlayerBody(new ShapeCircle(10, playerStartPosition), new Vector(1, 1), null, null, 100, 100, "Bob", 10, playerSpeed);

            TimeSpan        moveDuration = new TimeSpan(0, 0, 1);
            GameCommandMove moveCommand  = new GameCommandMove(0, new Vector(0, 1), null, player, moveDuration);

            //Act
            pe.ProcessBodyAction(moveCommand);

            //Assert
            double moveSize = playerSpeed * moveDuration.TotalMilliseconds / 1000.0;

            Assert.IsTrue(player.Shape.Position == new Point(playerStartPosition.X, playerStartPosition.Y + moveSize));
        }
Beispiel #2
0
        public void SameClassActiveBodiesCouldNotMakeDamageToEachOther()
        {
            //Arrange
            Guid ownerId        = Guid.NewGuid();
            var  handlers       = new MechanicEngineHandlersBuilder();
            var  mechanicEngine = Substitute.For <IMechanicEngine>();
            var  player1        = new PlayerBody(null, new Vector(1, 1), mechanicEngine, null, 100, 100, "Bob", 100, 1);
            var  player2        = new PlayerBody(null, new Vector(1, 1), mechanicEngine, null, 100, 100, "Bob", 100, 1);

            player1.SocialGroups.Add("1");
            player2.SocialGroups.Add("1");
            mechanicEngine.FindBody(ownerId).Returns(player1);

            var bulletCollisionHandler = handlers.BuildBulletCollisionHandler(mechanicEngine);
            var bullet = new Bullet(10, 10, 10, new ShapeCircle(10, new Point(0, 0)), new Vector(1, 1), ownerId, mechanicEngine, 0, string.Empty);

            var gameCommand = new GameCommandMove(0, new Vector(1, 1), mechanicEngine, bullet, new TimeSpan());
            var npc         = Substitute.For <NPCAI>(null, mechanicEngine, 0, 100, 100, 1);

            var physicsResult = new PhysicsProcessingResultCollision(new List <Body>()
            {
                player2
            });

            //Act & Assert
            Assert.IsTrue(bulletCollisionHandler.Item1(gameCommand, physicsResult));
            bulletCollisionHandler.Item2(gameCommand, physicsResult);

            Assert.IsTrue(player1.Life == 100 && player2.Life == 100);
        }
Beispiel #3
0
        public void ScoreShouldBeIncreaseAfterBulletCollisionWithEnemy()
        {
            //Arrange
            Guid ownerId        = Guid.NewGuid();
            var  handlers       = new MechanicEngineHandlersBuilder();
            var  mechanicEngine = Substitute.For <IMechanicEngine>();
            var  player         = Substitute.For <CharacterBody>(null, new Vector(1, 1), mechanicEngine, 100, 100, 100, 1);

            mechanicEngine.FindBody(ownerId).Returns(player);

            var bulletCollisionHandler = handlers.BuildBulletCollisionHandler(mechanicEngine);
            var bullet = new Bullet(10, 10, 10, new ShapeCircle(10, new Point(0, 0)), new Vector(1, 1), ownerId, mechanicEngine, 0, string.Empty);

            var gameCommand = new GameCommandMove(0, new Vector(1, 1), mechanicEngine, bullet, new TimeSpan());
            var npc         = Substitute.For <NPCAI>(null, mechanicEngine, 0, 100, 100, 1);

            var physicsResult = new PhysicsProcessingResultCollision(new List <Body>()
            {
                npc
            });

            //Act & Assert
            Assert.IsTrue(bulletCollisionHandler.Item1(gameCommand, physicsResult));
            bulletCollisionHandler.Item2(gameCommand, physicsResult);

            Assert.IsTrue(player.Score == 100);
        }
Beispiel #4
0
        public void BulletShouldNotBeDestroyedWhenCollidedWithIUsableBody()
        {
            //Arrange
            var usableBody = Substitute.For <PassiveBody, IUsableBody>(new ShapeCircle(1, new Point(1, 1)));

            var handlers               = new MechanicEngineHandlersBuilder();
            var mechanicEngine         = Substitute.For <IMechanicEngine>();
            var bulletCollisionHandler = handlers.BuildBulletCollisionHandler(mechanicEngine);
            var bullet = new Bullet(10, 10, 10, new ShapeCircle(10, new Point(0, 0)), new Vector(1, 1), Guid.NewGuid(), mechanicEngine, 0, string.Empty);

            var gameCommand = new GameCommandMove(0, new Vector(1, 1), mechanicEngine, bullet, new TimeSpan());
            var npc         = Substitute.For <NPCAI>(null, mechanicEngine, 0, 100, 100, 1);

            var physicsResult = new PhysicsProcessingResultCollision(new List <Body>()
            {
                usableBody
            });

            //Act & Assert
            Assert.IsFalse(bulletCollisionHandler.Item1(gameCommand, physicsResult));
        }