示例#1
0
 public void applyTorso(Torso torso)
 {
     if (Torso == null || Torso.Consumption > torso.Consumption)
     {
         Torso = torso;
     }
 }
 public Robot()
 {
     RobotHead  = new Head();
     RobotTorso = new Torso();
     RobotArms  = new List <Arm>();
     RobotLegs  = new List <Leg>();
 }
示例#3
0
 public void AddTorso(Torso torso)
 {
     if (this.Torso == null)
     {
         this.Torso = torso;
     }
     else if (this.Torso.EnergyConsumption > torso.EnergyConsumption)
     {
         this.Torso = torso;
     }
 }
示例#4
0
        static void Main()
        {
            long   maxEnergy = long.Parse(Console.ReadLine());
            Jarvis robot     = new Jarvis(maxEnergy);

            while (true)
            {
                string[] input = Console.ReadLine().Split();

                if (input[0] == "Assemble!")
                {
                    break;
                }

                switch (input[0])
                {
                case "Head":
                {
                    var part = new Head(int.Parse(input[1]), int.Parse(input[2]), input[3]);
                    robot.applyHead(part);
                    break;
                }

                case "Torso":
                {
                    var part = new Torso(int.Parse(input[1]), double.Parse(input[2]), input[3]);
                    robot.applyTorso(part);
                    break;
                }

                case "Arm":
                {
                    var part = new Arm(int.Parse(input[1]), int.Parse(input[2]), int.Parse(input[3]));
                    robot.applyArm(part);
                    break;
                }

                case "Leg":
                {
                    var part = new Leg(int.Parse(input[1]), int.Parse(input[2]), int.Parse(input[3]));
                    robot.applyLeg(part);
                    break;
                }
                }
            }

            Console.WriteLine(robot);
        }
示例#5
0
        public override string ToString()
        {
            if (Head == null || Torso == null || Arms.Count < 2 || Legs.Count < 2)
            {
                return("We need more parts!");
            }

            var totalEnergy = 0L;

            totalEnergy += Head.EnergyConsumption;
            totalEnergy += Torso.EnergyConsumption;
            totalEnergy += Arms.Sum(a => a.EnergyConsumption);
            totalEnergy += Legs.Sum(l => l.EnergyConsumption);

            if (totalEnergy > MaxEnergyConsumption)
            {
                return("We need more power!");
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("Jarvis:\r\n");
            sb.Append(Head.ToString());
            sb.Append(Torso.ToString());

            foreach (var arm in Arms.OrderBy(a => a.EnergyConsumption))
            {
                sb.Append(arm.ToString());
            }

            foreach (var leg in Legs.OrderBy(l => l.EnergyConsumption))
            {
                sb.Append(leg.ToString());
            }

            return(sb.ToString());
        }
示例#6
0
        static void Main(string[] args)
        {
            var maxEnergyConsumption = long.Parse(Console.ReadLine());

            var jarvis = new Robot();

            jarvis.MaxEnergyConsumption = maxEnergyConsumption;

            var line = Console.ReadLine();

            while (line != "Assemble!")
            {
                var tokens = line.Split();

                var part = tokens[0];
                var energyConsumption = int.Parse(tokens[1]);

                switch (part)
                {
                case "Head":
                {
                    var iq           = int.Parse(tokens[2]);
                    var skinMaterial = tokens[3];

                    var head = new Head
                    {
                        EnergyConsumption = energyConsumption,
                        Iq           = iq,
                        SkinMaterial = skinMaterial
                    };

                    jarvis.AddHead(head);
                }
                break;

                case "Torso":
                {
                    var processorSize   = double.Parse(tokens[2]);
                    var housingMaterial = tokens[3];

                    var torso = new Torso();
                    torso.EnergyConsumption          = energyConsumption;
                    torso.ProcessorSizeInCentimeters = processorSize;
                    torso.HousingMaterial            = housingMaterial;

                    jarvis.AddTorso(torso);
                }
                break;

                case "Arm":
                {
                    var armReachDistance = int.Parse(tokens[2]);
                    var countOfFingers   = int.Parse(tokens[3]);

                    var arm = new Arm();
                    arm.EnergyConsumption = energyConsumption;
                    arm.ArmReachDistance  = armReachDistance;
                    arm.CountOfFingers    = countOfFingers;

                    jarvis.AddArm(arm);
                }
                break;

                case "Leg":
                {
                    var strength = int.Parse(tokens[2]);
                    var speed    = int.Parse(tokens[3]);

                    var leg = new Leg();
                    leg.EnergyConsumption = energyConsumption;
                    leg.Strength          = strength;
                    leg.Speed             = speed;

                    jarvis.AddLeg(leg);
                }
                break;
                }

                line = Console.ReadLine();
            }

            Console.WriteLine(jarvis);
        }