コード例 #1
0
        static void Main(string[] args)
        {
            // New instance of the User Interface and Droid Collection classes
            UserInterface   ui = new UserInterface();
            DroidCollection dc = new DroidCollection();

            Protocol pro = new Protocol();

            //Get some input from the user
            int choice = ui.GetUserInput();

            // While the choice is not 3, continue.
            while (choice != 3)
            {
                // Check if input is 1
                if (choice == 1)
                {
                    dc.PrintArray();
                }

                // Check if input is 2
                if (choice == 2)
                {
                    ui.PrintDroidOptions();
                    string input = Console.ReadLine();

                    // While the input is not valid re-get the input
                    while (input != "1" &&
                           input != "2" &&
                           input != "3" &&
                           input != "4")
                    {
                        //Print Error message
                        ui.PrintErrorMessage();

                        //Re-print the options
                        ui.PrintDroidOptions();

                        //Get the input from the console again.
                        input = Console.ReadLine();
                    }
                    // Switch statement to add new droids to the list.
                    switch (input)
                    {
                    // Adds a protocol droid
                    case "1":
                        string[] newPDroidInformation = ui.GetNewProtocolDroid();
                        dc.AddNewProtocolDroid(newPDroidInformation[0],
                                               newPDroidInformation[1],
                                               int.Parse(newPDroidInformation[2]));
                        // Possible location for this?
                        //pro.CalculateTotalCost();
                        break;

                    // Adds a utility droid
                    case "2":
                        string[] newUDroidInformation = ui.GetNewUtilityDroid();
                        dc.AddNewUtilityDroid(newUDroidInformation[0],
                                              newUDroidInformation[1],
                                              newUDroidInformation[2] == "True",
                                              newUDroidInformation[3] == "True",
                                              newUDroidInformation[4] == "True");
                        break;

                    // Adds a janitor droid
                    case "3":
                        string[] newJDroidInformation = ui.GetNewJanitorDroid();
                        dc.AddNewJanitorDroid(newJDroidInformation[0],
                                              newJDroidInformation[1],
                                              newJDroidInformation[2] == "True",
                                              newJDroidInformation[3] == "True",
                                              newJDroidInformation[4] == "True",
                                              newJDroidInformation[5] == "True",
                                              newJDroidInformation[6] == "True");
                        break;

                    // Adds an astromech droid
                    case "4":
                        string[] newADroidInformation = ui.GetNewAstromechDroid();
                        dc.AddNewAstromechDroid(newADroidInformation[0],
                                                newADroidInformation[1],
                                                newADroidInformation[2] == "True",
                                                newADroidInformation[3] == "True",
                                                newADroidInformation[4] == "True",
                                                newADroidInformation[5] == "True",
                                                int.Parse(newADroidInformation[6]));
                        break;
                    }
                }
                // Prompt the user for input
                choice = ui.GetUserInput();
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: gabsot22/droid-factory
        static void Main(string[] args)
        {
            // Boolean to see if it should print the heading for new Droid
            bool validation = false;

            // Set a constant for the size of the droidCollection
            const int droidCollectionSize = 100;

            // Make a new instance of the User Interface class
            UserInterface ui = new UserInterface();

            //Let's make an array to hold a bunch of instances of the Droid class
            Droid[] droids = new Droid[100];

            // Create an instance of the DroidCollection class
            DroidCollection droidCollection = new DroidCollection(droidCollectionSize);

            // array to hold pre-loaded droids
            droids[0] = new ProtocolDroid("C3PO", "Protocol", "Gold", "Gold", 5); //droids[0] = new ProtocolDroid("C3PO", "Protocol", "Gold", "Gold", 35.00m, 45.00m);
            droids[1] = new UtilityDroid("BD1", "Utility", "Amethyst", "Red", true, true, true);
            droids[2] = new AstromechDroid("R2D2", "Astromech", "Iron", "Blue", true, true, true, true, 1);
            droids[3] = new JanitorDroid("A1Z4", "Janitor", "Iron", "Black", true, true, true, true, true);


            // Display the Welcome Message to the user
            ui.DisplayWelcomeGreeting();

            // Display the Menu and get the response. Store the response in the choice integer
            // This is the 'primer' run of displaying and getting.
            int choice = ui.DisplayMenuAndGetResponse();

            // While the choice selected is not, continue to do work
            while (choice != 3)
            {
                switch (choice)
                {
                // Add A New Droid To The List
                case 1:
                    // User Interface gets the droid type
                    string type = ui.GetDroidTypeInformation();

                    // Tests if type is protocol, utility, janitor, or astromech
                    if (type == "Protocol" || type == "protocol")
                    {
                        // Calls the UI for new Droid info and sets it to an array string
                        string[] newDroidInformation = ui.GetNewProtocolDroidInformation();
                        // Adds the new droid to the droidCollection class
                        droidCollection.AddNewProtocolDroid(newDroidInformation[0],
                                                            newDroidInformation[1],
                                                            newDroidInformation[2],
                                                            newDroidInformation[3],
                                                            int.Parse(newDroidInformation[4]));

                        // Display add droid succession
                        ui.DisplayAddDroidItemSuccess();
                        // Boolean for option 2
                        validation = true;
                    }
                    if (type == "Utility" || type == "utility")
                    {
                        // Calls the UI for new Droid info and sets it to an array string
                        string[] newDroidInformation = ui.GetNewUtilityDroidInformation();

                        // Adds the new droid to the droidCollection class
                        droidCollection.AddNewUtilityDroid(newDroidInformation[0],
                                                           newDroidInformation[1],
                                                           newDroidInformation[2],
                                                           newDroidInformation[3],
                                                           bool.Parse(newDroidInformation[4]),
                                                           bool.Parse(newDroidInformation[5]),
                                                           bool.Parse(newDroidInformation[6]));
                        // Display add droid succession
                        ui.DisplayAddDroidItemSuccess();
                        // Boolean for option 2
                        validation = true;
                    }
                    if (type == "Janitor" || type == "janitor")
                    {
                        // Calls the UI for new Droid info and sets it to an array string
                        string[] newDroidInformation = ui.GetNewJanitorDroidInformation();

                        // Adds the new droid to the droidCollection class
                        droidCollection.AddNewJanitorDroid(newDroidInformation[0],
                                                           newDroidInformation[1],
                                                           newDroidInformation[2],
                                                           newDroidInformation[3],
                                                           bool.Parse(newDroidInformation[4]),
                                                           bool.Parse(newDroidInformation[5]),
                                                           bool.Parse(newDroidInformation[6]),
                                                           bool.Parse(newDroidInformation[7]),
                                                           bool.Parse(newDroidInformation[8]));
                        // Display add droid succession
                        ui.DisplayAddDroidItemSuccess();
                        // Boolean for option 2
                        validation = true;
                    }
                    if (type == "Astromech" || type == "astromech")
                    {
                        // Calls the UI for new Droid info and sets it to an array string
                        string[] newDroidInformation = ui.GetNewAstromechDroidInformation();

                        // Adds the new droid to the droidCollection class
                        droidCollection.AddNewAstromechDroid(newDroidInformation[0],
                                                             newDroidInformation[1],
                                                             newDroidInformation[2],
                                                             newDroidInformation[3],
                                                             bool.Parse(newDroidInformation[4]),
                                                             bool.Parse(newDroidInformation[5]),
                                                             bool.Parse(newDroidInformation[6]),
                                                             bool.Parse(newDroidInformation[7]),
                                                             int.Parse(newDroidInformation[8]));
                        // Display add droid succession
                        ui.DisplayAddDroidItemSuccess();
                        // Boolean for option 2
                        validation = true;
                    }
                    break;

                // Print Droid List
                case 2:
                    // Tests to see if user already added a Droid
                    if (validation == true)
                    {
                        // Output New Droid heading
                        ui.NewDroidsOutputHeading();

                        // Output Heading
                        ui.DisplayDroidHeader();

                        // Output New Droids
                        ui.Output(droidCollection.ToString());
                    }
                    else
                    {
                        // Display error message
                        ui.DisplayErrorNoNewDroids();
                    }

                    // Output Pre-Loaded Droid heading
                    ui.PreLoadedDroidsOutputHeading();

                    // Output Heading again for pre-loaded Droids
                    ui.DisplayDroidHeader();

                    // Declare a return string
                    string outputString = "";

                    // Loop through all of the droids
                    foreach (Droid droid in droids)
                    {
                        // If the current beverage is not null, concat it to the return string
                        if (droid != null)
                        {
                            //Concat to the outputString
                            outputString += droid.ToString() +
                                            Environment.NewLine;
                        }
                    }
                    // Output preloaded Droids
                    ui.Output(outputString);
                    outputString = "";
                    break;
                }
                // Get the new choice of what to do from the user
                choice = ui.DisplayMenuAndGetResponse();
            }
        }