Advertisement
vvsvvs

Untitled

Aug 8th, 2022
772
0
127 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | None | 0 0
  1. using SpaceStation.Models.Astronauts.Contracts;
  2. using SpaceStation.Models.Mission.Contracts;
  3. using SpaceStation.Models.Planets.Contracts;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6.  
  7. namespace SpaceStation.Models.Mission
  8. {
  9.     public class Mission : IMission
  10.     {
  11.         public Mission()
  12.         {
  13.  
  14.         }
  15.  
  16.         public void Explore(IPlanet planet, ICollection<IAstronaut> astronauts)
  17.         {
  18.             bool isLoopExit = false;
  19.  
  20.             while (IsPlanetNotEmpty(planet) && !isLoopExit)
  21.             {
  22.                 IAstronaut currentAstronavt = astronauts.Where(x => x.CanBreath).FirstOrDefault();
  23.                 if (currentAstronavt != null)
  24.                 {
  25.                     currentAstronavt.Breath();
  26.                     string item = planet.Items.FirstOrDefault();
  27.                     planet.Items.Remove(item);
  28.                     currentAstronavt.Bag.Items.Add(item);
  29.                 }
  30.                 else
  31.                 {
  32.                     isLoopExit = true;
  33.                 }
  34.             }
  35.             //          Here is how the Explore method works:
  36.             //•   The astronauts start going out in open space one by one.They can't go, if they don't have any oxygen left.
  37.             //•   An astronaut lands on a planet and starts collecting its items one by one.
  38.             //•   He finds an item and he takes a breath.
  39.             //•   He adds the item to his backpack and respectively the item must be removed from the planet.
  40.             //•   Astronauts can't keep collecting items if their oxygen becomes 0.
  41.             //•   If it becomes 0, the next astronaut starts exploring.
  42.         }
  43.  
  44.         private bool IsPlanetNotEmpty(IPlanet planet) => planet.Items.Count > 0;
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement