Beispiel #1
0
        public ICoordinate GetRandomShipCoordinate()
        {
            BattleShip ship = GetRandomShip();

            IEnumerable <ICoordinate> coordinates = ship
                                                    .GetLocation()
                                                    .GetCoordinates();

            ICoordinate coordinate = GetRadomItem(new List <ICoordinate>(coordinates));

            return(coordinate);
        }
        private bool IsNewLocationValid(Location location, BattleShip battleship)
        {
            var collisiondetection = new CollisionDetection(TheSea, Ship);

            // no collision
            var isValid = collisiondetection.IsLocationValid(location)

                          // no outside seaboundaries
                          && TheSea.IsValid(location);

            return(isValid);
        }
        public void Launch()
        {
            foreach (Missile missile in Missiles)
            {
                BattleShip targetShip = TheSea.GetShipOn(missile.GetTarget());
                bool       hasTarget  = targetShip != null;

                if (hasTarget)
                {
                    HitShip(targetShip, missile);
                }
            }
        }
Beispiel #4
0
        public void Start()
        {
            foreach (BattleShip battleShip in BattleShips)
            {
                CurrentShip = battleShip;

                HandleCurrentShip();

                this.ViewModel.Recalculate();

                Delay();
            }
        }
Beispiel #5
0
        private IEnumerable <Missile> Shoot(CanonAndRadarCombiList weaponcombi, BattleShip battleship)
        {
            ICollection <Missile> missiles = new List <Missile>();

            foreach (Tuple <IKanon, IRadar> weapons in weaponcombi)
            {
                ICoordinate coordinate = TakeShot(weapons);
                Missile     missile    = new Missile(coordinate, battleship);

                missiles.Add(missile);
            }

            return(missiles);
        }
        private void HitShip(BattleShip targetShip, Missile missile)
        {
            var assestprovider = new BattleshipAssestProvider(targetShip);
            IEnumerable <IGoalkeeper> goalkeepers = assestprovider.GetGoalkeepers();
            IGoalkeeper goalkeeper    = goalkeepers.FirstOrDefault();
            bool        hasGoalkeeper = goalkeeper != null;

            if (hasGoalkeeper && IsMissileCatched(goalkeeper))
            {
                missile.SetEffect(MissileEffect.HitAndCatched);
                return;
            }

            MissileEffect effect = targetShip.AcceptMissile(missile);

            missile.SetEffect(effect);
        }
 public BattleshipAssestProvider(BattleShip battleship)
 {
     this.Battleship = battleship;
 }
 public SailAway(BattleShip ship, Sea sea)
 {
     Ship   = ship;
     TheSea = sea;
 }
Beispiel #9
0
 public void AcceptShip(BattleShip ship)
 {
     // check first
     AllShips.Add(ship);
 }
 public CollisionDetection(Sea sea, BattleShip ship)
 {
     TheSea      = sea;
     OwnLocation = ship.GetLocation();
 }
Beispiel #11
0
        private BattleShip GetRandomShip()
        {
            BattleShip randomship = GetRadomItem(BattleShips);

            return(randomship);
        }
Beispiel #12
0
 public Missile(ICoordinate target, BattleShip owner)
 {
     this.Target = target;
     this.Owner  = owner;
     this.Effect = MissileEffect.Unknown;
 }