Example #1
0
        static FinchCommand[] DisplayGetFinchCommands(int numberOfCommands)
        {
            FinchCommand[] commands = new FinchCommand[numberOfCommands];
            DisplayHeader("Get Finch Commands");


            for (int index = 0; index < numberOfCommands; index++)
            {
                Console.Write($"Command #{index + 1}:");


                if (!Enum.TryParse(Console.ReadLine().ToUpper(), out commands[index]))
                {
                    Console.WriteLine("Please enter a valid command");
                    index = index - 1;
                }
            }

            Console.WriteLine();
            Console.WriteLine("The commands:");
            for (int index = 0; index < numberOfCommands; index++)
            {
                Console.WriteLine($"Command #{index + 1}: {commands[index]}");
            }


            DisplayContinuePrompt();

            return(commands);
        }
Example #2
0
        static void Main(string[] args)
        {
            //
            // Note: initial Finch configuration values taken from a static
            //       config file
            int numberOfCommands = DefaultFinchConfig.NUMBER_OF_COMMNANDS;
            int delayDuration    = DefaultFinchConfig.DELAY_DURATION;
            int motorSpeed       = DefaultFinchConfig.MOTOR_SPEED;
            int ledBrightness    = DefaultFinchConfig.MOTOR_SPEED;

            //
            // TODO - 1) Comment out FinchCommand array
            //
            FinchCommand[] commands = new FinchCommand[numberOfCommands];
            Finch          myFinch  = new Finch();

            DisplayWelcomeScreen();

            InitializeFinch(myFinch);

            DisplayGetFinchCommands(commands, numberOfCommands);

            ProcessFinchCommands(myFinch, commands, motorSpeed, ledBrightness, delayDuration);

            TerminateFinch(myFinch);

            DisplayClosingScreen();
        }
Example #3
0
        static FinchCommand[] DisplayGetFinchCommands(int numberOfCommands)
        {
            FinchCommand[] commands = new FinchCommand[numberOfCommands];

            DisplayHeader("Get Finch Commands");

            for (int index = 0; index < numberOfCommands; index++)
            {
                bool         success;
                FinchCommand commandValue;
                do
                {
                    Console.Write($"Command #{index + 1}:");
                    success = Enum.TryParse(Console.ReadLine().ToUpper(), out commandValue) &&
                              Enum.IsDefined(typeof(FinchCommand), commandValue);
                    if (!success)
                    {
                        Console.WriteLine("Please enter a valid Finch command.");
                    }
                } while (!success);
                commands[index] = commandValue;
            }

            Console.WriteLine();
            Console.WriteLine("The commands:");
            for (int index = 0; index < numberOfCommands; index++)
            {
                Console.WriteLine($"Command #{index + 1}: {commands[index]}");
            }

            DisplayContinuePrompt();

            return(commands);
        }
Example #4
0
        static FinchCommand[] DisplayGetCommands(int numberOfCommands)
        {
            FinchCommand[] commands = new FinchCommand[numberOfCommands];

            DisplayHeader("Enter Finch Commands");

            Console.WriteLine("DONE, MOVEFORWARD, MOVEBACKWARD, STOPMOTORS, DELAY, TURNRIGHT, TURNLEFT, LEDON, LEDOFF");

            for (int i = 0; i < numberOfCommands; i++)
            {
                Console.Write($"Command number {i + 1}:");
                Enum.TryParse(Console.ReadLine().ToUpper(), out commands[i]);
            }

            Console.WriteLine();
            Console.Write("The commands you entered are:");
            for (int i = 0; i < numberOfCommands; i++)
            {
                Console.Write($"{commands[i]} - ");
            }

            DisplayContinuePrompt();

            return(commands);
        }
Example #5
0
        //static void DisplayGetFinchCommands(List<FinchCommand> commands, int numberOfCommands)
        static FinchCommand[] DisplayGetFinchCommands (int numberOfCommands)
        {

            FinchCommand commands = new FinchCommand[numberOfcommands];

            DisplayHeader("Get Finch Commands");

           Console.WriteLine();


               for (int index = 0; index < numberOfCommands; index++)
               {
                   Console.WriteLine($"Commands # {index + 1}: ");
                   Enum.TryParse(Console.ReadLine().ToUpper(), out commands);
               
               }

                Console.WriteLine();
                Console.WriteLine("The Commands: ");
                for (int index = 0; index < numberOfCommands; index++)
                {
                    Console.WriteLine($"Command #{index + 1}: {commands[index]}");
                }

                DisplayContinuePrompt();

                return commands;
        }
        static void DisplayGetFinchCommands(List <FinchCommand> commands)
        {
            FinchCommand command = FinchCommand.NONE;
            string       userResponse;

            DisplayScreenHeader("Finch Robot Commands");

            while (command != FinchCommand.DONE)
            {
                Console.Write("enter command:");
                userResponse = Console.ReadLine().ToUpper();
                Enum.TryParse(userResponse, out command);

                commands.Add(command);
            }
            DisplayContinuePrompt();
        }
Example #7
0
        static FinchCommand[] DisplayRetrieveFinchCommands(FinchCommand[] commands, string[] commandsString)
        {
            DisplayHeader("Retrieve Finch Commands");

            string datapath = "Data\\FinchCommands.txt";

            Console.WriteLine($"The data will be retrieved from {datapath}.");
            DisplayContinuePrompt();

            try
            {
                commandsString = File.ReadAllLines(datapath);
                commands       = new FinchCommand[commandsString.Length];

                //
                // convert
                //
                for (int i = 0; i < commandsString.Length; i++)
                {
                    if (Enum.TryParse(commandsString[i], out commands[i]))
                    {
                        Console.WriteLine($"Command {i+1} Successfully Parsed");
                    }
                    else
                    {
                        Console.WriteLine($"Command {i+1} Parse Was Unsuccessful");
                    }
                }
            }
            catch (DirectoryNotFoundException)
            {
                Console.WriteLine("Directory Not Found");
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("File Not Found");
            }

            DisplayContinuePrompt();

            return(commands);
        }
Example #8
0
        /// <summary>
        /// Prompt user for a FinchCommand and validate the response
        /// </summary>
        /// <returns>FinchCommand</returns>
        private static FinchCommand GetFinchCommandValue()
        {
            FinchCommand userCommand = FinchCommand.DONE;
            string       userResponse;
            bool         userResponseValid = false;

            while (!userResponseValid)
            {
                Console.Write("Command: ");
                userResponse = Console.ReadLine().Trim().ToUpper();

                if (Enum.TryParse <FinchCommand>(userResponse, out userCommand))
                {
                    userResponseValid = true;
                }
                else
                {
                    Console.Clear();
                    Console.WriteLine();
                    Console.WriteLine("It appears that you entered and invalid command.");
                    Console.WriteLine("Please reenter your command.");
                    Console.WriteLine();

                    //
                    // Display all of the enum command options
                    //
                    Console.WriteLine("Command Options: ");
                    Console.Write("| ");
                    foreach (var command in Enum.GetValues(typeof(FinchCommand)))
                    {
                        Console.Write(command + " | ");
                    }
                    Console.WriteLine();
                }
            }

            return(userCommand);
        }
Example #9
0
        static void DisplayGetFinchCommands(List <FinchCommand> commands)
        {
            FinchCommand command = FinchCommand.NONE;
            string       userResponse;
            bool         done = false;

            //
            //Users selection
            //
            DisplayScreenHeader("Finch Robot Commands");
            Console.WriteLine("all of the commands: ");
            Console.WriteLine("Moveforward, Movebackward");
            Console.WriteLine("Stopmotors, Wait");
            Console.WriteLine("Turnright,Turnleft");
            Console.WriteLine("LEDon, LEDoff ");
            Console.WriteLine("When you are all done with your commands just add [Done]");

            //
            //Commands
            //
            do
            {
                Console.Write("Enter Command:");
                userResponse = Console.ReadLine().ToUpper();
                switch (userResponse)
                {
                case "MOVEFORWARD":
                    Enum.TryParse(userResponse, out command);
                    commands.Add(command);
                    break;

                case "MOVEBACKWARD":
                    Enum.TryParse(userResponse, out command);
                    commands.Add(command);
                    break;

                case "STOPMOTORS":
                    Enum.TryParse(userResponse, out command);
                    commands.Add(command);
                    break;

                case "WAIT":
                    Enum.TryParse(userResponse, out command);
                    commands.Add(command);
                    break;

                case "TURNRIGHT":
                    Enum.TryParse(userResponse, out command);
                    commands.Add(command);
                    break;

                case "TURNLEFT":
                    Enum.TryParse(userResponse, out command);
                    commands.Add(command);
                    break;

                case "LEDON":
                    Enum.TryParse(userResponse, out command);
                    commands.Add(command);
                    break;

                case "LEDOFF":
                    Enum.TryParse(userResponse, out command);
                    commands.Add(command);
                    break;

                case "GETLIGHT":
                    Enum.TryParse(userResponse, out command);
                    commands.Add(command);
                    break;

                case "GETTEMP":
                    Enum.TryParse(userResponse, out command);
                    commands.Add(command);
                    break;

                case "DONE":
                    done = true;
                    break;

                default:
                    Console.WriteLine();
                    Console.WriteLine("This is not a valid Command.");
                    DisplayContinuePrompt();
                    Console.WriteLine();
                    break;
                }
            } while (!done);


            DisplayContinuePrompt();
        }