Merged Launch/RestartSession into SessionManager
- Renamed isRestartSession to isFinishedSession
This commit is contained in:
parent
5b85ee7a1c
commit
70e948569d
1 changed files with 31 additions and 71 deletions
76
Program.cs
76
Program.cs
|
@ -1,10 +1,9 @@
|
||||||
using SimsPersonalityGenerator;
|
using SimsPersonalityGenerator;
|
||||||
|
|
||||||
var isRestartSession = false;
|
var isFinishedSession = false;
|
||||||
|
|
||||||
void GenerateTraits()
|
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.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: ");
|
||||||
var prioritizedTraitsInput = Console.ReadLine()?.Trim();
|
var prioritizedTraitsInput = Console.ReadLine()?.Trim();
|
||||||
|
@ -32,76 +31,38 @@ void GenerateTraits()
|
||||||
}
|
}
|
||||||
|
|
||||||
Sim.DisplayPersonality(traits);
|
Sim.DisplayPersonality(traits);
|
||||||
RestartSession();
|
isFinishedSession = true;
|
||||||
|
SessionManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Refactor to fix code duplication for both Session methods
|
string? GetUserInput(string message)
|
||||||
// Method to restart the session based on user input
|
|
||||||
void RestartSession()
|
|
||||||
{
|
{
|
||||||
// Prompt the user to decide if they want to try again
|
// Prompt the user to generate a random personality
|
||||||
Console.WriteLine("Would you like to try again?");
|
Console.WriteLine(message);
|
||||||
|
|
||||||
// Read the user input
|
// Read the user input
|
||||||
var input = Console.ReadLine();
|
var input = Console.ReadLine();
|
||||||
|
|
||||||
// Check if the input is null or whitespace
|
return input;
|
||||||
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
|
// Method to launch a new session
|
||||||
void LaunchSession()
|
void SessionManager()
|
||||||
{
|
{
|
||||||
// Check if the session should be restarted
|
if (!isFinishedSession)
|
||||||
if (isRestartSession)
|
Console.WriteLine("Welcome to the Sim Personality Generator!");
|
||||||
{
|
|
||||||
// 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
|
var message = "Would you like to generate a random personality? [y/n]";
|
||||||
Console.WriteLine("Would you like to generate a random personality? [y/n]");
|
|
||||||
|
|
||||||
// Read the user input
|
if (isFinishedSession)
|
||||||
var input = Console.ReadLine();
|
message = "Would you like to generate a new personality? [y/n]";
|
||||||
|
|
||||||
|
var input = GetUserInput(message);
|
||||||
|
|
||||||
// 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
|
// Convert the input to lowercase to handle case insensitivity
|
||||||
switch (input.ToLower())
|
switch (input?.ToLower())
|
||||||
{
|
{
|
||||||
case "y": // If the user enters 'y'
|
case "y": // If the user enters 'y'
|
||||||
|
if (isFinishedSession) isFinishedSession = false;
|
||||||
// Clear the console for a fresh start
|
// Clear the console for a fresh start
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
// Generate traits (presumably some form of random data)
|
// Generate traits (presumably some form of random data)
|
||||||
|
@ -113,6 +74,5 @@ void LaunchSession()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
LaunchSession();
|
SessionManager();
|
Loading…
Add table
Reference in a new issue