コード例 #1
0
        public void ParseRobotMoves()
        {
            CommandsParser commandParser = new CommandsParser();
            var            result        = commandParser.ParseRobotMoves("LMLMLMLMM");

            Assert.IsTrue(result.Count > 0);
        }
コード例 #2
0
        public void MoveRobotToPosition()
        {
            CommandsParser commandParser = new CommandsParser();
            Arena          arena;
            bool           result = commandParser.IsValidArenaCommand("5 5", out arena);

            Assert.IsTrue(result);
            Robot robot;

            result = commandParser.IsValidCreateRobotCommand("1 2 N", out robot);
            Assert.IsTrue(result);
            var moves = commandParser.ParseRobotMoves("LMLMLMLMM");

            Assert.IsTrue(moves.Count > 0);

            MovesProvider provider = new MovesProvider();

            provider.MoveRobotToPosition(arena, robot, moves);

            Assert.AreEqual <int>(1, robot.PositionX);

            Assert.AreEqual <int>(3, robot.PositionY);

            Assert.AreEqual <CompasPoints>(CompasPoints.North, robot.Compas);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: svetlanatanasov/Robot-Wars
        static void Main(string[] args)
        {
            CommandsParser commandParser = new CommandsParser();

            Console.WriteLine("Enter coordinates of the Arena");
            string arenaCommands = Console.ReadLine();
            Arena  arena         = null;

            if (!commandParser.IsValidArenaCommand(arenaCommands, out arena))
            {
                Console.WriteLine("Invalid command");
                Console.ReadKey();
                return;
            }

            while (true)
            {
                Console.WriteLine("Enter position for robot");
                string commands = Console.ReadLine();
                Robot  robot    = null;

                if (!commandParser.IsValidCreateRobotCommand(commands, out robot))
                {
                    Console.WriteLine("Invalid command");
                    Console.ReadKey();
                    return;
                }
                if (robot.PositionX > arena.Width || robot.PositionY > arena.Hight)
                {
                    Console.WriteLine("Invalid coordinates");
                    Console.ReadKey();
                    return;
                }

                Console.WriteLine("Enter robot moves");
                commands = Console.ReadLine();
                var moves = commandParser.ParseRobotMoves(commands);

                var movesProvider = new MovesProvider();
                movesProvider.MoveRobotToPosition(arena, robot, moves);

                Console.WriteLine("{0} {1} {2}", robot.PositionX, robot.PositionY, robot.Compas);
            }
        }