Holds State specific for one Frame.
示例#1
0
        public void UpdateTest()
        {
            for (int i = 1; i < n; i++)
            {
                mockPlayers.Clear();
                players.Clear();

                for (int j = 0; j < i; j++)
                {
                    mockPlayers.Add(new Mock<Player>());
                    players.Add(mockPlayers[j].Object);
                }

                // create target
                GameModel target = new GameModel(mockFactory.Object, mockPhysics.Object, players, mockWorld.Object);
                FrameState frameState = new FrameState();

                // set up mock functionalities
                mockPhysics.Setup(m => m.Update(frameState.GameTime));
                for (int j = 0; j < i; j++)
                {
                    mockPlayers[j].Setup(m => m.Update(frameState));
                }

                // execute Update(frameState)
                target.Update(frameState);

                // verify functionality of the Update function
                mockPhysics.Verify(m => m.Update(frameState.GameTime), Times.Exactly(1));
                for (int j = 0; j < i; j++)
                {
                    mockPlayers[j].Verify(m => m.Update(frameState), Times.Exactly(1));
                }
            }
        }
示例#2
0
        public void UpdateAccelerationBackward1Test()
        {
            this.target = new HumanPlayer(playerId, null, Color.Blue, mockInputConfigurationRetriever.Object);
            this.target.Spaceship = this.spaceship;

            Keys[] keys = { Keys.Down };
            GameTime gameTime = new GameTime(new TimeSpan(0, 0, 10, 3, 0), new TimeSpan(0, 0, 0, 0, 100));
            FrameState frameState = new FrameState(gameTime, new KeyboardState(keys));

            spaceship.Rotation = 0;
            spaceship.Velocity = new Vector2(0, 0);

            target.Update(frameState);

            Assert.AreEqual(new Vector2(0f, 10f), spaceship.Velocity);

            /*
            this.target = new HumanPlayer(playerId, null, Color.Blue, mockInputConfigurationRetriever.Object);
            this.target.Spaceship = this.spaceship;
            spaceship.Rotation = 0;
            spaceship.Velocity = new Vector2(0, 0);

            Keys[] keys = { Keys.Up };
            GameTime gameTime = new GameTime(new TimeSpan(0, 0, 10, 3, 0), new TimeSpan(0, 0, 0, 0, 1));
            FrameState frameState = new FrameState(gameTime, new KeyboardState(keys));
            float speed;
            Vector2 velocity;

            for (int i = 0; i < 20; i++)
            {
                speed = (float)gameTime.ElapsedGameTime.TotalMilliseconds * -0.1f;
                velocity = spaceship.Velocity;
                velocity.X += (float)Math.Sin(this.spaceship.Rotation) * speed;
                velocity.Y -= (float)Math.Cos(this.spaceship.Rotation) * speed;

                target.Update(frameState);

               // bool xInRange = spaceship.Velocity.X > (velocity.X - 0.5) && spaceship.Velocity.X < (velocity.X + 0.5);
                //bool yInRange = spaceship.Velocity.Y > (velocity.Y - 0.5) && spaceship.Velocity.Y < (velocity.Y + 0.5);
                Assert.IsTrue(Vector2.Distance(spaceship.Velocity, velocity) < 0.5);

                // construct a new random TimeSpan for the next test
                gameTime = new GameTime(new TimeSpan(0, 0, 10, 3, 0), new TimeSpan(0, 0, 0, 0, i * (69 + i)));
            }
             */
        }
示例#3
0
        public void UpdateRotateRightTest()
        {
            /*this.target = new HumanPlayer(playerId, null, Color.Blue, mockInputConfigurationRetriever.Object);
            this.target.Spaceship = this.spaceship;

            Keys[] keys = { Keys.Right };
            GameTime gameTime = new GameTime(new TimeSpan(0, 0, 10, 3, 0), new TimeSpan(0, 0, 0, 0, 200));
            FrameState frameState = new FrameState(gameTime, new KeyboardState(keys));

            spaceship.Rotation = 0;

            target.Update(frameState);

            Assert.AreEqual(0.6f, spaceship.Rotation);*/

            this.target = new HumanPlayer(playerId, null, Color.Blue, mockInputConfigurationRetriever.Object);
            this.target.Spaceship = this.spaceship;
            spaceship.Rotation = 0;

            Keys[] keys = { Keys.Right };
            GameTime gameTime = new GameTime(new TimeSpan(0, 0, 10, 3, 0), new TimeSpan(0, 0, 0, 0, 1));
            FrameState frameState = new FrameState(gameTime, new KeyboardState(keys));
            float speed;
            float rotation;

            for (int i = 0; i < 20; i++)
            {
                speed = ((float)frameState.GameTime.ElapsedGameTime.TotalMilliseconds) * 0.003f;
                rotation = spaceship.Rotation + (speed * 1f);

                target.Update(frameState);

                Assert.AreEqual(rotation, spaceship.Rotation);

                // construct a new random TimeSpan for the next test
                gameTime = new GameTime(new TimeSpan(0, 0, 10, 3, 0), new TimeSpan(0, 0, 0, 0, i * (74 + i)));
            }
        }
示例#4
0
        public void UpdatePrevWeaponTest()
        {
            this.target = new HumanPlayer(playerId, mockPlayerHandler.Object, Color.Blue, mockInputConfigurationRetriever.Object);
            this.target.Spaceship = this.spaceship;

            Weapon currentWeapon = weapons[0];
            spaceship.CurrentWeapon = weapons[0];

            for (int i = -1; i >= -10; i--)
            {
                currentWeapon = weapons[Math.Abs(i % weapons.Length)];

                Keys[] keys = { Keys.O };
                FrameState frameState = new FrameState(null, new KeyboardState(keys));
                target.Update(frameState);

                frameState = new FrameState(null, new KeyboardState());
                target.Update(frameState);

                Assert.AreEqual(currentWeapon, spaceship.CurrentWeapon);
            }
        }
示例#5
0
        public void UpdateFireTest()
        {
            mockPlayerHandler.Setup(b => b.OnFire(this.spaceship));

            this.target = new HumanPlayer(playerId, mockPlayerHandler.Object, Color.Blue, mockInputConfigurationRetriever.Object);
            this.target.Spaceship = this.spaceship;

            Keys[] keys = { Keys.Space };
            FrameState frameState = new FrameState(null, new KeyboardState(keys));
            target.Update(frameState);

            frameState = new FrameState(null, new KeyboardState());
            target.Update(frameState);

            mockPlayerHandler.Verify(b => b.OnFire(spaceship), Times.Exactly(1));
        }
示例#6
0
        public void UpdateAccelerationForward2Test()
        {
            this.target = new HumanPlayer(playerId, null, Color.Blue, mockInputConfigurationRetriever.Object);
            this.target.Spaceship = this.spaceship;

            Keys[] keys = { Keys.Up };
            GameTime gameTime = new GameTime(new TimeSpan(0, 0, 10, 3, 0), new TimeSpan(0, 0, 0, 0, 100));
            FrameState frameState = new FrameState(gameTime, new KeyboardState(keys));

            spaceship.Rotation = (float)(270.0 * Math.PI / 180.0);
            spaceship.Velocity = new Vector2(0, 0);

            target.Update(frameState);

            bool correctX = (spaceship.Velocity.X < -9.99) && (spaceship.Velocity.X > -10.001);
            bool correctY = (spaceship.Velocity.Y > -0.001) && (spaceship.Velocity.Y < 0.001);
            Assert.AreEqual(true, correctX);
            Assert.AreEqual(true, correctY);
        }