Exemple #1
0
        private static readonly int _numberOfPlayer = 2; // This could be configurable

        static void Main(string[] args)
        {
            Console.WriteLine("Please enter arena Top Right Corner Coordinate");

            var arenaTR = Console.ReadLine().Split(' ');

            var arena = new Arena(new RectangularGrid(new Location(Convert.ToInt32(arenaTR[0]), Convert.ToInt32(arenaTR[1]))));

            for (int i = 0; i < _numberOfPlayer; i++)
            {
                Console.WriteLine($"Please enter Robot{i + 1} location and direction");

                var robot1 = Console.ReadLine().Split(' ');

                arena.AddRobot(new Robot(new Location(Convert.ToInt32(robot1[0]), Convert.ToInt32(robot1[1])), GetDirection(robot1[2])));

                Console.WriteLine("Please provide operations, Valid operations are L, M, R");

                var operations = Console.ReadLine().ToCharArray();

                foreach (var action in operations)
                {
                    if (action == 'L')
                    {
                        arena.ChangeDirection(RobotWars.Core.Action.L);
                    }

                    if (action == 'R')
                    {
                        arena.ChangeDirection(RobotWars.Core.Action.R);
                    }

                    if (action == 'M')
                    {
                        arena.MoveRobot();
                    }
                }
            }

            Console.WriteLine($" Robot1: {arena.Robots[0].Location} {arena.Robots[0].Direction}");
            Console.WriteLine($" Robot2: {arena.Robots[1].Location} {arena.Robots[1].Direction}");

            Console.ReadLine();
        }
        public void Robot1()
        {
            // Arrange
            var arena = new Arena(new RectangularGrid(new Location(5, 5)));

            arena.AddRobot(new Robot(new Location(1, 2), Direction.N));

            // Act
            arena.ChangeDirection(Action.L);
            arena.MoveRobot();
            arena.ChangeDirection(Action.L);
            arena.MoveRobot();
            arena.ChangeDirection(Action.L);
            arena.MoveRobot();
            arena.ChangeDirection(Action.L);
            arena.MoveRobot();
            arena.MoveRobot();

            // Assert
            Assert.AreEqual(1, arena.Robots.Last().Location.X);
            Assert.AreEqual(3, arena.Robots.Last().Location.Y);
            Assert.AreEqual(Direction.N, arena.Robots.Last().Direction);
        }