2025-02-02 01:34:43 -05:00
|
|
|
namespace SimsPersonalityGenerator;
|
|
|
|
|
2025-02-02 03:09:17 -05:00
|
|
|
using System.Text.Json;
|
2025-02-02 02:00:36 -05:00
|
|
|
|
2025-02-02 01:34:43 -05:00
|
|
|
public class Sim
|
|
|
|
{
|
2025-02-02 02:00:36 -05:00
|
|
|
|
2025-02-02 03:09:17 -05:00
|
|
|
public int Nice { get; private set; }
|
|
|
|
public int Neat { get; private set; }
|
|
|
|
public int Outgoing { get; private set; }
|
|
|
|
public int Active { get; private set; }
|
|
|
|
public int Playful { get; private set; }
|
2025-02-02 01:34:43 -05:00
|
|
|
|
2025-02-02 04:09:53 -05:00
|
|
|
const int MIN_HIGHEST_POINT = 8;
|
|
|
|
const int MAX_LOWEST_POINT = 5;
|
|
|
|
|
2025-02-02 03:09:17 -05:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the Sim class with a random personality.
|
|
|
|
/// </summary>
|
2025-02-02 01:34:43 -05:00
|
|
|
public Sim()
|
|
|
|
{
|
|
|
|
GenerateRandomPersonality();
|
|
|
|
}
|
|
|
|
|
2025-02-02 03:09:17 -05:00
|
|
|
/// <summary>
|
|
|
|
/// Sets one personality trait higher or lower and compensates by adjusting another trait.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="trait">The name of the trait to adjust.</param>
|
|
|
|
/// <param name="isHigh">True if the trait should be set higher, false if it should be set lower.</param>
|
2025-02-02 04:09:53 -05:00
|
|
|
public void RebalanceTraits(Traits trait, bool isHigh = false)
|
2025-02-02 01:34:43 -05:00
|
|
|
{
|
2025-02-02 02:00:36 -05:00
|
|
|
switch (trait)
|
2025-02-02 01:34:43 -05:00
|
|
|
{
|
2025-02-02 02:00:36 -05:00
|
|
|
case Traits.Nice:
|
2025-02-02 04:09:53 -05:00
|
|
|
if (isHigh && Nice >= MAX_LOWEST_POINT)
|
|
|
|
Nice = Math.Min(MIN_HIGHEST_POINT, Neat + 5);
|
2025-02-02 01:34:43 -05:00
|
|
|
else
|
2025-02-02 04:09:53 -05:00
|
|
|
Neat = Math.Min(MIN_HIGHEST_POINT, Nice + 5);
|
2025-02-02 01:34:43 -05:00
|
|
|
break;
|
2025-02-02 02:00:36 -05:00
|
|
|
case Traits.Neat:
|
2025-02-02 04:09:53 -05:00
|
|
|
if (isHigh && Neat >= MAX_LOWEST_POINT)
|
|
|
|
Neat = Math.Min(MIN_HIGHEST_POINT, Active + 5);
|
2025-02-02 01:34:43 -05:00
|
|
|
else
|
2025-02-02 04:09:53 -05:00
|
|
|
Active = Math.Min(MIN_HIGHEST_POINT, Neat + 5);
|
2025-02-02 01:34:43 -05:00
|
|
|
break;
|
2025-02-02 02:00:36 -05:00
|
|
|
case Traits.Outgoing:
|
2025-02-02 04:09:53 -05:00
|
|
|
if (isHigh && Outgoing >= MAX_LOWEST_POINT)
|
|
|
|
Outgoing = Math.Min(MIN_HIGHEST_POINT, Playful + 5);
|
2025-02-02 01:34:43 -05:00
|
|
|
else
|
2025-02-02 04:09:53 -05:00
|
|
|
Playful = Math.Min(MIN_HIGHEST_POINT, Outgoing + 5);
|
2025-02-02 01:34:43 -05:00
|
|
|
break;
|
2025-02-02 02:00:36 -05:00
|
|
|
case Traits.Active:
|
2025-02-02 04:09:53 -05:00
|
|
|
if (isHigh && Active >= MAX_LOWEST_POINT)
|
|
|
|
Active = Math.Min(MIN_HIGHEST_POINT, Nice + 5);
|
2025-02-02 01:34:43 -05:00
|
|
|
else
|
2025-02-02 04:09:53 -05:00
|
|
|
Nice = Math.Min(MIN_HIGHEST_POINT, Active + 5);
|
2025-02-02 01:34:43 -05:00
|
|
|
break;
|
2025-02-02 02:00:36 -05:00
|
|
|
case Traits.Playful:
|
2025-02-02 04:09:53 -05:00
|
|
|
if (isHigh && Playful >= MAX_LOWEST_POINT)
|
|
|
|
Playful = Math.Min(MIN_HIGHEST_POINT, Outgoing + 5);
|
2025-02-02 01:34:43 -05:00
|
|
|
else
|
2025-02-02 04:09:53 -05:00
|
|
|
Outgoing = Math.Min(MIN_HIGHEST_POINT, Playful + 5);
|
2025-02-02 01:34:43 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new ArgumentException("Invalid trait name.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-02-02 03:09:17 -05:00
|
|
|
/// <summary>
|
|
|
|
/// Generates a random personality with balanced traits.
|
|
|
|
/// </summary>
|
2025-02-02 04:09:53 -05:00
|
|
|
public void GenerateRandomPersonality()
|
2025-02-02 01:34:43 -05:00
|
|
|
{
|
|
|
|
Random rand = new Random();
|
2025-02-02 03:09:17 -05:00
|
|
|
Nice = rand.Next(11);
|
|
|
|
Neat = rand.Next(11);
|
|
|
|
Outgoing = rand.Next(11);
|
|
|
|
Active = rand.Next(11);
|
|
|
|
Playful = rand.Next(11);
|
2025-02-02 01:34:43 -05:00
|
|
|
|
|
|
|
// Ensure that the sum of traits is balanced
|
2025-02-02 03:09:17 -05:00
|
|
|
int totalSum = Nice + Neat + Outgoing + Active + Playful;
|
2025-02-02 01:34:43 -05:00
|
|
|
if (totalSum > 50)
|
|
|
|
{
|
2025-02-02 03:09:17 -05:00
|
|
|
int average = totalSum - 50;
|
2025-02-02 01:34:43 -05:00
|
|
|
int traitToReduce = rand.Next(5);
|
|
|
|
switch (traitToReduce)
|
|
|
|
{
|
2025-02-02 03:09:17 -05:00
|
|
|
case 0: Nice -= Math.Min(Nice, average); break;
|
|
|
|
case 1: Neat -= Math.Min(Neat, average); break;
|
|
|
|
case 2: Outgoing -= Math.Min(Outgoing, average); break;
|
|
|
|
case 3: Active -= Math.Min(Active, average); break;
|
|
|
|
case 4: Playful -= Math.Min(Playful, average); break;
|
2025-02-02 01:34:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-02-02 03:09:17 -05:00
|
|
|
/// <summary>
|
|
|
|
/// Returns a JSON representation of the character's personality traits.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>A JSON containing the values of all personality traits.</returns>
|
2025-02-02 01:34:43 -05:00
|
|
|
public override string ToString()
|
|
|
|
{
|
2025-02-02 03:09:17 -05:00
|
|
|
var sim = new Sim();
|
|
|
|
{
|
|
|
|
Nice = Nice;
|
|
|
|
Neat = Neat;
|
|
|
|
Outgoing = Outgoing;
|
|
|
|
Playful = Playful;
|
|
|
|
Active = Active;
|
|
|
|
};
|
2025-02-02 04:09:53 -05:00
|
|
|
|
|
|
|
var options = new JsonSerializerOptions()
|
|
|
|
{
|
|
|
|
WriteIndented = true,
|
|
|
|
};
|
|
|
|
|
|
|
|
return JsonSerializer.Serialize<Sim>(sim, options);
|
2025-02-02 01:34:43 -05:00
|
|
|
}
|
|
|
|
}
|