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