Esempio n. 1
0
        public async Task TurnAfterCollision_CanTurnAwayfromCollions()
        {
            MovableCharacter character = TestObjectFactory.MovableCharacterUnderTestWithMockDesktopNavigator;

            character.Position.FacingVector        = TestObjectFactory.MockPosition.Vector;
            character.DesktopNavigator.Destination = null;
            Movement movement = TestObjectFactory.MovementUnderTest;

            DesktopNavigator desktopNavigator = character.DesktopNavigator;
            var mocker = Mock.Get <DesktopNavigator>(desktopNavigator);

            // first move the character forward normally
            character.DesktopNavigator.IsInCollision = false;
            await movement.Move(character, Direction.Forward);

            mocker.Verify(x => x.Navigate(character.Position, Direction.Forward, movement.Speed, movement.HasGravity, It.IsAny <List <Position> >()), Times.Once);
            // now set collision and see if character navigates
            mocker.ResetCalls();
            character.DesktopNavigator.IsInCollision = true;
            await movement.Move(character, Direction.Forward);

            mocker.Verify(x => x.Navigate(character.Position, Direction.Forward, movement.Speed, true, It.IsAny <List <Position> >()), Times.Never);
            // now try to turn around and test again
            mocker.ResetCalls();
            await movement.Turn(character, TurnDirection.Right);

            Assert.IsFalse(character.DesktopNavigator.IsInCollision);
        }
Esempio n. 2
0
        public async Task MoveCharacter_NavigatesAhead()
        {
            // arrange
            MovableCharacter character = TestObjectFactory.MovableCharacterUnderTestWithMockDesktopNavigator;

            character.DesktopNavigator.Destination = null;
            character.Position.FacingVector        = TestObjectFactory.MockPosition.Vector;
            Movement movement = TestObjectFactory.MovementUnderTest;
            // act
            await movement.Move(character, Direction.Forward);

            // assert
            DesktopNavigator desktopNavigator = character.DesktopNavigator;
            var mocker = Mock.Get <DesktopNavigator>(desktopNavigator);

            mocker.Verify(x => x.Navigate(character.Position, Direction.Forward, movement.Speed, movement.HasGravity, It.IsAny <List <Position> >()));
        }
Esempio n. 3
0
        public async Task SettingGravityOnMove_ThenNavigatesWithgravity()
        {
            // arrange
            MovableCharacter character = TestObjectFactory.MovableCharacterUnderTestWithMockDesktopNavigator;

            character.Position.FacingVector = TestObjectFactory.MockPosition.Vector;
            Movement movement    = TestObjectFactory.MovementUnderTest;
            Position destination = TestObjectFactory.MockPosition;

            // act
            movement.HasGravity = true;
            await movement.Move(character, Direction.Left, destination, 0f);

            // assert
            DesktopNavigator desktopNavigator = character.DesktopNavigator;
            var mocker = Mock.Get <DesktopNavigator>(desktopNavigator);

            mocker.Verify(x => x.NavigateToDestination(character.Position, destination, Direction.Left, movement.Speed, true, It.IsAny <List <Position> >()));
        }
Esempio n. 4
0
        public async Task MoveCharacterForwardToDestination_TurnsDesktopCharacterToDestinationAndStartsMovingToDestination()
        {
            // arrange
            MovableCharacter character = TestObjectFactory.MovableCharacterUnderTestWithMockDesktopNavigator;

            Movement movement    = TestObjectFactory.MovementUnderTest;
            Position destination = TestObjectFactory.MockPosition;

            // act
            await movement.MoveForwardTo(new List <MovableCharacter> {
                character
            }, destination);

            // assert
            DesktopNavigator desktopNavigator = character.DesktopNavigator;
            var mocker2 = Mock.Get <Position>(character.Position);

            mocker2.Verify(x => x.TurnTowards(destination));

            var mocker = Mock.Get <DesktopNavigator>(desktopNavigator);

            mocker.Verify(x => x.NavigateToDestination(character.Position, destination, Direction.Forward, movement.Speed, movement.HasGravity, It.IsAny <List <Position> >()));
        }
 public MovableCharacterImpl(DesktopCharacterTargeter targeter, DesktopNavigator desktopNavigator, KeyBindCommandGenerator generator, Camera camera,
                             CharacterActionList <Identity> identities, AnimatedCharacterRepository repo) : base(targeter, generator, camera, identities, repo)
 {
     this.DesktopNavigator = desktopNavigator;
 }