Commented main code
This commit is contained in:
parent
70e948569d
commit
af9f85b1a4
1 changed files with 40 additions and 17 deletions
51
Program.cs
51
Program.cs
|
@ -4,10 +4,14 @@ var isFinishedSession = false;
|
||||||
|
|
||||||
void GenerateTraits()
|
void GenerateTraits()
|
||||||
{
|
{
|
||||||
|
// Prompt the user to enter traits they want to prioritize.
|
||||||
Console.WriteLine("You can prioritize one or more traits to be above 8 by entering them.");
|
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: ");
|
Console.Write("Enter traits separated by commas (e.g., Outgoing, Nice), or press Enter to generate a random personality: ");
|
||||||
|
|
||||||
|
// Read the user input and trim any leading or trailing whitespace.
|
||||||
var prioritizedTraitsInput = Console.ReadLine()?.Trim();
|
var prioritizedTraitsInput = Console.ReadLine()?.Trim();
|
||||||
|
|
||||||
|
// Initialize a dictionary with predefined traits and their initial values set to 0.
|
||||||
var traits = new Dictionary<string, int>
|
var traits = new Dictionary<string, int>
|
||||||
{
|
{
|
||||||
{ "Outgoing", 0 },
|
{ "Outgoing", 0 },
|
||||||
|
@ -17,59 +21,78 @@ void GenerateTraits()
|
||||||
{ "Active", 0 }
|
{ "Active", 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Process the prioritized traits
|
// Process the prioritized traits input:
|
||||||
|
// 1. Split the input string by commas.
|
||||||
|
// 2. Trim whitespace from each resulting trait.
|
||||||
|
// 3. Filter out any empty or invalid traits (traits that are not in the predefined list).
|
||||||
var prioritizedTraits = new HashSet<string>(prioritizedTraitsInput.Split(',')
|
var prioritizedTraits = new HashSet<string>(prioritizedTraitsInput.Split(',')
|
||||||
.Select(t => t.Trim()).Where(t => !string.IsNullOrEmpty(t) && traits.ContainsKey(t)));
|
.Select(t => t.Trim()).Where(t => !string.IsNullOrEmpty(t) && traits.ContainsKey(t)));
|
||||||
|
|
||||||
|
// Check if there are any prioritized traits provided by the user.
|
||||||
if (prioritizedTraits.Count > 0)
|
if (prioritizedTraits.Count > 0)
|
||||||
{
|
{
|
||||||
|
// Assign values to the prioritized traits.
|
||||||
Sim.AssignPrioritizedTraits(traits, prioritizedTraits);
|
Sim.AssignPrioritizedTraits(traits, prioritizedTraits);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// If no prioritized traits are provided, assign random values to all traits.
|
||||||
Sim.AssignRandomTraits(traits);
|
Sim.AssignRandomTraits(traits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Display the generated personality traits.
|
||||||
Sim.DisplayPersonality(traits);
|
Sim.DisplayPersonality(traits);
|
||||||
|
|
||||||
|
// Mark the session as finished.
|
||||||
isFinishedSession = true;
|
isFinishedSession = true;
|
||||||
|
|
||||||
|
// Re-enter the session manager to allow for another session or to exit.
|
||||||
SessionManager();
|
SessionManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
string? GetUserInput(string message)
|
// Retrieves user input from the console with a given prompt.
|
||||||
|
string? GetUserInput(string prompt)
|
||||||
{
|
{
|
||||||
// Prompt the user to generate a random personality
|
Console.WriteLine(prompt);
|
||||||
Console.WriteLine(message);
|
|
||||||
// Read the user input
|
|
||||||
var input = Console.ReadLine();
|
var input = Console.ReadLine();
|
||||||
|
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method to launch a new session
|
// Manages the personality generator session. It checks if a previous session is finished
|
||||||
|
// and prompts the user to either generate a new personality or exit the application.
|
||||||
void SessionManager()
|
void SessionManager()
|
||||||
{
|
{
|
||||||
|
// Greet the user at the start of a new session only if the previous session wasn't finished.
|
||||||
if (!isFinishedSession)
|
if (!isFinishedSession)
|
||||||
Console.WriteLine("Welcome to the Sim Personality Generator!");
|
Console.WriteLine("Welcome to the Sim Personality Generator!");
|
||||||
|
|
||||||
|
// Define a message to prompt the user about generating a personality.
|
||||||
|
// The message differs slightly if a previous session was already finished.
|
||||||
var message = "Would you like to generate a random personality? [y/n]";
|
var message = "Would you like to generate a random personality? [y/n]";
|
||||||
|
|
||||||
if (isFinishedSession)
|
if (isFinishedSession)
|
||||||
message = "Would you like to generate a new personality? [y/n]";
|
message = "Would you like to generate a new personality? [y/n]";
|
||||||
|
|
||||||
|
// Retrieve the user's input through a prompt specified by 'message'.
|
||||||
var input = GetUserInput(message);
|
var input = GetUserInput(message);
|
||||||
|
|
||||||
// Convert the input to lowercase to handle case insensitivity
|
// Convert the input to lowercase to handle user input in a case-insensitive manner.
|
||||||
switch (input?.ToLower())
|
switch (input?.ToLower())
|
||||||
{
|
{
|
||||||
case "y": // If the user enters 'y'
|
case "y":
|
||||||
if (isFinishedSession) isFinishedSession = false;
|
// Reset the session status if the previous session was finished.
|
||||||
// Clear the console for a fresh start
|
if (isFinishedSession)
|
||||||
|
isFinishedSession = false;
|
||||||
|
|
||||||
|
// Clear the console to provide a clean interface for generating a new personality.
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
// Generate traits (presumably some form of random data)
|
|
||||||
|
// Generate a new set of personality traits
|
||||||
GenerateTraits();
|
GenerateTraits();
|
||||||
break;
|
break;
|
||||||
default: // If the user enters anything other than 'y'
|
|
||||||
// Exit the application with the current exit code
|
default:
|
||||||
|
// If the user enters anything other than 'y', terminate the application gracefully.
|
||||||
Environment.Exit(Environment.ExitCode);
|
Environment.Exit(Environment.ExitCode);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue