public ComponentManager(ContentManager contentManager, Microsoft.Xna.Framework.GraphicsDeviceManager graphicsDeviceManager)
        {
            _contentManager     = contentManager;
            _resourceRepository = new ResourceRepository(new BasicResourceRepositoryConfiguration(), _contentManager);

            Font = _resourceRepository.GetFont();
            _spaceShipTexture = _resourceRepository.GetTextureByType(typeof(SpaceShip));

            var graphicsDevice = graphicsDeviceManager.GraphicsDevice;

            Configuration = new BasicGameConfiguration(
                _spaceShipTexture.Height,
                Font
                );

            graphicsDeviceManager.PreferredBackBufferWidth  = Configuration.ScreenSize.Width;
            graphicsDeviceManager.PreferredBackBufferHeight = Configuration.ScreenSize.Height;
            graphicsDeviceManager.ApplyChanges();

            SpaceShip      = new SpaceShip(Configuration, new Size(_spaceShipTexture.Width, _spaceShipTexture.Height));
            _ballTexture   = _resourceRepository.GetTextureByType(typeof(BasicBall));
            BallRepository = new BallRepository(Configuration, new Size(_ballTexture.Width, _ballTexture.Height));

            Balls = new List <IBall>();

            _drawer = new ComponentDrawer(graphicsDevice, Font);

            Prizes = new List <IPrize>();
            Shoots = new List <IShoot>();

            MediaPlayer.Volume = .03f;
        }
Beispiel #2
0
        public void IfIGoVeryFastToTheLeftICantGoMoreFarThanTheSpace()
        {
            IGameConfiguration configuration = new BasicGameConfiguration(90, null);
            SpaceShip          spaceShip     = new SpaceShip(configuration, new Size(10, 10));

            spaceShip.Position = new Vector2(2, 0);
            spaceShip.Speed    = new Vector2(-3, 0);
            spaceShip.Move();

            Assert.AreEqual(0, spaceShip.Position.X);

            spaceShip.Move();

            Assert.AreEqual(spaceShip.Speed.X, spaceShip.Position.X);
        }
Beispiel #3
0
        public void IfIGoUpVeryFastICantGoMoreFarThanTheSpace()
        {
            IGameConfiguration configuration = new BasicGameConfiguration(42, null);
            BasicBall          ball          = new BasicBall(configuration, new Size(42, 42));

            ball.Position = new Vector2(42, 3);
            ball.Speed    = new Vector2(42, -4);
            ball.Move();

            Assert.AreEqual(0, ball.Position.Y);

            ball.Move();

            Assert.AreEqual(ball.Speed.Y, ball.Position.Y);
        }
Beispiel #4
0
        public void IfIGoVeryFastToTheRightICantGoMoreFarThanTheSpace()
        {
            int screenWidth = 100, spaceShipWidth = 10;
            IGameConfiguration configuration = new BasicGameConfiguration(90, null);
            SpaceShip          spaceShip = new SpaceShip(configuration, new Size(spaceShipWidth, 10));

            spaceShip.Position = new Vector2(89, 0);
            spaceShip.Speed    = new Vector2(3, 0);
            spaceShip.Move();

            Assert.AreEqual(screenWidth - spaceShipWidth, spaceShip.Position.X);

            spaceShip.Move();

            Assert.AreEqual(spaceShip.Speed.X, (float)Math.Round(screenWidth - spaceShipWidth - spaceShip.Position.X, 2) * -1);
        }
Beispiel #5
0
        public void IfIGoVeryFastToTheLeftICantGoMoreFarThanTheSpace()
        {
            int speed = 4;
            IGameConfiguration configuration = new BasicGameConfiguration(42, null);
            BasicBall          ball          = new BasicBall(configuration, new Size(42, 42));

            ball.Position = new Vector2(speed - 1, 42);
            ball.Speed    = new Vector2(speed * -1, 42);
            ball.Move();

            Assert.AreEqual(0, ball.Position.X);

            ball.Move();

            Assert.AreEqual(ball.Speed.X, ball.Position.X);
        }
Beispiel #6
0
 public void IFindCollisions()
 {
     var configuration = new BasicGameConfiguration(0, null);
     var blocks        = new List <IBlock>()
     {
         new BasicBlock(configuration, new Size(64, 32))
         {
             Position = new Vector2(5, 5)
         }
     };
     var ball = new BasicBall(configuration, new Size(5, 5))
     {
         Position = new Vector2(15, 26.15f), Speed = new Vector2(0, -2)
     };
     var board = new Board(blocks, null, new Size(100, 100), ball.Size.Width * ball.Scale.X);
     var block = board.Collides(ball);
 }
Beispiel #7
0
        public void IfIGoVeryFastToTheRightICantGoMoreFarThanTheSpace()
        {
            int screenWidth = 800, ballWidth = 21, speed = 4;
            int roundErrorForBallScaleFloatValue = 1;
            IGameConfiguration configuration     = new BasicGameConfiguration(42, null);
            BasicBall          ball              = new BasicBall(configuration, new Size(ballWidth, 42));

            ball.Position = new Vector2(screenWidth - ballWidth - speed + 1, 42);
            ball.Speed    = new Vector2(speed, 42);
            ball.Move();

            Assert.AreEqual(screenWidth - ballWidth, ball.Position.X - roundErrorForBallScaleFloatValue);

            ball.Move();

            Assert.AreEqual(ball.Speed.X, (float)Math.Round(screenWidth - ballWidth - ball.Position.X, 2) * -1 - roundErrorForBallScaleFloatValue);
        }