Exemplo n.º 1
0
        public void MoveShip(IKapitein captain)
        {
            Location from = Ship.GetLocation();

            Location to = GetNewLocation(from, captain);

            if (IsNewLocationValid(to, Ship))
            {
                Ship.SetLocation(to);
            }
        }
Exemplo n.º 2
0
        private Location GetNewLocation(Location from, IKapitein captain)
        {
            var direction = captain.GetDirection();

            if (ShouldTurn(direction, from))
            {
                return(GetNewLocationByTurning(direction, from));
            }

            return(GetNewLocationByMoving(direction, from));
        }
Exemplo n.º 3
0
        public void Navigate()
        {
            var       assestprovider = new BattleshipAssestProvider(Ship);
            IKapitein captain        = assestprovider
                                       .GetCaptains()
                                       .FirstOrDefault();
            bool hasCaptain = captain != null;

            if (hasCaptain && captain.ShouldMove())
            {
                MoveShip(captain);
            }
        }