コード例 #1
0
        public void MoveShip(IKapitein captain)
        {
            Location from = Ship.GetLocation();

            Location to = GetNewLocation(from, captain);

            if (IsNewLocationValid(to, Ship))
            {
                Ship.SetLocation(to);
            }
        }
コード例 #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));
        }
コード例 #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);
            }
        }