public void GivenTorpedoes_WhenHitWormhole_ThenTorpedoTraversesWormhole()
        {
            WorldStateService.GenerateStartingWorld();
            var state = WorldStateService.GetState();

            List <Tuple <GameObject, GameObject> > wormholes = state.WormholePairs;
            var wormhole = wormholes[0].Item1;

            var startPosition = new Position(wormhole.Position.X + wormhole.Size + 5,
                                             wormhole.Position.Y + wormhole.Size + 5);
            var torpedo = new TorpedoGameObject()
            {
                Id             = Guid.NewGuid(),
                GameObjectType = GameObjectType.TorpedoSalvo,
                Size           = EngineConfigFake.Value.Torpedo.Size,
                IsMoving       = true,
                Position       = startPosition
            };

            WorldStateService.AddGameObject(torpedo);

            var handler = collisionHandlerResolver.ResolveHandler(wormhole, torpedo);

            handler.ResolveCollision(wormhole, torpedo);

            Assert.IsInstanceOf <WormholeCollisionHandler>(handler);
            Assert.True(torpedo.Position != startPosition);
        }
        public void GivenTorpedo_WhenProcessTick_ThenTorpedoMoves()
        {
            SetupFakeWorld(true, false);
            var bot = FakeGameObjectProvider.GetBotWithActions();

            bot.CurrentHeading = 90;
            bot.Speed          = 20;
            bot.IsMoving       = true;

            var torpedoPosition = VectorCalculatorService.GetPositionFrom(bot.Position, bot.Size + EngineConfigFake.Value.Torpedo.Size + 1, bot.CurrentAction.Heading);
            var torpedoSalvo    = new TorpedoGameObject()
            {
                Id             = Guid.NewGuid(),
                Position       = torpedoPosition,
                Size           = EngineConfigFake.Value.Torpedo.Size,
                Speed          = EngineConfigFake.Value.Torpedo.Speed,
                CurrentHeading = 45,
                FiringPlayerId = bot.Id,
                IsMoving       = true
            };

            WorldStateService.AddGameObject(torpedoSalvo);

            tickProcessingService = new TickProcessingService(
                collisionHandlerResolver,
                VectorCalculatorService,
                WorldStateService,
                collisionService);

            Assert.DoesNotThrow(() => tickProcessingService.SimulateTick());

            Assert.AreNotEqual(torpedoPosition, torpedoSalvo.Position);
        }
        public void GivenTorpedoes_WhenHitPlayer_ThenSmallerAndTorpedoSmaller_AndFiringPlayerLarger()
        {
            SetupFakeWorld(true);
            var bot       = WorldStateService.GetPlayerBots().First();
            var playerBot = FakeGameObjectProvider.GetBotAt(new Position(100, 100));
            var torpedo   = new TorpedoGameObject()
            {
                Id             = Guid.NewGuid(),
                GameObjectType = GameObjectType.TorpedoSalvo,
                Size           = EngineConfigFake.Value.Torpedo.Size,
                IsMoving       = true,
                Position       = new Position(0, 10),
                Speed          = EngineConfigFake.Value.Torpedo.Speed,
                FiringPlayerId = playerBot.Id
            };

            WorldStateService.AddGameObject(torpedo);


            var handler = collisionHandlerResolver.ResolveHandler(torpedo, bot);

            handler.ResolveCollision(torpedo, bot);

            Assert.IsInstanceOf <TorpedoCollisionHandler>(handler);
            Assert.AreEqual(0, torpedo.Size);
            Assert.AreEqual(0, bot.Size);
            Assert.AreEqual(20, playerBot.Size);
        }
        public void GivenTorpedoes_WhenHitAsteroid_ThenSmallerAndTorpedoSmaller()
        {
            SetupFakeWorld(true);
            var superFood      = FakeGameObjectProvider.GetSuperfoodAt(new Position(0, 10));
            var asteroidFields = FakeGameObjectProvider.GetAsteroidFields();
            var asteroidField  = asteroidFields[0];
            var asteroidSize   = asteroidField.Size;


            var torpedo = new TorpedoGameObject()
            {
                Id             = Guid.NewGuid(),
                GameObjectType = GameObjectType.TorpedoSalvo,
                Size           = EngineConfigFake.Value.Torpedo.Size,
                IsMoving       = true,
                Position       = new Position(8, 0)
            };

            WorldStateService.AddGameObject(torpedo);


            var handler = collisionHandlerResolver.ResolveHandler(asteroidField, torpedo);

            handler.ResolveCollision(asteroidField, torpedo);

            Assert.IsInstanceOf <AsteroidFieldCollisionHandler>(handler);
            Assert.Less(torpedo.Size, 10);
            Assert.Less(asteroidField.Size, asteroidSize);
        }
        public void GivenTorpedoes_WhenHitGasCloud_ThenSmallerAndTorpedoSmaller()
        {
            SetupFakeWorld(true);
            List <GameObject> gasClouds = FakeGameObjectProvider.GetGasClouds();
            var gasCloud = gasClouds[0];

            var torpedo = new TorpedoGameObject()
            {
                Id             = Guid.NewGuid(),
                GameObjectType = GameObjectType.TorpedoSalvo,
                Size           = EngineConfigFake.Value.Torpedo.Size,
                IsMoving       = true,
                Position       = new Position(8, 0)
            };

            WorldStateService.AddGameObject(torpedo);


            var handler = collisionHandlerResolver.ResolveHandler(gasCloud, torpedo);

            handler.ResolveCollision(gasCloud, torpedo);

            Assert.IsInstanceOf <GasCloudCollisionHandler>(handler);
            Assert.Less(torpedo.Size, 10);
        }
        public void ProcessAction(BotObject bot)
        {
            var torpedoSalvo = new TorpedoGameObject()
            {
                Id       = Guid.NewGuid(),
                Position = vectorCalculatorService.GetPositionFrom(bot.Position, bot.Size + engineConfig.Torpedo.Size + 1, bot.CurrentAction
                                                                   .Heading),
                Size           = engineConfig.Torpedo.Size,
                Speed          = engineConfig.Torpedo.Speed,
                CurrentHeading = bot.CurrentAction.Heading,
                FiringPlayerId = bot.Id
            };

            bot.Size -= engineConfig.Torpedo.Cost;
            worldStateService.UpdateBotSpeed(bot);

            worldStateService.AddGameObject(torpedoSalvo);
        }
        public void GivenTorpedoes_WhenHitFood_ThenSmallerAndTorpedoSmaller()
        {
            SetupFakeWorld(true);
            var food = FakeGameObjectProvider.GetFoodAt(new Position(0, 10));

            var torpedo = new TorpedoGameObject()
            {
                Id             = Guid.NewGuid(),
                GameObjectType = GameObjectType.TorpedoSalvo,
                Size           = EngineConfigFake.Value.Torpedo.Size,
                IsMoving       = true,
                Position       = food.Position
            };

            WorldStateService.AddGameObject(torpedo);

            var handler = collisionHandlerResolver.ResolveHandler(food, torpedo);

            handler.ResolveCollision(food, torpedo);

            Assert.IsInstanceOf <FoodCollisionHandler>(handler);
            Assert.True(torpedo.Size == torpedo.Size - food.Size);
        }