using SimsPersonalityGenerator; var isRestartSession = false; void GenerateTraits() { Console.WriteLine("Welcome to the Sim Personality Generator!"); Console.WriteLine("You can prioritize one or more traits to be above 8 by entering them."); Console.Write("Enter traits separated by commas (e.g., Outgoing, Nice), or press Enter to generate a random personality: "); var prioritizedTraitsInput = Console.ReadLine()?.Trim(); var traits = new Dictionary { { "Outgoing", 0 }, { "Nice", 0 }, { "Playful", 0 }, { "Neat", 0 }, { "Active", 0 } }; // Process the prioritized traits var prioritizedTraits = new HashSet(prioritizedTraitsInput.Split(',') .Select(t => t.Trim()).Where(t => !string.IsNullOrEmpty(t) && traits.ContainsKey(t))); if (prioritizedTraits.Count > 0) { Sim.AssignPrioritizedTraits(traits, prioritizedTraits); } else { Sim.AssignRandomTraits(traits); } Sim.DisplayPersonality(traits); RestartSession(); } // TODO: Refactor to fix code duplication for both Session methods // Method to restart the session based on user input void RestartSession() { // Prompt the user to decide if they want to try again Console.WriteLine("Would you like to try again?"); // Read the user input var input = Console.ReadLine(); // Check if the input is null or whitespace if (string.IsNullOrWhiteSpace(input)) { // If the input is invalid or empty, exit the application Environment.Exit(Environment.ExitCode); } else { // Convert the input to lowercase to handle case insensitivity switch (input.ToLower()) { case "y": // If the user enters 'y' // Set the flag to restart the session isRestartSession = true; // Clear the console for a fresh start Console.Clear(); // Call the method to launch a new session LaunchSession(); break; default: // If the user enters anything other than 'y' // Exit the application with the current exit code Environment.Exit(Environment.ExitCode); break; } } } // Method to launch a new session void LaunchSession() { // Check if the session should be restarted if (isRestartSession) { // Reset the restart flag after the session is launched isRestartSession = false; // Generate traits (presumably some form of random data) GenerateTraits(); } // Prompt the user to generate a random personality Console.WriteLine("Would you like to generate a random personality? [y/n]"); // Read the user input var input = Console.ReadLine(); // Check if the input is null or whitespace if (string.IsNullOrWhiteSpace(input)) { // If the input is invalid or empty, exit the application Environment.Exit(Environment.ExitCode); } else { // Convert the input to lowercase to handle case insensitivity switch (input.ToLower()) { case "y": // If the user enters 'y' // Clear the console for a fresh start Console.Clear(); // Generate traits (presumably some form of random data) GenerateTraits(); break; default: // If the user enters anything other than 'y' // Exit the application with the current exit code Environment.Exit(Environment.ExitCode); break; } } } LaunchSession();