Exemplo n.º 1
0
        public void TestWest()
        {
            RobotInstance rob = new RobotInstance("WEST", 1, 3);

            Assert.AreEqual("1,3,WEST", rob.ToString(), "Object created has wrong attributes.");
            rob.Move();
            Assert.AreEqual("0,3,WEST", rob.ToString(), "Movement from not working");
            rob.Move();
        }
Exemplo n.º 2
0
        public void TestNorth()
        {
            RobotInstance rob = new RobotInstance("NORTH", 4, 3);

            Assert.AreEqual("4,3,NORTH", rob.ToString(), "Object created has wrong attributes.");
            rob.Move();
            Assert.AreEqual("4,4,NORTH", rob.ToString(), "Movement from not working");
            rob.Move();
        }
Exemplo n.º 3
0
        public void TestSouth()
        {
            RobotInstance rob = new RobotInstance("SOUTH", 2, 1);

            Assert.AreEqual("2,1,SOUTH", rob.ToString(), "Object created has wrong attributes.");
            rob.Move();
            Assert.AreEqual("2,0,SOUTH", rob.ToString(), "Movement from not working");
            rob.Move();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            RobotInstance toy = null;

            while (true)
            {
                string[] line = Console.ReadLine().Split();
                if (toy == null)
                {
                    if (line[0].CompareTo("PLACE") == 0 && line.Length == 2)
                    {
                        string[] vals = line[1].Split(",");
                        if (vals.Length == 3)
                        {
                            string dir = vals[2];
                            try
                            {
                                int x = Convert.ToInt32(vals[0]);
                                int y = Convert.ToInt32(vals[1]);
                                toy = new RobotInstance(dir, x, y);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    // else is not required as invalid arguments have to be ignored
                }
                else
                {
                    try
                    {
                        switch (line[0])
                        {
                        case "LEFT":
                            toy.Rotate(line[0]);
                            break;

                        case "RIGHT":
                            toy.Rotate(line[0]);
                            break;

                        case "MOVE":
                            toy.Move();
                            break;

                        case "REPORT":
                            Console.WriteLine(toy.ToString());
                            break;
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }