コード例 #1
0
        static void Main(string[] args)
        {
            List <Rocket> simulatedRockets = new List <Rocket>(); //lista med raketer användaren har lagt till

            FalconHeavy falconHeavySpaceX = new FalconHeavy();
            Starship    starshipSpaceX    = new Starship();

            bool isRunning = true;

            while (isRunning)
            {
                Console.Clear();

                Console.WriteLine("[1] Add rockets");
                Console.WriteLine("[2] List rockets");
                Console.WriteLine("[3] Run simulation");
                Console.WriteLine("[4] Exit");

                ConsoleKeyInfo keyPressed = Console.ReadKey(true);

                Console.Clear();

                switch (keyPressed.Key)
                {
                case ConsoleKey.D1:     //add rockets
                    //listar raketer som finns, som användaren kan välja mellan, och de läggs i i en "simulator" lista
                    Console.WriteLine("[1] Falcon Heavy, SpaceX");
                    Console.WriteLine("[2] Starship, SpaceX");

                    switch (keyPressed.Key)
                    {
                    case ConsoleKey.D1:         //add Falcon Heavy

                        foreach (var therocket in simulatedRockets)
                        {
                            if (therocket.Name == falconHeavySpaceX.Name)
                            {
                                Console.WriteLine("Rocket already added");
                                Thread.Sleep(2000);
                            }
                            else
                            {
                                simulatedRockets.Add(falconHeavySpaceX);
                                Console.WriteLine("Rocked added");

                                Thread.Sleep(2000);
                            }
                        }
                        break;

                    case ConsoleKey.D2:         //add Starship

                        foreach (var therocket in simulatedRockets)
                        {
                            if (therocket.Name == starshipSpaceX.Name)
                            {
                                Console.WriteLine("Rocket already added");
                                Thread.Sleep(2000);
                            }
                            else
                            {
                                simulatedRockets.Add(starshipSpaceX);
                                Console.WriteLine("Rocked added");

                                Thread.Sleep(2000);
                            }
                        }
                        break;
                    }

                    break;

                case ConsoleKey.D2:     //list rockets
                                        //listar raketerna som användaren har valt
                    Console.WriteLine("Simulated rockets");
                    Console.WriteLine("___________________________________________________________");

                    foreach (var listRockets in simulatedRockets)
                    {
                        if (listRockets == null)
                        {
                            continue;
                        }
                        Console.WriteLine(Rocket.name);
                    }

                    break;

                case ConsoleKey.D3:     //run simulation

                    Console.Write("Engine burn period (sec): ");

                    Console.Write("Rocket".PadRight(30, ' '));
                    Console.Write("Velocity (km/s)".PadRight(20, ' '));
                    Console.Write("Fuel left (tons)");

                    foreach ()
                    {
                        ...

                        string rocketName = rocket.ToString();
                    }
                    string velocity       = string.Format("{0:0.00}", Rocket.VelocityInKilometersPerSecond);
                    uint   fuelLeftInTons = Rocket.fuelAmountInKilograms / 1000;

                    Console.Write(rocketName.PadRight(30, ' '));
                    Console.Write(velocity.PadRight(20, ' '));
                    Console.Write(fuelLeftInTons);


                    break;
コード例 #2
0
ファイル: Program.cs プロジェクト: Na-R-84/Rocket
        static void Main(string[] args)
        {
            bool isRunning = true;
            int  i         = 0;

            while (isRunning)
            {
                Clear();
                Console.ForegroundColor
                    = ConsoleColor.Magenta;
                WriteLine(" -- Menu -- ");

                WriteLine("1. Add rocket");
                WriteLine("2. List rocket");
                WriteLine("3. Run simulation");
                WriteLine("4. Run Simulation with graph");
                WriteLine("5. Exit");

                ConsoleKeyInfo pressedKey = ReadKey();

                switch (pressedKey.Key)
                {
                case ConsoleKey.D1:
                    Clear();
                    WriteLine("--Add your Rocket--");
                    WriteLine();
                    WriteLine("[1] Starship, SpaceX\n[2] Falcon Heavy, SpaceX");

                    ConsoleKeyInfo rocketChoice = ReadKey();

                    switch (rocketChoice.Key)
                    {
                    case ConsoleKey.D1:
                        rocketList[i] = new Starship("Falcon 9, SpaceX", 549, 1600);

                        break;

                    case ConsoleKey.D2:
                        rocketList[i] = new FalconHeavy("Falcon Heavy, SpaceX", 1420, 3000);

                        break;
                    }
                    i++;

                    break;

                case ConsoleKey.D2:
                    Clear();

                    int counter = 1;
                    WriteLine("Simulated Rockets");
                    WriteLine("----------------------------------------------------------------------");
                    foreach (Rocket eachRocketShip in rocketList)
                    {
                        if (rocketList[counter - 1] == null)
                        {
                            continue;
                        }
                        WriteLine($"{counter++}. {eachRocketShip.RocketName}");
                    }

                    WriteLine("\n\nPress any key to continue...");
                    ReadLine();

                    break;

                case ConsoleKey.D3:
                    Clear();

                    WriteLine("Engine burn period (sec):");
                    double engineBurn = double.Parse(ReadLine());

                    Clear();
                    WriteLine("Engine burn period (sec):");
                    WriteLine("\n Rocket\t\t\t\t\t Velocity (km/s)\t\t\t Fuel left (tons)");
                    WriteLine("--------------------------------------------------------------------------------------");


                    foreach (var rocket in rocketList)
                    {
                        if (rocket == null)
                        {
                            continue;
                        }

                        WriteLine($"{rocket.RocketName}\t\t\t{Math.Round(rocket.EngineOn(engineBurn), 2)}\t\t\t\t{Math.Round(rocket.FuelLeft(rocket.AmountOfFuel, engineBurn), 1)} ");
                    }

                    ReadLine();
                    break;

                case ConsoleKey.D4:

                    foreach (var rocket in rocketList)
                    {
                        if (rocket == null)
                        {
                            continue;
                        }

                        WriteLine("Engine burn period (sec):");
                        double engineBurn1 = double.Parse(ReadLine());

                        rocket.Graph(rocket.EngineOn(engineBurn1), engineBurn1);
                    }
                    ReadKey();

                    break;

                case ConsoleKey.D5:

                    isRunning = false;
                    break;
                }
            }
        }