Ejemplo n.º 1
0
        public void Execute(Chappie robot)
        {
            robot.TurnRight(90);
            Console.WriteLine($"Heading: {robot.Heading}");
            var driveAheadDistance = robot.BattleFieldWidth;

            if (robot.IsDrivingDown())
            {
                driveAheadDistance = (robot.Status.Y - (robot.EnemyCoordinates.Any() ? robot.EnemyCoordinates.Min(p => p.Y) : 0) + 100);
            }
            else if (robot.IsDrivingLeft())
            {
                driveAheadDistance = (robot.Status.X - (robot.EnemyCoordinates.Any() ? robot.EnemyCoordinates.Min(p => p.X) : 0) + 100);
            }
            else if (robot.IsDrivingUp())
            {
                driveAheadDistance = ((robot.EnemyCoordinates.Any() ? robot.EnemyCoordinates.Max(p => p.Y) : robot.BattleFieldHeight) - robot.Status.Y) + 100;
            }
            else if (robot.IsDrivingRight())
            {
                driveAheadDistance = ((robot.EnemyCoordinates.Any() ? robot.EnemyCoordinates.Max(p => p.X) : 0) - robot.Status.X) + 100;
            }

            Console.WriteLine($"Robot.Status.Y: {robot.Status.Y} Robot max Y: {(robot.EnemyCoordinates.Any() ? robot.EnemyCoordinates.Max(p => p.Y) : robot.BattleFieldHeight)}");
            Console.WriteLine($"Driving ahead: {driveAheadDistance}");

            robot.Ahead(driveAheadDistance);
        }
Ejemplo n.º 2
0
        public void Execute(Chappie robot)
        {
            robot.TurnRight(90);
            Console.WriteLine($"Heading: {robot.Heading}");

            var driveAheadDistance = 5000;

            if (robot.IsDrivingDown() || robot.IsDrivingUp())
            {
                driveAheadDistance = Convert.ToInt32(Math.Round(robot.BattleFieldHeight, 0));
            }
            else if (robot.IsDrivingLeft() || robot.IsDrivingRight())
            {
                driveAheadDistance = Convert.ToInt32(Math.Round(robot.BattleFieldWidth, 0));
            }

            Console.WriteLine($"Driving ahead: {driveAheadDistance}");
            robot.Ahead(driveAheadDistance);
        }