From ea1d6b0634a54feda60ee89bd5c0b93f0f9622c4 Mon Sep 17 00:00:00 2001 From: smallbenji Date: Thu, 26 Mar 2026 12:04:25 +0100 Subject: [PATCH] history is flowing --- PeopleVille/Equipment/Food.cs | 2 +- PeopleVille/Person/AdultCitizen.cs | 59 ++++++++++++++------- PeopleVille/Person/Person.cs | 3 +- PeopleVille/Person/PersonBuilder.cs | 39 ++++++++++++++ PeopleVille/Program.cs | 28 ++++++++-- PeopleVille/RNG.cs | 1 + PeopleVille/WorldBuilder/WorldBuilder.cs | 13 +++++ PeopleVille/WorldBuilder/WorldInterfaces.cs | 1 + 8 files changed, 121 insertions(+), 25 deletions(-) create mode 100644 PeopleVille/Person/PersonBuilder.cs diff --git a/PeopleVille/Equipment/Food.cs b/PeopleVille/Equipment/Food.cs index a7bc38a..7610688 100644 --- a/PeopleVille/Equipment/Food.cs +++ b/PeopleVille/Equipment/Food.cs @@ -20,7 +20,7 @@ namespace PeopleVille.Equipment public void Use(Person person) { person.Health += HealthPoints; - Console.WriteLine($"{person} ate food and healed {HealthPoints}"); + Console.WriteLine($"{person.Name} ate food and healed {HealthPoints}"); person.Inventory.Remove(this); } } diff --git a/PeopleVille/Person/AdultCitizen.cs b/PeopleVille/Person/AdultCitizen.cs index b4f5e4a..74e1dc0 100644 --- a/PeopleVille/Person/AdultCitizen.cs +++ b/PeopleVille/Person/AdultCitizen.cs @@ -17,33 +17,54 @@ namespace PeopleVille.Persons public void DoSomething() { - // 50/50 om vi gør noget eller ej - if (RNG.ThrowDice(Dices.D2) == 1) + if (this.Health <= 0 && !Dead) + { + this.Dead = true; + + Console.WriteLine($"RIP: {this.Name} døde..."); + return; - - bool hasGun = Inventory.OfType().Any(); - bool hasUnder100 = Health < 100; - - if (hasGun && hasUnder100) - { - if (RNG.ThrowDice(Dices.D2) == 1) - ShootRandomPerson(); - else - EatFood(); } - else if (hasGun) + + // 50/50 om vi gør noget eller ej + if (RNG.ThrowDice(Dices.D3) == 1) + return; + switch (RNG.ThrowDice(Dices.D3)) { - ShootRandomPerson(); - } - else if (hasUnder100) - { - EatFood(); + case 1: + bool hasGun = Inventory.OfType().Any(); + bool hasUnder100 = Health < 100; + bool hasFood = Inventory.OfType().Any(); + + if (hasGun && hasUnder100) + { + if (RNG.ThrowDice(Dices.D2) == 1) + ShootRandomPerson(); + else + if (hasFood) + EatFood(); + } + else if (hasGun) + { + ShootRandomPerson(); + } + else if (hasUnder100 && hasFood) + { + EatFood(); + } + break; + case 2: + //Move location + break; + case 3: + //Do nothing + break; } } private void ShootRandomPerson() { - var targets = World.People.Where(x => x != this && x.CurrentLocation == CurrentLocation).ToList(); + var targets = World.People.Where(x => x != this && x.CurrentLocation == CurrentLocation && !x.Dead).ToList(); if (targets.Count == 0) return; diff --git a/PeopleVille/Person/Person.cs b/PeopleVille/Person/Person.cs index 42420b1..8772ecb 100644 --- a/PeopleVille/Person/Person.cs +++ b/PeopleVille/Person/Person.cs @@ -7,7 +7,7 @@ namespace PeopleVille.Persons public abstract class Person { public string Name { get; set; } - public int Health { get; set; } + public int Health { get; set; } = 100; // hellere at de starter med tomt inventory end et inventory der ikke eksisterer. public List Inventory { get; set; } = []; @@ -19,6 +19,7 @@ namespace PeopleVille.Persons public GameManager Manager { get; set; } public World World { get; set; } + public bool Dead { get; set; } = false; public virtual void Initialize() { } diff --git a/PeopleVille/Person/PersonBuilder.cs b/PeopleVille/Person/PersonBuilder.cs new file mode 100644 index 0000000..782749d --- /dev/null +++ b/PeopleVille/Person/PersonBuilder.cs @@ -0,0 +1,39 @@ +namespace PeopleVille.Persons +{ + public class PeopleBuilder + { + readonly string[] maleNames = ["John", "Peter", "Mikkel", "Lars", "Benjamin"]; + readonly string[] femaleNames = ["Cirkeline", "Josefine", "Simone", "Gertrud", "Smilla"]; + readonly string[] lastNames = ["Petersen", "Rasmussen", "Madsen"]; + + public List CreatePeople(int number) + { + List people = []; + + for (var i = 0; i < number; i++) + { + string name = String.Empty; + switch (RNG.ThrowDice(Dices.D2)) + { + case 1: + name += maleNames[RNG.Range(0, maleNames.Length)]; + break; + case 2: + name += femaleNames[RNG.Range(0, femaleNames.Length)]; + break; + default: + throw new Exception("What happened?"); + } + + name += " " + lastNames[RNG.Range(0, lastNames.Length)]; + + people.Add(new AdultCitizen() + { + Name = name + }); + } + + return people; + } + } +} \ No newline at end of file diff --git a/PeopleVille/Program.cs b/PeopleVille/Program.cs index 6896832..bab5742 100644 --- a/PeopleVille/Program.cs +++ b/PeopleVille/Program.cs @@ -1,13 +1,33 @@ -using PeopleVille.WorldBuilder; +using PeopleVille.Equipment; +using PeopleVille.Locations; +using PeopleVille.Persons; +using PeopleVille.WorldBuilder; + +var peopleBuilder = new PeopleBuilder(); + +var location = new Bank { Name = "Banken" }; + +var gun = new Gun() +{ + Name = "Glock-18", + Damage = 20 +}; + +var kage = new Food() +{ + Name = "Kage", + HealthPoints = 20 +}; var world = new WorldBuilder() .AddGameManager() .AddEquipment() - .FromFile("/path/to/file") + .FromRange([gun, kage]) .AddLocations() - .FromFolder("/path/to/folder") + .FromRange([location]) .AddPersons() - .FromFile("/path/to/file") + .FromRange(peopleBuilder.CreatePeople(15)) + .WithRandomItems(20) .EndWorldBuilding() .Build(); diff --git a/PeopleVille/RNG.cs b/PeopleVille/RNG.cs index b044458..431dae0 100644 --- a/PeopleVille/RNG.cs +++ b/PeopleVille/RNG.cs @@ -25,6 +25,7 @@ namespace PeopleVille public static class Dices { public static Die D2 = new(2); + public static Die D3 = new(3); public static Die D4 = new(4); public static Die D6 = new(6); } diff --git a/PeopleVille/WorldBuilder/WorldBuilder.cs b/PeopleVille/WorldBuilder/WorldBuilder.cs index af81a83..869026e 100644 --- a/PeopleVille/WorldBuilder/WorldBuilder.cs +++ b/PeopleVille/WorldBuilder/WorldBuilder.cs @@ -140,5 +140,18 @@ namespace PeopleVille.WorldBuilder return instances; } + + IPersonBuilder IPersonBuilder.WithRandomItems(int number) + { + foreach (var person in world.People) + { + for (var i = 0; i < number; i++) + { + person.Inventory.Add(world.Equipment[RNG.Range(0, world.Equipment.Count)]); + } + } + + return this; + } } } diff --git a/PeopleVille/WorldBuilder/WorldInterfaces.cs b/PeopleVille/WorldBuilder/WorldInterfaces.cs index cde463f..da8e8e5 100644 --- a/PeopleVille/WorldBuilder/WorldInterfaces.cs +++ b/PeopleVille/WorldBuilder/WorldInterfaces.cs @@ -36,6 +36,7 @@ namespace PeopleVille.WorldBuilder IPersonBuilder FromFolder(string pathToFolder); IPersonBuilder FromFile(string pathToFile); IPersonBuilder FromRange(IEnumerable people); + IPersonBuilder WithRandomItems(int number); IWorldBuilder EndWorldBuilding(); }