示例#1
0
        public void PlexisChallenge()
        {
            Surface MySurface = new Surface(new Size(5, 5));

            Rover Spirit = new Rover(MySurface, new Point(1, 2), PhysicalObject.Heading.North);
            Spirit.Rotate(PhysicalObject.Rotation.Left);
            Spirit.Move();
            Spirit.Rotate(PhysicalObject.Rotation.Left);
            Spirit.Move();
            Spirit.Rotate(PhysicalObject.Rotation.Left);
            Spirit.Move();
            Spirit.Rotate(PhysicalObject.Rotation.Left);
            Spirit.Move();
            Spirit.Move();
            Assert.AreEqual(new Point(1, 3), MySurface.GetPosition(Spirit));
            Assert.AreEqual(PhysicalObject.Heading.North, Spirit.Direction);

            Rover Opportunity = new Rover(MySurface, new Point(3, 3), PhysicalObject.Heading.East);
            Opportunity.Move();
            Opportunity.Move();
            Opportunity.Rotate(PhysicalObject.Rotation.Right);
            Opportunity.Move();
            Opportunity.Move();
            Opportunity.Rotate(PhysicalObject.Rotation.Right);
            Opportunity.Move();
            Opportunity.Rotate(PhysicalObject.Rotation.Right);
            Opportunity.Rotate(PhysicalObject.Rotation.Right);
            Opportunity.Move();
            Assert.AreEqual(new Point(5, 1), MySurface.GetPosition(Opportunity));
            Assert.AreEqual(PhysicalObject.Heading.East, Opportunity.Direction);
        }
示例#2
0
        static void Main(string[] args)
        {
            HashSet<Rover> Rovers = new HashSet<Rover>();
            String[] Input;

            Console.WriteLine("Please specify the size of the Mars Plateu:");
            Console.WriteLine("The first number is the width, and the second number is the height.");

            Input = Console.ReadLine().Split(' ');
            Surface MySurface = new Surface(new Size(Convert.ToInt32(Input[0]), Convert.ToInt32(Input[1])));

            while (true)
            {
                Console.WriteLine("");
                Console.WriteLine("Please specify the starting position and direction of the rover:");
                Console.WriteLine("The first number is the horizontal coordinate, the second number is the vertical coordinate");
                Console.WriteLine("The third value is a single character representing a Cardinal Point (N, S, E, or W)");
                Console.WriteLine("Please enter a blank line to indicate you have no more rovers to enter.");

                Input = Console.ReadLine().Split(' ');

                try
                {
                    PhysicalObject.Heading Direction = PhysicalObject.Heading.North;
                    switch (Input[2].ToUpper())
                    {
                        case "N":
                            Direction = PhysicalObject.Heading.North;
                            break;
                        case "E":
                            Direction = PhysicalObject.Heading.East;
                            break;
                        case "S":
                            Direction = PhysicalObject.Heading.South;
                            break;
                        case "W":
                            Direction = PhysicalObject.Heading.West;
                            break;
                    }
                    Rover CurrentRover = new Rover(MySurface, new Point(Convert.ToInt32(Input[0]), Convert.ToInt32(Input[1])), Direction);

                    Console.WriteLine("Please provide a string of directions for the rover to follow.  No spaces are requred.");
                    Console.WriteLine("{ L = Turn Left; R = Turn Right; M = Move 1 unit forward }");

                    String UserInput = Console.ReadLine().Replace(" ", "");

                    foreach (Char character in UserInput.ToUpper())
                    {
                        switch (character)
                        {
                            case 'L':
                                CurrentRover.Rotate(PhysicalObject.Rotation.Left);
                                break;
                            case 'R':
                                CurrentRover.Rotate(PhysicalObject.Rotation.Right);
                                break;
                            case 'M':
                                CurrentRover.Move();
                                break;
                        }
                    }

                    Rovers.Add(CurrentRover);
                }
                catch
                {
                    break;
                }
            }

            Console.WriteLine("These are the resulting location(s) for your rover(s):");

            foreach (Rover TestRover in Rovers)
            {
                String Output = "";
                Output += MySurface.GetPosition(TestRover).X;
                Output += " ";
                Output += MySurface.GetPosition(TestRover).Y;
                Output += " ";

                switch (TestRover.Direction)
                {
                    case PhysicalObject.Heading.North:
                        Output += "N";
                        break;
                    case PhysicalObject.Heading.East:
                        Output += "E";
                        break;
                    case PhysicalObject.Heading.South:
                        Output += "S";
                        break;
                    case PhysicalObject.Heading.West:
                        Output += "W";
                        break;
                }

                Console.WriteLine(Output);
            }

            Console.Read();
        }
示例#3
0
 public void RotateTest()
 {
     Surface MySurface = new Surface(new Size(5, 5));
     Rover Rover1 = new Rover(MySurface, new Point(0, 0), PhysicalObject.Heading.North);
     Rover1.Move();
     Assert.AreEqual(new Point(0, 1), MySurface.GetPosition(Rover1));
     Rover1.Rotate(PhysicalObject.Rotation.Right);
     Rover1.Move();
     Assert.AreEqual(new Point(1, 1), MySurface.GetPosition(Rover1));
     Rover1.Rotate(PhysicalObject.Rotation.Right);
     Rover1.Move();
     Assert.AreEqual(new Point(1, 0), MySurface.GetPosition(Rover1));
     Rover1.Rotate(PhysicalObject.Rotation.Right);
     Rover1.Move();
     Assert.AreEqual(new Point(0, 0), MySurface.GetPosition(Rover1));
     Rover1.Rotate(PhysicalObject.Rotation.Right);
     Rover1.Move();
     Assert.AreEqual(new Point(0, 1), MySurface.GetPosition(Rover1));
     Rover1.Rotate(PhysicalObject.Rotation.Right);
     Rover1.Move();
     Assert.AreEqual(new Point(1, 1), MySurface.GetPosition(Rover1));
     Rover1.Rotate(PhysicalObject.Rotation.Left);
     Rover1.Move();
     Assert.AreEqual(new Point(1, 2), MySurface.GetPosition(Rover1));
     Rover1.Rotate(PhysicalObject.Rotation.Left);
     Rover1.Move();
     Assert.AreEqual(new Point(0, 2), MySurface.GetPosition(Rover1));
     Rover1.Rotate(PhysicalObject.Rotation.Left);
     Rover1.Move();
     Assert.AreEqual(new Point(0, 1), MySurface.GetPosition(Rover1));
     Rover1.Rotate(PhysicalObject.Rotation.Left);
     Rover1.Move();
     Assert.AreEqual(new Point(1, 1), MySurface.GetPosition(Rover1));
     Rover1.Rotate(PhysicalObject.Rotation.Left);
     Rover1.Move();
     Assert.AreEqual(new Point(1, 2), MySurface.GetPosition(Rover1));
     Rover1.Rotate(PhysicalObject.Rotation.Left);
     Rover1.Move();
     Assert.AreEqual(new Point(0, 2), MySurface.GetPosition(Rover1));
 }
        static void Main(string[] args)
        {
            HashSet <Rover> Rovers = new HashSet <Rover>();

            String[] Input;

            Console.WriteLine("Please specify the size of the Mars Plateu:");
            Console.WriteLine("The first number is the width, and the second number is the height.");

            Input = Console.ReadLine().Split(' ');
            Surface MySurface = new Surface(new Size(Convert.ToInt32(Input[0]), Convert.ToInt32(Input[1])));

            while (true)
            {
                Console.WriteLine("");
                Console.WriteLine("Please specify the starting position and direction of the rover:");
                Console.WriteLine("The first number is the horizontal coordinate, the second number is the vertical coordinate");
                Console.WriteLine("The third value is a single character representing a Cardinal Point (N, S, E, or W)");
                Console.WriteLine("Please enter a blank line to indicate you have no more rovers to enter.");

                Input = Console.ReadLine().Split(' ');

                try
                {
                    PhysicalObject.Heading Direction = PhysicalObject.Heading.North;
                    switch (Input[2].ToUpper())
                    {
                    case "N":
                        Direction = PhysicalObject.Heading.North;
                        break;

                    case "E":
                        Direction = PhysicalObject.Heading.East;
                        break;

                    case "S":
                        Direction = PhysicalObject.Heading.South;
                        break;

                    case "W":
                        Direction = PhysicalObject.Heading.West;
                        break;
                    }
                    Rover CurrentRover = new Rover(MySurface, new Point(Convert.ToInt32(Input[0]), Convert.ToInt32(Input[1])), Direction);

                    Console.WriteLine("Please provide a string of directions for the rover to follow.  No spaces are requred.");
                    Console.WriteLine("{ L = Turn Left; R = Turn Right; M = Move 1 unit forward }");

                    String UserInput = Console.ReadLine().Replace(" ", "");

                    foreach (Char character in UserInput.ToUpper())
                    {
                        switch (character)
                        {
                        case 'L':
                            CurrentRover.Rotate(PhysicalObject.Rotation.Left);
                            break;

                        case 'R':
                            CurrentRover.Rotate(PhysicalObject.Rotation.Right);
                            break;

                        case 'M':
                            CurrentRover.Move();
                            break;
                        }
                    }

                    Rovers.Add(CurrentRover);
                }
                catch
                {
                    break;
                }
            }

            Console.WriteLine("These are the resulting location(s) for your rover(s):");

            foreach (Rover TestRover in Rovers)
            {
                String Output = "";
                Output += MySurface.GetPosition(TestRover).X;
                Output += " ";
                Output += MySurface.GetPosition(TestRover).Y;
                Output += " ";

                switch (TestRover.Direction)
                {
                case PhysicalObject.Heading.North:
                    Output += "N";
                    break;

                case PhysicalObject.Heading.East:
                    Output += "E";
                    break;

                case PhysicalObject.Heading.South:
                    Output += "S";
                    break;

                case PhysicalObject.Heading.West:
                    Output += "W";
                    break;
                }

                Console.WriteLine(Output);
            }

            Console.Read();
        }