Example #1
0
        public void CalculateDistanceToTarget()
        {
            if (travel == false)
            {
                int    distanceToMoon = 52638263, distanceToMars = 159134924, distanceToEarth = 369420840;
                double timeToMoon = 71.52, timeToMars = 213.91, timeToEarth = 439.62;

                if (harvestedWorlds[1] == "1")
                {
                    if (harvestedWorlds[2] == "1")
                    {
                        timeToEarth     += timeToMars + timeToMoon;
                        distanceToEarth += distanceToMars + distanceToMoon;
                    }
                    else if (harvestedWorlds[3] == "1")
                    {
                        timeToMars     += timeToEarth + timeToMoon;
                        distanceToMars += distanceToEarth + distanceToMoon;
                    }
                    else
                    {
                        timeToEarth     += timeToMoon;
                        timeToEarth     += timeToMoon;
                        distanceToEarth += distanceToMoon;
                        distanceToMars  += distanceToMoon;
                    }
                }
                else if (harvestedWorlds[2] == "1")
                {
                    if (harvestedWorlds[3] == "1")
                    {
                        timeToMoon     += timeToMars + timeToEarth;
                        distanceToMoon += distanceToMars + distanceToEarth;
                    }
                    else
                    {
                        timeToEarth     += timeToMars;
                        timeToMoon      += timeToMars;
                        distanceToEarth += distanceToMars;
                        distanceToMoon  += distanceToMars;
                    }
                }
                else if (harvestedWorlds[3] == "1")
                {
                    timeToMoon     += timeToEarth;
                    timeToMars     += timeToEarth;
                    distanceToMoon += distanceToEarth;
                    distanceToMars += distanceToEarth;
                }

                Print("");
                PrintWithRepetition($"Calculating distance to {TargetWorld} ");
                Print("Distance: " + (TargetWorld.ToString() == "Moon" ? $"≈ {distanceToMoon} km" :
                                      (TargetWorld.ToString() == "Mars" ? $"≈ {distanceToMars} km" : $"≈ {distanceToEarth} km")));
                Print("");
                Print($"Setting a course for {TargetWorld}.");
                Print("ETA: " + (TargetWorld.ToString() == "Moon" ? $"≈ {timeToMoon} hours" :
                                 (TargetWorld.ToString() == "Mars" ? $"≈ {timeToMars} hours" : $"≈ {timeToEarth} hours")));
                Print("");
                Print($"{ChosenClass} status: Inactive until arrival on {TargetWorld} ");
            }
            else
            {
                Print("");
                Print($"{ChosenClass} is already at the location of the targeted world");
            }
        }
Example #2
0
        public void EvaluateSituation()
        {
            if (status == true)
            {
                Print($"[{ChosenClass}] Status: Active");
                PrintWithRepetition($"[{ChosenClass}] Assessing current situation");
                Print($"[{ChosenClass}] World: {TargetWorld}");
                Print($"[{ChosenClass}] Population: {TargetWorld.Population}");
                Print($"[{ChosenClass}] Health: {ChosenClass.Health}");

                if (TargetWorld.LifeForms)
                {
                    int notExistingTargets = 0;

                    Print($"[{ChosenClass}] Hostile life forms: ");

                    foreach (Target target in TargetWorld.Targets)
                    {
                        Print($"[{ChosenClass}] {target}: {target.Amount}");

                        if (target.Amount == 0)
                        {
                            notExistingTargets++;
                        }
                    }

                    if (notExistingTargets == TargetWorld.Targets.Count)
                    {
                        TargetWorld.LifeForms = false;

                        EvaluateSituation();
                    }
                }
                else
                {
                    int  choice  = 1;
                    bool correct = false;

                    if (TargetWorld.ToString() == "Moon")
                    {
                        harvestedWorlds[1] = "1";
                    }
                    else if (TargetWorld.ToString() == "Mars")
                    {
                        harvestedWorlds[2] = "1";
                    }
                    else
                    {
                        harvestedWorlds[3] = "1";
                    }

                    Print($"[{ChosenClass}] All hostiles have been harvested");
                    Print($"[{ChosenClass}] {TargetWorld}: Harvested");

                    if (harvestedWorlds[1] == "0" || harvestedWorlds[2] == "0" || harvestedWorlds[3] == "0")
                    {
                        Print($"[{ChosenClass}] Proceed to harvest the next world: Yes <Use the arrow keys to switch between 'Yes' and 'No'>");

                        while (correct == false)
                        {
                            switch (Console.ReadKey().Key)
                            {
                            case ConsoleKey.LeftArrow:
                                Console.SetCursorPosition(ChosenClass.ToString().Length + 38, rows);
                                choice = (choice + 1) % 2;
                                if (choice == 0)
                                {
                                    Print("No ");
                                }
                                else
                                {
                                    Print("Yes");
                                }
                                rows--;
                                Console.SetCursorPosition(0, rows + 1);
                                break;

                            case ConsoleKey.RightArrow:
                                Console.SetCursorPosition(ChosenClass.ToString().Length + 38, rows);
                                choice = (choice + 1) % 2;
                                if (choice == 0)
                                {
                                    Print("No ");
                                }
                                else
                                {
                                    Print("Yes");
                                }
                                rows--;
                                Console.SetCursorPosition(0, rows + 1);
                                break;

                            case ConsoleKey.Enter:
                                correct = true;
                                break;

                            default:
                                Console.SetCursorPosition(0, rows + 1);
                                Console.Write(" ");
                                Console.SetCursorPosition(0, rows + 1);
                                break;
                            }
                        }

                        if (choice == 1)
                        {
                            currentTarget = 0;
                            travel        = false;
                            status        = false;
                            boot          = false;

                            ShutDownRobot();
                            rows++;
                            GetTargetWorld();
                            Boot();
                            CalculateDistanceToTarget();
                            Travel();
                            Activate();
                            EvaluateSituation();
                        }
                        else
                        {
                            consoleShutDown = true;

                            ShutDownRobot();
                            Print("Mission: Success");
                            PrintWithRepetition("Console shutting down");
                            Print("FINISHED");
                        }
                    }
                    else
                    {
                        consoleShutDown = true;

                        Print($"[{ChosenClass}] All worlds have been harvested");
                        ShutDownRobot();
                        Print("Mission: Success");
                        PrintWithRepetition("Console shutting down");
                        Print("FINISHED");
                    }
                }
            }
            else
            {
                Print("Robot is deactivated.");
            }
        }