示例#1
0
        public int CreateRobot(int arenaHandle)
        {
            Arena arena = Global.Arenas.GetArena(arenaHandle);
            Robot robot = arena.AddRobot(WhoAmI());

            return(robot.Handle);
        }
示例#2
0
        public void AddPlayerFail()
        {
            // Arrange
            var arena = new Arena(new RectangularGrid(new Location(10, 5)));

            // Assert
            Assert.Throws <OutOfArenaException>(
                () => { arena.AddRobot(new Robot(new Location(11, 0), Direction.S)); });
        }
示例#3
0
        public void AddPlayerSuccess()
        {
            // Arrange
            var arena = new Arena(new RectangularGrid(new Location(10, 5)));

            // Act
            arena.AddRobot(new Robot(new Location(2, 2), Direction.S));

            // Assert
            Assert.AreEqual(1, arena.Robots.Count);
        }
示例#4
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);
        }
示例#6
0
        protected void ButtonAddRobot_Click(object sender, EventArgs e)
        {
            Robot robot = arena.AddRobot(Context.User.Identity.Name);

            Response.Redirect(string.Format("Robot.aspx?robot={0}", robot.Handle));
        }