Beispiel #1
0
        static void GetPartsForUltron(Ultron ultron)
        {
            var command = Console.ReadLine();

            while (command != "Assemble!")
            {
                var part      = command.Split(' ').First();
                var partSepcs = command.Split(' ').Skip(1).ToArray();

                switch (part)
                {
                case "Head":
                    GetHead(ultron, partSepcs);
                    break;

                case "Torso":
                    GetTorso(ultron, partSepcs);
                    break;

                case "Arm":
                    GetArm(ultron, partSepcs);
                    break;

                case "Leg":
                    GetLeg(ultron, partSepcs);
                    break;
                }

                command = Console.ReadLine();
            }
        }
Beispiel #2
0
 static void PrintUltronAsemblyStatus(Ultron ultron, long maxEnergy)
 {
     if (ultron.TotalEnergy > maxEnergy)
     {
         Console.WriteLine("We need more power!");
     }
     else if (ultron.Head == null || ultron.Torso == null ||
              ultron.Arms.Count != 2 || ultron.Legs.Count != 2)
     {
         Console.WriteLine("We need more parts!");
     }
     else
     {
         Console.WriteLine("Jarvis:"); // fake Ultron
         Console.WriteLine(ultron.Head);
         Console.WriteLine(ultron.Torso);
         foreach (var arm in ultron.Arms)
         {
             Console.WriteLine(arm);
         }
         foreach (var leg in ultron.Legs)
         {
             Console.WriteLine(leg);
         }
     }
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            var maxEnergy = long.Parse(Console.ReadLine());

            var ultron = new Ultron();

            GetPartsForUltron(ultron);
            PrintUltronAsemblyStatus(ultron, maxEnergy);
        }
Beispiel #4
0
        static void GetArm(Ultron ultron, string[] partSepcs)
        {
            var newArm = new Arm
            {
                EnergyConsumption = int.Parse(partSepcs[0]),
                ReachDistance     = int.Parse(partSepcs[1]),
                FingersCount      = int.Parse(partSepcs[2])
            };

            ultron.Arms.Add(newArm);
            ultron.Arms = ultron.Arms.OrderBy(ec => ec.EnergyConsumption).ToList();
            if (ultron.Arms.Count > 2)
            {
                ultron.Arms = ultron.Arms.Take(2).ToList();
            }
        }
Beispiel #5
0
        static void GetLeg(Ultron ultron, string[] partSepcs)
        {
            var newLeg = new Leg
            {
                EnergyConsumption = int.Parse(partSepcs[0]),
                Strenght          = int.Parse(partSepcs[1]),
                Speed             = int.Parse(partSepcs[2])
            };

            ultron.Legs.Add(newLeg);
            ultron.Legs = ultron.Legs.OrderBy(ec => ec.EnergyConsumption).ToList();
            if (ultron.Legs.Count > 2)
            {
                ultron.Legs = ultron.Legs.Take(2).ToList();
            }
        }
Beispiel #6
0
        static void GetHead(Ultron ultron, string[] partSepcs)
        {
            var newHead = new Head
            {
                EnergyConsumption = int.Parse(partSepcs[0]),
                IQ       = int.Parse(partSepcs[1]),
                Material = partSepcs[2]
            };

            if (ultron.Head == null)
            {
                ultron.Head = newHead;
            }
            else if (newHead.EnergyConsumption < ultron.Head.EnergyConsumption)
            {
                ultron.Head = newHead;
            }
        }
Beispiel #7
0
        static void GetTorso(Ultron ultron, string[] partSepcs)
        {
            var newTorso = new Torso
            {
                EnergyConsumption = int.Parse(partSepcs[0]),
                CpuSize           = double.Parse(partSepcs[1]),
                Material          = partSepcs[2]
            };

            if (ultron.Torso == null)
            {
                ultron.Torso = newTorso;
            }
            else if (newTorso.EnergyConsumption < ultron.Torso.EnergyConsumption)
            {
                ultron.Torso = newTorso;
            }
        }