Esempio n. 1
0
        public string ExplorePlanet(string planetName)
        {
            if (!this.astrRepo.Models.Any(x => x.Oxygen > 60))
            {
                throw new InvalidOperationException(string.Format(ExceptionMessages.InvalidAstronautCount));
            }

            var planetToExplore = planetRepo.FindByName(planetName);

            if (planetToExplore is null)
            {
                throw new InvalidOperationException(ExceptionMessages.InvalidPlanetName);
            }

            newMission.Explore(planetToExplore, (ICollection <IAstronaut>)astrRepo.Models);

            var deadAstr = astrRepo.Models.Where(x => x.Oxygen <= 0);

            if (!planetToExplore.Items.Any())
            {
                this.planetRepo.Remove(planetToExplore);
                this.planetExplored++;
            }

            return(string.Format(OutputMessages.PlanetExplored, planetName, deadAstr.Count()));
        }
Esempio n. 2
0
        public string ExplorePlanet(string planetName)
        {
            List <IAstronaut> suitableAstronauts = this.astronautRepository.Models.Where(a => a.Oxygen > 60).ToList();

            if (suitableAstronauts.Count == 0)
            {
                throw new InvalidOperationException(ExceptionMessages.InvalidAstronautCount);
            }

            IPlanet planet = this.planetRepository.FindByName(planetName);

            mission.Explore(planet, suitableAstronauts);
            this.exploredPlanetsCount++;

            int deadAstronauts = suitableAstronauts.Count(a => !a.CanBreath);

            return(string.Format(OutputMessages.PlanetExplored, planetName, deadAstronauts));
        }
Esempio n. 3
0
        public string ExplorePlanet(string planetName)
        {
            List <IAstronaut> astronautsWithOxygenAboveSixty = this.astronautRepository.Models.Where(a => a.Oxygen > 60).ToList();

            IPlanet planet = planetRepository.Models.FirstOrDefault(p => p.Name == planetName);


            if (astronautsWithOxygenAboveSixty.Count == 0)
            {
                throw new InvalidOperationException("You need at least one astronaut to explore the planet!");
            }

            exploredPlanetsCount++;

            mission.Explore(planet, astronautsWithOxygenAboveSixty);

            int deadAstronauts = astronautsWithOxygenAboveSixty.Count(a => !a.CanBreath);

            return($"Planet: {planetName} was explored! Exploration finished with {deadAstronauts} dead astronauts!");
        }
Esempio n. 4
0
        public string ExplorePlanet(string planetName)
        {
            IPlanet planet = planetRepository.FindByName(planetName);

            var suitableAstronauts = astronautRepository.Models.Where(a => a.Oxygen > 60).ToList();

            if (suitableAstronauts.Count == 0)
            {
                throw new InvalidOperationException(ExceptionMessages.InvalidAstronautCount);
            }

            int initialCountOfSuitableAstronauts = suitableAstronauts.Count;

            mission.Explore(planet, suitableAstronauts);
            exploredPlanetsCount++;

            int deadAstronauts = initialCountOfSuitableAstronauts - suitableAstronauts.Count;

            return(string.Format(OutputMessages.PlanetExplored, planetName, deadAstronauts));
        }