コード例 #1
0
ファイル: Program.cs プロジェクト: philipadlergard/RCTester
        static bool CheckMove(IRcCar car, Room room)
        {
            if (car.X < 0 || car.X > room.MaxXPos)
            {
                return false;
            }
            if (car.Y < 0 || car.Y > room.MaxYPos)
            {
                return false;
            }

            return true;
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: philipadlergard/RCTester
        static bool CheckMove(IRcCar car, Room room)
        {
            if (car.X < 0 || car.X > room.MaxXPos)
            {
                return(false);
            }
            if (car.Y < 0 || car.Y > room.MaxYPos)
            {
                return(false);
            }

            return(true);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: philipadlergard/RCTester
        static void Main(string[] args)
        {
            string roomSize;
            string startingPos;
            string commands;

            Console.Write("Set roomsize (two integers separated with whitespace, start with height)");
            Console.WriteLine();

            roomSize = Console.ReadLine();

            while (!ValidateRoomSizeInput(roomSize))
            {
                roomSize = Console.ReadLine();
                Console.WriteLine();
            }

            Room room = CreateRoom(roomSize);

            Console.Write("Set startingposition and heading of the car (two integers followed by one letter, separated with whitespaces)");
            Console.WriteLine();

            startingPos = Console.ReadLine();
            Console.WriteLine();

            while (!ValidateStartPosInput(startingPos))
            {
                startingPos = Console.ReadLine();
                Console.WriteLine();
            }

            IRcCar car = CreateCar(startingPos);

            Console.Write("Type commands for the car. Available are F, B, L and R");
            Console.WriteLine();

            commands = Console.ReadLine();
            Console.WriteLine();

            while (!ValidateCommandInput(commands))
            {
                commands = Console.ReadLine();
                Console.WriteLine();
            }

            StartTest(car, room, commands);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: philipadlergard/RCTester
        static void StartTest(IRcCar car, Room room, string commands)
        {
            for (int i = 0; i < commands.Length; i++)
            {
                switch (commands[i])
                {
                case 'F':
                    car.MoveForward();
                    break;

                case 'B':
                    car.MoveBack();
                    break;

                case 'L':
                    car.MoveLeft();
                    break;

                case 'R':
                    car.MoveRight();
                    break;

                default:
                    break;
                }

                bool validMove = CheckMove(car, room);

                if (!validMove)
                {
                    Console.WriteLine("Test failed, car crashed into the wall trying to head {0} {1} meters from the bottom and {2} meters from the left", car.Heading, car.Y, car.X);
                    Console.ReadKey();
                }
            }

            Console.WriteLine("Test was successfull, car stopped {0} meters from the bottom and {1} meters from the left facing {2}", car.Y, car.X, car.Heading);
            Console.ReadKey();
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: philipadlergard/RCTester
        static void StartTest(IRcCar car, Room room, string commands)
        {
            for (int i = 0; i < commands.Length; i++)
            {
                switch (commands[i])
                {
                    case 'F':
                        car.MoveForward();
                        break;
                    case 'B':
                        car.MoveBack();
                        break;
                    case 'L':
                        car.MoveLeft();
                        break;
                    case 'R':
                        car.MoveRight();
                        break;
                    default:
                        break;
                }

                bool validMove = CheckMove(car, room);

                if (!validMove)
                {
                    Console.WriteLine("Test failed, car crashed into the wall trying to head {0} {1} meters from the bottom and {2} meters from the left", car.Heading, car.Y, car.X);
                    Console.ReadKey();
                }
            }

            Console.WriteLine("Test was successfull, car stopped {0} meters from the bottom and {1} meters from the left facing {2}", car.Y, car.X, car.Heading);
            Console.ReadKey();
        }