From 6a7399977d10e7af1f32d25d11d9621d3fe246d8 Mon Sep 17 00:00:00 2001 From: aqys Date: Thu, 26 Mar 2026 12:55:30 +0100 Subject: [PATCH] LocationBuilder --- PeopleVille/Location/LocationBuilder.cs | 41 +++++++++++++++++++++++++ PeopleVille/Person/AdultCitizen.cs | 1 + PeopleVille/Program.cs | 3 +- 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 PeopleVille/Location/LocationBuilder.cs diff --git a/PeopleVille/Location/LocationBuilder.cs b/PeopleVille/Location/LocationBuilder.cs new file mode 100644 index 0000000..0533c78 --- /dev/null +++ b/PeopleVille/Location/LocationBuilder.cs @@ -0,0 +1,41 @@ +namespace PeopleVille.Locations +{ + public class LocationBuilder + { + readonly string[] bankNames = ["Nationalbanken", "Borgernes Bank", "Den Store Bank"]; + readonly string[] gunStoreNames = ["Våben Salg", "Bangbang Butikken", "SkyderButikken"]; + readonly string[] eggStoreNames = ["Gårdens Æg", "Æggehuset", "Byens Æg"]; + + public List CreateLocations(int number) + { + List locations = []; + + for (var i = 0; i < number; i++) + { + switch (RNG.ThrowDice(Dices.D3)) + { + case 1: + locations.Add(new Bank() + { + Name = bankNames[RNG.Range(0, bankNames.Length)] + }); + break; + case 2: + locations.Add(new GunStore() + { + Name = gunStoreNames[RNG.Range(0, gunStoreNames.Length)] + }); + break; + case 3: + locations.Add(new EggStore() + { + Name = eggStoreNames[RNG.Range(0, eggStoreNames.Length)] + }); + break; + } + } + + return locations; + } + } +} \ No newline at end of file diff --git a/PeopleVille/Person/AdultCitizen.cs b/PeopleVille/Person/AdultCitizen.cs index 2ded3c0..d437109 100644 --- a/PeopleVille/Person/AdultCitizen.cs +++ b/PeopleVille/Person/AdultCitizen.cs @@ -58,6 +58,7 @@ namespace PeopleVille.Persons var otherLocations = World.Locations.Where(x => x != CurrentLocation).ToList(); if (otherLocations.Count > 0) Walk(otherLocations[RNG.ThrowDice(new Die(otherLocations.Count)) - 1]); + Console.WriteLine($"{Name} Walked to {CurrentLocation.Name}"); break; case 3: //Do nothing diff --git a/PeopleVille/Program.cs b/PeopleVille/Program.cs index bab5742..bc8e350 100644 --- a/PeopleVille/Program.cs +++ b/PeopleVille/Program.cs @@ -4,6 +4,7 @@ using PeopleVille.Persons; using PeopleVille.WorldBuilder; var peopleBuilder = new PeopleBuilder(); +var locationBuilder = new LocationBuilder(); var location = new Bank { Name = "Banken" }; @@ -24,7 +25,7 @@ var world = new WorldBuilder() .AddEquipment() .FromRange([gun, kage]) .AddLocations() - .FromRange([location]) + .FromRange(locationBuilder.CreateLocations(15)) .AddPersons() .FromRange(peopleBuilder.CreatePeople(15)) .WithRandomItems(20)