コード例 #1
0
ファイル: Rover.cs プロジェクト: HatoonAlmoajel/RoverMovement
        /*this flag is used to prompt the user to enter Upper right coordinates AGAIN for Rover 2 ,in case
         * rover 1 entry was invalid*/

        static void Main(string[] args)
        {
            Console.Write("Enter Graph Upper Right Coordinate:");
            string input0 = Console.ReadLine(); // Get string from user*/

            //this loop is prompting the user to enter two rover informaions

            for (int roverCount = 1; roverCount < 3; roverCount++)
            {
                if (flag)
                {
                    Console.Write("Enter Graph Upper Right Coordinate:");
                    input0 = Console.ReadLine(); // Get string from user*/
                }
                Console.Write("Rover  " + roverCount + "  Starting Position:");
                string input1 = Console.ReadLine(); // Get string from user
                Console.Write("Rover  " + roverCount + "  Movement Plan:");
                string input2 = Console.ReadLine(); // Get string from user


                //process inputs
                RoverMovement obj = new RoverMovement();
                string[]      UpperRightCoordinates = input0.Split(' ');
                string[]      StartingPositionArray = input1.Split(' ');
                char[]        MovementPlan          = input2.ToCharArray();


                /*initial validation
                 * check empty entries or out of accepted range ( StartingPositionArray should be of size 4 and
                 * starts with a space)*/


                if (input0 != string.Empty && input1 != string.Empty && input2 != string.Empty && input1[0] == ' ' && StartingPositionArray.Length == 4 && UpperRightCoordinates.Length == 3)
                {
                    // call two differant methods to validate StartingPositionArray and MovementPlan.
                    if (obj.ValidateStartingPosition(StartingPositionArray, UpperRightCoordinates) && obj.ValidateMovementPlan(MovementPlan))
                    {
                        obj.MoveRover(StartingPositionArray, MovementPlan, 1, UpperRightCoordinates);
                    }
                    else
                    {
                        Console.WriteLine("wrong input format");
                    }
                }
                else
                {
                    Console.WriteLine("wrong or Empty input ");
                }


                Console.ReadKey();
            }
        }
コード例 #2
0
        private void RoverMovementEvent(RoverMovement movementData)
        {
            Debug.WriteLine(movementData.Movement.ToString());

            if (movementData.Movement == RoverMovementType.Autopilot)
            {
                // Enters autopiloting mode.
                autoPiloting = true;
            }
            else
            {
                // Otherwise, if necessary stops the autopiloting.
                autoPiloting = false;
                led?.TurnGreen();

                if (movements.TryGetValue(movementData.Movement, out Action movement))
                {
                    movement?.Invoke();
                }
            }
        }