public void MovementTest_PlayerMoves_GridIsUpdated()
        {
            _layer.PositionIsValid(Arg.Any <IPosition>()).Returns(true);
            _layer.GetCharacter(Arg.Is <IPosition>(c => c == _currentPosition)).Returns(_character);
            _layer.GetCharacter(Arg.Is <IPosition>(c => c == _targetPosition)).Returns((ICharacter)null);
            _layer.GetTile(Arg.Any <IPosition>()).Walkable.Returns(true);

            _currentPosition = Substitute.For <IPosition>();
            _currentPosition.X.Returns(3);
            _currentPosition.Y.Returns(3);

            _targetPosition = Substitute.For <IPosition>();
            _targetPosition.X.Returns(4);
            _targetPosition.Y.Returns(3);

            _character.Position.X.Returns(3);
            _character.Position.Y.Returns(3);

            _uut.MoveCharacter(_currentPosition, _targetPosition, _layer);


            Received.InOrder(() =>
            {
                _layer.RemoveCharacter(Arg.Is <ICharacter>(_character));
                _character.Position = _targetPosition;
                _layer.AddCharacter(Arg.Is <ICharacter>(_character));
            });
        }
Beispiel #2
0
 //Moves a character in the layer from oldPosition to newPosition
 //If move is invalid return false
 //If successful returns true
 public bool MoveCharacter(IPosition currentPosition, IPosition newPosition, ILayer layer)
 {
     if (checkIfValidMove(currentPosition, newPosition, layer))
     {
         ICharacter characterToMove = layer.GetCharacter(currentPosition);
         layer.RemoveCharacter(characterToMove);
         characterToMove.Position = newPosition;
         layer.AddCharacter(characterToMove);
         return(true);
     }
     return(false);
 }
        public void interact(IGameState gameState)
        {
            ILayer currentLayer  = gameState.Map.GetCurrentLayer();
            ILayer layerToAccend = gameState.Map.getLayerAboveOrNull();

            if (layerToAccend != null)
            {
                IPosition enteringPostion = layerToAccend.getExitingPositionOrNull();
                if (enteringPostion != null)
                {
                    ICharacter player = gameState.Player;
                    currentLayer.RemoveCharacter(player);
                    player.Position = enteringPostion;
                    layerToAccend.AddCharacter(player);
                    gameState.Map.setCurrentLayerToLayerAbove();
                }
            }
        }
Beispiel #4
0
        public void interact(IGameState gameState)
        {
            ILayer currentLayer  = gameState.Map.GetCurrentLayer();
            ILayer layerToDecent = gameState.Map.getLayerBelowOrNull();

            if (layerToDecent != null)
            {
                IPosition enteringPostion = layerToDecent.getEnteringPositionOrNull();
                if (enteringPostion != null)
                {
                    ICharacter player = gameState.Player;
                    currentLayer.RemoveCharacter(player);
                    player.Position = enteringPostion;
                    layerToDecent.AddCharacter(player);
                    gameState.Map.setCurrentLayerToLayerBelow();
                }
            }
        }