Example #1
0
        public void Update()
        {
            LaserFactory laserFactory = new LaserFactory(laserSpeed, laserWidth, laserHeight, numRows * numColumns);
            BombFactory  bombFactory  = new BombFactory(bombSpeed, bombWidth, bombHeight, numBombSlots);

            ScoreAndLife scoreAndLife = new ScoreAndLife(lives, laserFactory, bombFactory);
            Player       player       = new Player(screenWidth, screenHeight, playerSpeed, playerWidth, playerHeight, laserFactory, bombFactory, scoreAndLife, timerIntervalPlayerRespawn);
            Bunkers      bunkers      = new Bunkers(numBunkers, screenWidth, screenHeight, bunkerWidth, bunkerHeight, bunkerHealth, playerHeight, spaceBetweenBunkerAndPlayer);
            Mothership   mothership   = new Mothership(screenWidth, mothershipWidth, mothershipHeight, mothershipSpeed, mothershipPoints, timerIntervalMothership, mothershipSpacerFromTop);
            //int screenWidth = 100;
            //int alienWidth = 1;
            //int alienHeight = 2;
            //int alienSpeed = 1;
            //int spacer = 1;
            //int numRows = 1;
            //int rowLength = 1;
            //int playerHeight = 0;
            //arrange
            //Bunkers bunkers = new Bunkers(numBunkers, screenWidth, screenHeight, bunkerWidth, bunkerHeight, bunkerHealth, playerHeight, spaceBetweenBunkerAndPlayer);
            BombFactory bf = new BombFactory(0, 0, 0, 0);

            AlienSquad alienS = new AlienSquad(bunkers, bombFactory, laserFactory, player, mothership, scoreAndLife, numRows, numColumns, screenWidth, player.BoundingBox.Height, alienWidth, alienHeight, alienSpeed, spacer, bombFrequency, alienPointStart, alienPointDecrement, alienSpacerFromTop, speedIncrease, bombFrequencyIncrement, bombFrequencyMin);

            //act
            alienS.Update();

            //assert
            //Assert.AreEqual(,); //expected, actual
        }
        public void OnPlayerDeath_gameOver()
        {
            //arrange
            // bool eventCaught=true;
            int lives = 1;
            //int score = 10;
            ScoreAndLife sl         = new ScoreAndLife(lives, laserFactory, bombFactory);
            Player       player     = new Player(screenWidth, screenHeight, playerSpeed, playerWidth, playerHeight, laserFactory, bombFactory, sl, timerIntervalPlayerRespawn);
            Bunkers      bunkers    = new Bunkers(numBunkers, screenWidth, screenHeight, bunkerWidth, bunkerHeight, bunkerHealth, playerHeight, spaceBetweenBunkerAndPlayer);
            Mothership   mothership = new Mothership(screenWidth, mothershipWidth, mothershipHeight, mothershipSpeed, mothershipPoints, timerIntervalMothership, mothershipSpacerFromTop);
            AlienSquad   alienSquad = new AlienSquad(bunkers, bombFactory, laserFactory, player, mothership, sl, numRows, numColumns, screenWidth, player.BoundingBox.Height, alienWidth, alienHeight, alienSpeed, spacer, bombFrequency, alienPointStart, alienPointDecrement, alienSpacerFromTop, speedIncrease, bombFrequencyIncrement, bombFrequencyMin);

            //act
            laserFactory.RegisterAlienSquad(alienSquad);
            laserFactory.RegisterBunkers(bunkers);
            laserFactory.RegisterMothership(mothership);
            //sl.gameOver += delegate()
            //{
            //    eventCaught = true;
            //};
            sl.OnPlayerDeath();
            int result = sl.Lives;

            //assert
            Assert.AreEqual(0, result); //expected, actual
            //Assert.IsTrue(eventCaught);
        }
        public void OnPlayerDeath_HaveLife()
        {
            //arrange
            int lives = 2;
            //int score = 10;
            ScoreAndLife sl = new ScoreAndLife(lives, laserFactory, bombFactory);

            //act
            sl.OnPlayerDeath();
            int result = sl.Lives;

            //assert
            Assert.AreEqual(1, result); //expected, actual
        }
        public void OnAlienDeath()
        {
            //arrange
            int lives = 1;
            //int score=10;
            ScoreAndLife sl = new ScoreAndLife(lives, laserFactory, bombFactory);

            //act
            sl.OnAlienDeath(20);
            int result = sl.Score;

            //assert
            Assert.AreEqual(20, result); //expected, actual
        }
        public void MoveLeft_EnoughSpace()
        {
            int          playerW      = 10;
            int          screenW      = 20;
            int          speed        = 5; //should end up at 0
            LaserFactory laserFactory = new LaserFactory(laserSpeed, laserWidth, laserHeight, numRows * numColumns);
            BombFactory  bombFactory  = new BombFactory(bombSpeed, bombWidth, bombHeight, numBombSlots);

            // Create game objects
            ScoreAndLife scoreAndLife = new ScoreAndLife(lives, laserFactory, bombFactory);
            //arrange

            Player player = new Player(screenW, 100, speed, playerW, 2, laserFactory, bombFactory, scoreAndLife, timerIntervalPlayerRespawn);

            //act
            player.MoveLeft();
            int x = player.BoundingBox.X;


            //assert
            Assert.AreEqual(0, x); //expected, actual
        }
Example #6
0
        public void UpdateProjectiles_TouchPlayer()
        {
            int          bombSpeed    = 5;
            int          bombWidth    = 1;
            int          bombHeight   = 1;
            int          numBombSlots = 5;
            LaserFactory laserFactory = new LaserFactory(laserSpeed, laserWidth, laserHeight, numRows * numColumns);
            BombFactory  bombFactory  = new BombFactory(bombSpeed, bombWidth, bombHeight, numBombSlots);

            // Create game objects
            ScoreAndLife scoreAndLife = new ScoreAndLife(lives, laserFactory, bombFactory);
            Player       player       = new Player(screenWidth, screenHeight, playerSpeed, playerWidth, playerHeight, laserFactory, bombFactory, scoreAndLife, timerIntervalPlayerRespawn);
            //arrange
            BombFactory bomb = new BombFactory(bombSpeed, bombWidth, bombHeight, numBombSlots);

            //int playerW = 10;
            //int screenW = 20;
            //int speed = 5; //should end up at 0

            //act
            int xBomb = bomb.Bombs[0].BoundingBox.X;
            int yBomb = bomb.Bombs[0].BoundingBox.Y;

            bomb.UpdateProjectiles();

            int xBomb1 = bomb.Bombs[0].BoundingBox.X;
            int yBomb1 = bomb.Bombs[0].BoundingBox.Y;

            //assert

            Assert.AreEqual(0, xBomb); //expected, actual
            Assert.AreEqual(0, yBomb);

            Assert.AreEqual(0, xBomb1); //expected, actual
            Assert.AreEqual(0, yBomb1);
        }
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // Create textures
            Texture2D textureAlien      = this.Content.Load <Texture2D>(@"assets/bug");
            Texture2D textureBomb       = this.Content.Load <Texture2D>(@"assets/bomb");
            Texture2D textureBunker     = this.Content.Load <Texture2D>(@"assets/bunker");
            Texture2D textureLaser      = this.Content.Load <Texture2D>(@"assets/laser");
            Texture2D textureMothership = this.Content.Load <Texture2D>(@"assets/mothership");
            Texture2D texturePlayer     = this.Content.Load <Texture2D>(@"assets/player");

            // Initialize variables
            alienHeight      = textureAlien.Height;
            alienWidth       = textureAlien.Width;
            bombHeight       = textureBomb.Height;
            bombWidth        = textureBomb.Width;
            bunkerHeight     = textureBunker.Height;
            bunkerWidth      = textureBunker.Width;
            laserHeight      = textureLaser.Height;
            laserWidth       = textureLaser.Width;
            mothershipHeight = textureMothership.Height;
            mothershipWidth  = textureMothership.Width;
            playerHeight     = texturePlayer.Height;
            playerWidth      = texturePlayer.Width;

            // Create factories
            laserFactory = new LaserFactory(laserSpeed, laserWidth, laserHeight, numRows * numColumns);
            bombFactory  = new BombFactory(bombSpeed, bombWidth, bombHeight, numBombSlots);

            // Create game objects
            scoreAndLife = new ScoreAndLife(lives, laserFactory, bombFactory);
            player       = new Player(screenWidth, screenHeight, playerSpeed, playerWidth, playerHeight, laserFactory, bombFactory, scoreAndLife, timerIntervalPlayerRespawn);
            bunkers      = new Bunkers(numBunkers, screenWidth, screenHeight, bunkerWidth, bunkerHeight, bunkerHealth, playerHeight, spaceBetweenBunkerAndPlayer);
            mothership   = new Mothership(screenWidth, mothershipWidth, mothershipHeight, mothershipSpeed, mothershipPoints, timerIntervalMothership, mothershipSpacerFromTop);
            alienSquad   = new AlienSquad(bunkers, bombFactory, laserFactory, player, mothership, scoreAndLife, numRows, numColumns, screenWidth, player.BoundingBox.Height, alienWidth, alienHeight, alienSpeed, spacer, bombFrequency, alienPointStart, alienPointsPerRow, alienSpacerFromTop, speedIncrease, bombFrequencyIncrement, bombFrequencyMin);

            // Create sprite objects
            laserSprite      = new LaserSprite(this, laserFactory.Laser, textureLaser);
            mothershipSprite = new MothershipSprite(this, mothership, player, textureMothership);
            playerSprite     = new PlayerSprite(this, player, texturePlayer);
            scoreSprite      = new ScoreSprite(this, scoreAndLife);

            for (var x = 0; x < alienSquad.Length; x++)
            {
                Components.Add(new AlienSprite(this, (Alien)alienSquad[x], textureAlien));
            }
            foreach (Bunker bunker in bunkers)
            {
                Components.Add(new BunkerSprite(this, bunker, textureBunker));
            }
            foreach (Projectile bomb in bombFactory.Bombs)
            {
                Components.Add(new BombSprite(this, bomb, textureBomb));
            }

            // Add components
            Components.Add(mothershipSprite);
            Components.Add(playerSprite);
            Components.Add(scoreSprite);
            Components.Add(laserSprite);

            // Register objects
            laserFactory.RegisterAlienSquad(alienSquad);
            laserFactory.RegisterBunkers(bunkers);
            laserFactory.RegisterMothership(mothership);
            bombFactory.RegisterBunkers(bunkers);
            bombFactory.RegisterPlayer(player);

            base.Initialize();
        }
 public ScoreSprite(Game game, ScoreAndLife score)
     : base(game)
 {
     this.game  = game;
     this.score = score;
 }