コード例 #1
0
    private static void Main(string[] args)
    {
        TrashInitialData();
        while (true)
        {
            var data        = ReadArray();
            var currentTurn = new MarsLander(data);

            currentTurn.Move();
        }
    }
コード例 #2
0
    static void Main(string[] args)
    {
        string[] inputs;
        int      surfaceN = int.Parse(Console.ReadLine());    // the number of points used to draw the surface of Mars.

        SurfacePoint[] allPoints = new SurfacePoint[surfaceN];
        for (int i = 0; i < surfaceN; i++)
        {
            inputs = Console.ReadLine().Split(' ');
            int landX = int.Parse(inputs[0]);             // X coordinate of a surface point. (0 to 6999)
            int landY = int.Parse(inputs[1]);             // Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars.
            allPoints[i] = new SurfacePoint(landX, landY);
        }

        List <SurfacePoint> allPairsOfStraightPoints = new List <SurfacePoint>();

        for (int cur = 0; cur < (allPoints.Length - 1); cur++)
        {
            if (allPoints[cur].CheckThisSurface(allPoints[cur + 1]))
            {
                allPairsOfStraightPoints.Add(allPoints[cur]);
                allPairsOfStraightPoints.Add(allPoints[cur + 1]);
            }
        }

        MarsLander mLander = new MarsLander();
        bool       closestLandingSurfaceChecked = false;

        // game loop
        while (true)
        {
            inputs = Console.ReadLine().Split(' ');
            int X      = int.Parse(inputs[0]);
            int Y      = int.Parse(inputs[1]);
            int hSpeed = int.Parse(inputs[2]);           // the horizontal speed (in m/s), can be negative.
            int vSpeed = int.Parse(inputs[3]);           // the vertical speed (in m/s), can be negative.
            int fuel   = int.Parse(inputs[4]);           // the quantity of remaining fuel in liters.
            int rotate = int.Parse(inputs[5]);           // the rotation angle in degrees (-90 to 90).
            int power  = int.Parse(inputs[6]);           // the thrust power (0 to 4).

            mLander.MarsLanderNewData(X, Y, hSpeed, vSpeed, rotate, power);

            // Write an action using Console.WriteLine()
            // To debug: Console.Error.WriteLine("Debug messages...");
            if (!closestLandingSurfaceChecked)
            {
                mLander.CheckClosestSurfaceForLander(allPairsOfStraightPoints);
                closestLandingSurfaceChecked = true;
            }

            Console.WriteLine(mLander.LanderNextMove());
        }
    }
コード例 #3
0
        /// <summary>
        ///  In a nutshell, the program is made up of four major classes:
        ///
        ///  1. This Program class
        ///      It houses main; main's job is to drive the overall logic of the game
        ///
        ///  2. MarsLander
        ///      This stores the current height, speed, and fuel of the lander (properly encapsulated)
        ///      This also has an instance of the 'MarsLanderHistory' object, and the lander is
        ///      responsible for adding to the history whenever it calculates the lander's new speed
        ///
        ///  3. UserInterface
        ///      This handles ALL interactions with the user. 
        ///      NO OTHER CLASS IS ALLOWED TO INTERACT WITH THE USER!!
        ///
        ///  3. MarsLanderHistory
        ///      This manages an array of RoundInfo objects.  It will provide a method to add
        ///      another round to the history of the lander (and will resize the array, if needed)
        ///      It provides a Clone method so that the lander can return a copy of the 
        ///      history (which will prevent other classes from changing it's history)
        ///      And it provides a way to get the number of rounds, and (for each round) the
        ///      height and speed of that round (the UserInterface.PrintHistory method will use these)
        ///          (This class uses the provided, minor RoundInfo class)
        ///
        ///  Substantial amounts of this program have been commented out, so that the program will compile
        /// </summary>
        static void Main(string[] args)
        {
            UserInterface ui = new UserInterface();
            MarsLander lander = new MarsLander();

            const int MAX_SPEED = 10; // 10 m/s
                // const means that we can't change the value after this line

            ui.PrintGreeting();

            while (lander.GetCurrent().GetHeight() > 0)
            {
                ui.PrintLocation(lander);
                ui.PrintLanderInfo(lander);

                int fuelToBurn = ui.GetFuelToBurn(lander);

                lander.CalculateNewSpeed(fuelToBurn);
            }

            ui.PrintLocation(lander);
            ui.PrintLanderInfo(lander);
            ui.PrintEndOfGameResult(lander, MAX_SPEED);
        }