Exemple #1
0
        public void AddLeg(Leg legInput)
        {
            if (Legs == null)
            {
                Legs = new List <Leg>();
            }

            if (Legs.Count < 2)
            {
                Legs.Add(legInput);
            }
            else
            {
                for (int i = 0; i < this.Arms.Count; i++)
                {
                    if (Legs[i].Energy > legInput.Energy)
                    {
                        Legs.RemoveAt(i);
                        Legs.Add(legInput);
                    }
                }
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            long maxEnergy = long.Parse(Console.ReadLine());

            Robot robot = new Robot();

            robot.Energy = maxEnergy;

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

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

                switch (tokens[0])
                {
                case "Head":
                    Head newHead = new Head
                                   (
                        int.Parse(tokens[1]),
                        int.Parse(tokens[2]),
                        tokens[3]
                                   );
                    robot.AddHead(newHead);
                    break;

                case "Torso":
                    Torso newTorso = new Torso
                                     (
                        int.Parse(tokens[1]),
                        double.Parse(tokens[2]),
                        tokens[3]
                                     );
                    robot.AddTorso(newTorso);
                    break;

                case "Arm":
                    Arm newArm = new Arm
                                 (
                        int.Parse(tokens[1]),
                        int.Parse(tokens[2]),
                        int.Parse(tokens[3])
                                 );
                    robot.AddArm(newArm);
                    break;

                case "Leg":
                    Leg newLeg = new Leg
                                 (
                        int.Parse(tokens[1]),
                        int.Parse(tokens[2]),
                        int.Parse(tokens[3])
                                 );
                    robot.AddLeg(newLeg);
                    break;
                }
            }

            Console.WriteLine(robot.ToString());
        }