Example #1
0
        public void AddClampAnglesTest()
        {
            Paddle paddle = new LongPaddle(0, PaddleDataFactory.GetPaddleData(PaddleType.Long));

            paddle.AddClampAngles(0, 10);
            Assert.IsTrue(paddle.MinAngle > paddle.MaxAngle);
        }
Example #2
0
        public void OnPosSyncTest()
        {
            Paddle paddle = new NormalPaddle(0, PaddleDataFactory.GetPaddleData(PaddleType.Normal));
            float  a      = paddle.AngularPosition;

            paddle.OnPosSync(0);
            Assert.IsTrue(paddle.AngularPosition == a);
        }
Example #3
0
        public void AddLifeTest()
        {
            Paddle paddle = new NormalPaddle(0, PaddleDataFactory.GetPaddleData(PaddleType.Normal));

            paddle.SetLife(0);
            paddle.AddLife(1);
            Assert.IsTrue(paddle.Life == 1);
        }
Example #4
0
        public void MoveTest()
        {
            Paddle paddle = new NormalPaddle(0, PaddleDataFactory.GetPaddleData(PaddleType.Normal));
            float  a      = paddle.AngularPosition;

            paddle.AddClampAngles(0, 100);
            paddle.Move(1);
            Assert.IsFalse(paddle.AngularPosition == a);
        }
Example #5
0
        public void IsAliveTest()
        {
            Paddle paddle = new NormalPaddle(0, PaddleDataFactory.GetPaddleData(PaddleType.Normal));

            paddle.SetLife(0);
            Paddle paddle1 = new NormalPaddle(0, PaddleDataFactory.GetPaddleData(PaddleType.Normal));

            paddle1.SetLife(1);
            Assert.IsTrue(paddle.IsAlive() == false && paddle1.IsAlive() == true);
        }
Example #6
0
        public void TransferPowerUpTest()
        {
            PoweredUpData data = new PoweredUpData();

            data.ChangePaddleSpeed = true;
            data.GivePlayerLife    = true;
            data.UndoPlayerMove    = true;
            Paddle paddle = new ShortPaddle(0, PaddleDataFactory.GetPaddleData(PaddleType.Short));

            Assert.ThrowsException <System.TypeInitializationException>(() => { paddle.TransferPowerUp(data); });
        }
        public void ReboundPositionTest()
        {
            PassableObstacleStrategy strategy = new PassableObstacleStrategy();
            Vector2 vector = new Vector2(10, 10);
            Ball    b      = Ball.CreateBall(0, BallType.Normal, vector, 10, vector, 10);
            Paddle  p      = new NormalPaddle(10, PaddleDataFactory.GetPaddleData(PaddleType.Normal));

            Obstacles.Obstacle obstacle = new Obstacles.Obstacle(10, 10, 10, 5, 5);
            Vector2            result   = strategy.ReboundPosition(b, vector, p, obstacle);

            Assert.AreEqual(vector, result);
        }
        public void ReboundDirectionTest()
        {
            PaddleMovingRight strategy = new PaddleMovingRight();
            Vector2           vector   = new Vector2(10, 10);
            Ball   b = Ball.CreateBall(0, BallType.Normal, vector, 10, vector, 10);
            Paddle p = new NormalPaddle(10, PaddleDataFactory.GetPaddleData(PaddleType.Normal));

            Obstacles.Obstacle obstacle = new Obstacles.Obstacle(10, 10, 10, 5, 5);
            Vector2            result   = strategy.ReboundDirection(b, vector, p, obstacle);

            Assert.IsFalse(vector == result);
        }
 public void ReboundDirectionTest1()
 {
     Assert.ThrowsException <NullReferenceException>(() =>
     {
         NonPassablePowerupStrategy strategy = new NonPassablePowerupStrategy();
         Vector2 vector = new Vector2(10, 10);
         Ball b         = Ball.CreateBall(0, BallType.Normal, vector, 10, vector, 10);
         Obstacles.Obstacle obstacle = new Obstacles.Obstacle(10, 10, 10, 5, 5);
         Paddle p       = new NormalPaddle(10, PaddleDataFactory.GetPaddleData(PaddleType.Normal));
         Vector2 result = strategy.ReboundDirection(b, vector, p, obstacle);
     });
 }
Example #10
0
        public void MoveTest1()
        {
            Paddle paddle = new NormalPaddle(0, PaddleDataFactory.GetPaddleData(PaddleType.Normal));
            float  a      = paddle.AngularPosition;

            paddle.AddClampAngles(0, 100);
            paddle.TransferPowerUp(new PoweredUpData()
            {
                ChangePaddleSpeed = true
            });
            paddle.Move(1);
            Assert.IsFalse(paddle.AngularPosition == a);
        }
Example #11
0
        public void ReboundPositionTest()
        {
            NonPassableObstacleStrategy strategy = new NonPassableObstacleStrategy();
            Paddle  paddle     = new NormalPaddle(10, PaddleDataFactory.GetPaddleData(PaddleType.Normal));
            Vector2 vector     = new Vector2(10, 10);
            Vector2 normalised = new Vector2(1, 0);
            Ball    b          = Ball.CreateBall(0, BallType.Deadly, vector, 10, vector, 10);

            NonPassableArenaObjectFactory factory = new NonPassableArenaObjectFactory();
            ObstacleBuilder objBuilder            = new ObstacleBuilder().AddDuration(10).AddHeigth(10).AddPosX(5).AddWidth(10).AddPosY(5);
            Obstacle        obstacle = factory.CreateObstacle(objBuilder);

            Vector2 result = strategy.ReboundPosition(b, normalised, paddle, obstacle);

            Assert.IsFalse(vector == result);
        }
Example #12
0
        private static void DoWithoutFlyweight(int n)
        {
            Stopwatch sw = new Stopwatch();
            long      before, after;

            sw.Reset();
            before = GC.GetTotalMemory(false);
            sw.Start();
            for (int i = 0; i < n; i++)
            {
                var type = (PaddleType)(i % 4);

                switch (type)
                {
                case PaddleType.Normal:
                    new NormalPaddle(0, PaddleDataFactory.GetPaddleData(type));
                    break;

                case PaddleType.Long:
                    new LongPaddle(0, PaddleDataFactory.GetPaddleData(type));
                    break;

                case PaddleType.Short:
                    new ShortPaddle(0, PaddleDataFactory.GetPaddleData(type));
                    break;

                default:
                    break;
                }
            }
            sw.Stop();
            after = GC.GetTotalMemory(false);
            long usedWithout = after - before;
            long msWithout   = sw.ElapsedMilliseconds;

            Debug.WriteLine($"{n}: Without Flyweight: {msWithout} milliseconds. {usedWithout} bytes");
        }
 public void Initialize()
 {
     GameManager.StartLocalGame();
     ArenaFacade.Instance.UpdateDimensions(new Vector2(451, 451), new Vector2(225.5, 225.5), new Vector2(0, 0), 200.5f);
     ArenaFacade.Instance.PlayerPaddles.Add(0, new NormalPaddle(0, PaddleDataFactory.GetPaddleData(PaddleType.Normal)));
 }
Example #14
0
        public void GetCenterAngleTest()
        {
            Paddle paddle = new NormalPaddle(0, PaddleDataFactory.GetPaddleData(PaddleType.Normal));

            Assert.IsTrue(SharedUtilities.DegToRad(paddle.AngularPosition + paddle.AngularSize / 2f) == paddle.GetCenterAngle());
        }
Example #15
0
        public void PaddleTest()
        {
            Paddle paddle = new LongPaddle(0, PaddleDataFactory.GetPaddleData(PaddleType.Long));

            Assert.IsTrue(paddle.AngularSize == PaddleDataFactory.GetPaddleData(PaddleType.Long).Size&& paddle.Thickness == PaddleDataFactory.GetPaddleData(PaddleType.Long).Thickness);
        }