Example #1
0
        public void TestTotalCostForProtocolWorks()
        {
            ProtocolDroid pdroid = new ProtocolDroid("Carbonite", "Protocol", "Bronze", 12);

            pdroid.CalculateTotalCost();

            Assert.AreEqual(450.00m, pdroid.TotalCost);
        }
        static void Main(string[] args)
        {
            // Populate menus
            populateMenus();

            // Initialize the console window
            UserInterface.InitializeConsoleWindow("Droid Creator");

            // Main program loop
            do
            {
                // Print the main menu and get an answer from the user
                int menuChoice = UserInterface.GetMainMenuSelection(MenuSelections, "Droid Making Program");

                // Make a choice depending on the menu selection
                switch (menuChoice)
                {
                    // Add a droid
                    case 1:
                        // General pattern here is 1) draw the menu 2) declare value variables 3) get the values from the menu elements and assign them to the value variables

                        // Variable to hold the new droid
                        Droid assembledDroid = null;

                        #region Droid Variables
                        // Variables to hold values that will be used to create a new droid
                        Droid.DroidMaterial material = Droid.DroidMaterial.AGRINIUM;
                        Droid.DroidColor color = Droid.DroidColor.BLACK;
                        Droid.DroidModel model = Droid.DroidModel.ASTROMECH;

                        int numberOfLanguages = 0;

                        bool hasToolbox = false;
                        bool hasComputerConnection = false;
                        bool hasArm = false;

                        bool hasTrashCompactor = false;
                        bool hasVacuum = false;

                        bool hasFireExtinguisher = false;
                        int numberOfShips = 0;
                        #endregion

                        // Start menu
                        GeneralDroidMenu.Start();

                        #region General Droid Handling
                        // Get handle to UI elements
                        SelectionBox materialBox = (SelectionBox) GeneralDroidMenu.GetElementByTitle("material:");
                        SelectionBox colorBox = (SelectionBox)GeneralDroidMenu.GetElementByTitle("color:");
                        SelectionBox modelBox = (SelectionBox)GeneralDroidMenu.GetElementByTitle("model:");

                        // Extract and assign data from elements
                        Enum.TryParse<Droid.DroidMaterial>(materialBox.SelectedText, out material);
                        Enum.TryParse<Droid.DroidColor>(colorBox.SelectedText, out color);
                        Enum.TryParse<Droid.DroidModel>(modelBox.SelectedText, out model);
                        #endregion

                        #region Protocol and Utility Droid Handling
                        // Decide which menu to show next based on what they entered for "model"
                        switch (model)
                        {
                            case Droid.DroidModel.PROTOCOL:         // For the protocol droid...

                                // Start the menu
                                ProtocolDroidMenu.Start();

                                // Get handle to UI element
                                SelectionBox numLanguagesBox = (SelectionBox)ProtocolDroidMenu.GetElementByTitle("number of languages:");

                                // Extract and assign data from element
                                int.TryParse(numLanguagesBox.SelectedText, out numberOfLanguages);

                                break;
                            case Droid.DroidModel.UTILITY:          // For the utility, janitor, and astromech droids...
                            case Droid.DroidModel.JANITOR:
                            case Droid.DroidModel.ASTROMECH:

                                // Start the menu
                                UtilityDroidMenu.Start();

                                // Get handle to UI elements
                                SelectionBox hasToolboxBox = (SelectionBox)UtilityDroidMenu.GetElementByTitle("toolbox:");
                                SelectionBox hasComputerConnectionBox = (SelectionBox)UtilityDroidMenu.GetElementByTitle("computer connection:");
                                SelectionBox hasArmBox = (SelectionBox)UtilityDroidMenu.GetElementByTitle("arm:");

                                // Extract and assign data from elements
                                bool.TryParse(hasToolboxBox.SelectedText, out hasToolbox);
                                bool.TryParse(hasComputerConnectionBox.SelectedText, out hasComputerConnection);
                                bool.TryParse(hasArmBox.SelectedText, out hasArm);

                                #region Janitor and Astromech Droid Handling

                                // Take care of the janitor and astromech droids
                                switch (model)
                                {
                                    case Droid.DroidModel.JANITOR:          // For the janitor droid...

                                        // Start the menu
                                        JanitorDroidMenu.Start();

                                        // Get handle to UI elements
                                        SelectionBox hasTrashCompactorBox = (SelectionBox)JanitorDroidMenu.GetElementByTitle("trash compactor:");
                                        SelectionBox hasVacuumBox = (SelectionBox)JanitorDroidMenu.GetElementByTitle("vacuum:");

                                        // Extract and assign data from elements
                                        bool.TryParse(hasTrashCompactorBox.SelectedText, out hasTrashCompactor);
                                        bool.TryParse(hasVacuumBox.SelectedText, out hasVacuum);

                                        break;
                                    case Droid.DroidModel.ASTROMECH:        // For the astromech droid...

                                        // Start the menu
                                        AstromechDroidMenu.Start();

                                        // Get handle to UI elements
                                        SelectionBox hasFireExtinguisherBox = (SelectionBox)AstromechDroidMenu.GetElementByTitle("fire extinguisher:");
                                        SelectionBox numberOfShipsBox = (SelectionBox)AstromechDroidMenu.GetElementByTitle("number of ships:");

                                        // Extract and assign data from elements
                                        bool.TryParse(hasFireExtinguisherBox.SelectedText, out hasFireExtinguisher);
                                        int.TryParse(numberOfShipsBox.SelectedText, out numberOfShips);

                                        break;
                                }
                                #endregion

                                break;
                        }
                        #endregion

                        // Based on what the user entered, create a new droid from that data
                        switch (model)
                        {
                            case Droid.DroidModel.PROTOCOL:
                                assembledDroid = new ProtocolDroid(material, model, color, numberOfLanguages);
                                break;
                            case Droid.DroidModel.UTILITY:
                                assembledDroid = new UtilityDroid(material, model, color, hasToolbox, hasComputerConnection, hasArm);
                                break;
                            case Droid.DroidModel.JANITOR:
                                assembledDroid = new JanitorDroid(material, model, color, hasToolbox, hasComputerConnection, hasArm, hasTrashCompactor, hasVacuum);
                                break;
                            case Droid.DroidModel.ASTROMECH:

                                break;
                        }

                        // FINALLY, add the assembled droid to the list
                        DroidCollection.Add(assembledDroid);

                        // Clear screen
                        UserInterface.ClearScreen();

                        // Draw status
                        UserInterface.SetStatus(UserInterface.PressAnyPhrase(assembledDroid.Model + " droid added to droid list!"));

                        // Wait for user to press a key
                        Console.ReadKey(true);

                        break;

                    // List the droids
                    case 2:
                        UserInterface.ListDroids();
                        break;

                    // Exit program
                    case 3:
                        System.Environment.Exit(0);
                        break;
                }

            } while (true);
        }