SimsPersonalityGenerator/Sim.cs

91 lines
3 KiB
C#
Raw Normal View History

2025-02-02 01:34:43 -05:00
namespace SimsPersonalityGenerator;
2025-02-02 02:00:36 -05:00
public enum Traits { Nice, Neat, Outgoing, Active, Playful }
2025-02-02 01:34:43 -05:00
public class Sim
{
2025-02-02 02:00:36 -05:00
2025-02-02 01:34:43 -05:00
public int Niceness { get; private set; }
public int Neatness { get; private set; }
public int Outgoingness { get; private set; }
public int Activeness { get; private set; }
2025-02-02 02:00:36 -05:00
public int Laziness { get; private set; }
2025-02-02 01:34:43 -05:00
public int Playfulness { get; private set; }
public Sim()
{
GenerateRandomPersonality();
}
2025-02-02 02:00:36 -05:00
// TODO: Fix trait mix up
public void SetTraitHigher(Traits trait, bool isHigh)
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 01:34:43 -05:00
if (isHigh)
Niceness = Math.Min(10, Neatness + 5);
else
Neatness = Math.Min(10, Niceness + 5);
break;
2025-02-02 02:00:36 -05:00
case Traits.Neat:
2025-02-02 01:34:43 -05:00
if (isHigh)
Neatness = Math.Min(10, Activeness + 5);
else
Activeness = Math.Min(10, Neatness + 5);
break;
2025-02-02 02:00:36 -05:00
case Traits.Outgoing:
2025-02-02 01:34:43 -05:00
if (isHigh)
Outgoingness = Math.Min(10, Playfulness + 5);
else
Playfulness = Math.Min(10, Outgoingness + 5);
break;
2025-02-02 02:00:36 -05:00
case Traits.Active:
2025-02-02 01:34:43 -05:00
if (isHigh)
Activeness = Math.Min(10, Niceness + 5);
else
Niceness = Math.Min(10, Activeness + 5);
break;
2025-02-02 02:00:36 -05:00
case Traits.Playful:
2025-02-02 01:34:43 -05:00
if (isHigh)
Playfulness = Math.Min(10, Outgoingness + 5);
else
Outgoingness = Math.Min(10, Playfulness + 5);
break;
default:
throw new ArgumentException("Invalid trait name.");
}
}
private void GenerateRandomPersonality()
{
Random rand = new Random();
Niceness = rand.Next(11);
Neatness = rand.Next(11);
Outgoingness = rand.Next(11);
Activeness = rand.Next(11);
Playfulness = rand.Next(11);
// Ensure that the sum of traits is balanced
int totalSum = Niceness + Neatness + Outgoingness + Activeness + Playfulness;
if (totalSum > 50)
{
int overage = totalSum - 50;
int traitToReduce = rand.Next(5);
switch (traitToReduce)
{
case 0: Niceness -= Math.Min(Niceness, overage); break;
case 1: Neatness -= Math.Min(Neatness, overage); break;
case 2: Outgoingness -= Math.Min(Outgoingness, overage); break;
case 3: Activeness -= Math.Min(Activeness, overage); break;
case 4: Playfulness -= Math.Min(Playfulness, overage); break;
}
}
}
public override string ToString()
{
return $"Niceness: {Niceness}, Neatness: {Neatness}, Outgoingness: {Outgoingness}, Activeness: {Activeness}, Playfulness: {Playfulness}";
}
}