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; }
///
/// 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.
// TODO: Fix trait mix up
public void SetTraitHigher(Traits trait, bool isHigh)
{
switch (trait)
{
case Traits.Nice:
if (isHigh)
Nice = Math.Min(8, Neat + 5);
else
Neat = Math.Min(8, Nice + 5);
break;
case Traits.Neat:
if (isHigh)
Neat = Math.Min(8, Active + 5);
else
Active = Math.Min(8, Neat + 5);
break;
case Traits.Outgoing:
if (isHigh)
Outgoing = Math.Min(8, Playful + 5);
else
Playful = Math.Min(8, Outgoing + 5);
break;
case Traits.Active:
if (isHigh)
Active = Math.Min(8, Nice + 5);
else
Nice = Math.Min(8, Active + 5);
break;
case Traits.Playful:
if (isHigh)
Playful = Math.Min(8, Outgoing + 5);
else
Outgoing = Math.Min(8, Playful + 5);
break;
default:
throw new ArgumentException("Invalid trait name.");
}
}
///
/// Generates a random personality with balanced traits.
///
private 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;
};
return JsonSerializer.Serialize(sim);
}
}