Пример #1
0
        public void Ball_TestBounceOnWallHit()
        {
            RectangleF gf = GameManager.gameField;
            SizeF target;

            //Test left wall bounce
            Ball b = new RegularBall(new PointF(gf.Left + 1.0f, gf.Bottom / 2));
            b.moveVector = new SizeF(-1.0f, 1.0f);
            target = new SizeF(b.moveVector.Width * -1, b.moveVector.Height);
            b.Update();
            b.Update();
            b.Update();
            Assert.AreEqual(target, b.moveVector);

            //Test right wall bounce
            b = new RegularBall(new PointF(gf.Right - 1.0f, gf.Bottom / 2));
            b.moveVector = new SizeF(1.0f, 1.0f);
            target = new SizeF(b.moveVector.Width * -1, b.moveVector.Height);
            b.Update();
            b.Update();
            b.Update();
            Assert.AreEqual(target, b.moveVector);

            //Test top wall bounce
            b = new RegularBall(new PointF(gf.Right / 2, gf.Top - 1.0f));
            b.moveVector = new SizeF(1.0f, -1.0f);
            target = new SizeF(b.moveVector.Width, b.moveVector.Height * -1);
            b.Update();
            b.Update();
            b.Update();
            Assert.AreEqual(target, b.moveVector);
        }
Пример #2
0
 public void Ball_TestBounceOnBrickHit()
 {
     PointF origin = new PointF(80, 220);
     Ball b = new RegularBall(origin);
     b.moveVector = new SizeF(1, -1.0f);
     b.Update();
     b.Update();
     Assert.AreEqual(new SizeF(1, 1.0f), b.moveVector);
 }
Пример #3
0
 public void Brick_TestGhost()
 {
     //Similar to Brick_TestCharged()
     Ball b = new RegularBall(PointF.Empty);
     b.moveVector = new SizeF(0, -1.0f);
     Brick br = new GhostBrick(PointF.Empty);
     br.OnHit(ref b);
     Assert.AreEqual(new SizeF(0, -1.0f), b.moveVector);
     Assert.AreEqual(typeof(GhostBall), b.GetType());
 }
Пример #4
0
        public void Brick_TestBonusHit()
        {
            int seed = 131415;
            GameManager.Init(null, 10, 10, new Menu(), seed);

            Ball b = new RegularBall(GameManager.bricks[3, 9].GetPosition());
            b.moveVector = new SizeF(0, -1.0f);
            b.Update();
            b.Update();
            Assert.AreEqual(new SizeF(0, 1.0f), b.moveVector);
            Assert.AreEqual(2, GameManager.score);
        }
Пример #5
0
        public void Brick_TestDestroyOnHit()
        {
            int seed = 131415;
            GameManager.Init(null, 10, 10, new Menu(), seed);

            Ball b = new RegularBall(GameManager.bricks[9,9].GetPosition());
            b.moveVector = new SizeF(0, -1.0f);

            //Move the ball towards the brick to hit it
            b.Update();
            b.Update();

            //Check if it is removed from the game/brick array
            Assert.AreEqual(null, GameManager.bricks[9, 9]);
        }
Пример #6
0
        public void Brick_TestCharge()
        {
            //Create a new Ball object
            Ball b = new RegularBall(PointF.Empty);

            //Set the move vector
            b.moveVector = new SizeF(1, -1.0f);

            //Create a new ChargedBrick object
            Brick br = new ChargedBrick(PointF.Empty);

            //Hit the brick
            br.OnHit(ref b);

            //Ball does not change direction
            Assert.AreEqual(new SizeF(1, -1.0f), b.moveVector);

            //Ball changes type to 'ChargedBall'
            Assert.AreEqual(typeof(ChargedBall), b.GetType());
        }
Пример #7
0
        public void Ball_TestBounceOnPadHit()
        {
            RectangleF playerBox = GameManager.player.boundingBox;

            //Position the ball 1 pixel above the player
            Ball b = new RegularBall(new PointF(GameManager.player.GetPosition().X, GameManager.player.GetPosition().Y - 1));

            //Test slow ball
            b.moveVector = new SizeF(0, 1);
            SizeF expected = this.calculateSpeed(ref b, playerBox);
            b.Update();
            Assert.AreEqual(expected, b.moveVector);

            b = new RegularBall(new PointF(GameManager.player.GetPosition().X, GameManager.player.GetPosition().Y - 1));

            //Test fast ball (maximum speed)
            b.moveVector = new SizeF(0, playerBox.Height);
            expected = calculateSpeed(ref b, playerBox);
            b.Update();
            Assert.AreEqual(expected, b.moveVector);
        }
Пример #8
0
        public void Ball_TestTransitionType()
        {
            Ball b = new RegularBall(new PointF());
            Ball b2 = new ChargedBall(b);

            //Check if the type is not taken over by the new ball.
            Assert.AreNotEqual(typeof(RegularBall), b2.GetType());
        }
Пример #9
0
        public void Ball_TestTransitionProperties()
        {
            Ball b = new RegularBall(new PointF());
            b.moveVector.Width += 10.0f;
            Ball b2 = new ChargedBall(b);

            //Check if the move vector is taken over by the new ball correctly.
            Assert.AreEqual(b.moveVector, b2.moveVector);
        }
Пример #10
0
        public void Ball_TestMovement()
        {
            //Set start position
            PointF origin = new PointF(5.0f, 5.0f);

            //Set move vector
            SizeF move = new SizeF(1.0f, 1.0f);

            //Target after one update.
            PointF target = new PointF(origin.X + move.Width, origin.Y + move.Height);

            //Move the ball 1 'tick'
            Ball b = new RegularBall(origin);
            b.moveVector = move;
            b.Update();

            Assert.AreEqual(target, b.GetPosition());
        }
Пример #11
0
        public void Ball_TestDie()
        {
            Ball b = new RegularBall(new PointF(20, GameManager.gameField.Bottom - 1));
            int start = GameManager.numberOfLives;
            b.moveVector = new SizeF(0, 1.0f);
            b.Update();
            //Test if a life is taken away
            Assert.AreEqual(start - 1, GameManager.numberOfLives);

            b.Update();
            b.Update();
            //check if game has restarted (3 lives again)
            Assert.AreEqual(start, GameManager.numberOfLives);
        }