From 09998f8e0795dd64f2295cd21859117adc1e3fc1 Mon Sep 17 00:00:00 2001 From: aqys <51910@edu.sde.dk> Date: Wed, 25 Mar 2026 11:19:52 +0100 Subject: [PATCH] TownBuilder, og lidt refactoring --- PeopleVille/GameManager.cs | 2 +- PeopleVille/Location/Bank.cs | 2 +- PeopleVille/Location/EggStore.cs | 2 +- PeopleVille/Location/GunStore.cs | 2 +- PeopleVille/Location/ILocation.cs | 2 +- PeopleVille/Location/Store.cs | 2 +- PeopleVille/Program.cs | 17 +++++++---- PeopleVille/WorldBuilder/WorldBuilder.cs | 31 ++++++++++++++++++++- PeopleVille/WorldBuilder/WorldInterfaces.cs | 10 +++++-- 9 files changed, 55 insertions(+), 15 deletions(-) diff --git a/PeopleVille/GameManager.cs b/PeopleVille/GameManager.cs index 7285fef..8d2e371 100644 --- a/PeopleVille/GameManager.cs +++ b/PeopleVille/GameManager.cs @@ -1,4 +1,4 @@ -using PeopleVille.Location; +using PeopleVille.Locations; namespace PeopleVille { diff --git a/PeopleVille/Location/Bank.cs b/PeopleVille/Location/Bank.cs index 82f16a6..f153f79 100644 --- a/PeopleVille/Location/Bank.cs +++ b/PeopleVille/Location/Bank.cs @@ -1,4 +1,4 @@ -namespace PeopleVille.Location +namespace PeopleVille.Locations { public class Bank : Location { diff --git a/PeopleVille/Location/EggStore.cs b/PeopleVille/Location/EggStore.cs index 57858a5..6822768 100644 --- a/PeopleVille/Location/EggStore.cs +++ b/PeopleVille/Location/EggStore.cs @@ -1,4 +1,4 @@ -namespace PeopleVille.Location +namespace PeopleVille.Locations { public class EggStore : Store { diff --git a/PeopleVille/Location/GunStore.cs b/PeopleVille/Location/GunStore.cs index d9ff040..31365f7 100644 --- a/PeopleVille/Location/GunStore.cs +++ b/PeopleVille/Location/GunStore.cs @@ -1,4 +1,4 @@ -namespace PeopleVille.Location +namespace PeopleVille.Locations { public class GunStore : Store { diff --git a/PeopleVille/Location/ILocation.cs b/PeopleVille/Location/ILocation.cs index 9ee3068..f56c97a 100644 --- a/PeopleVille/Location/ILocation.cs +++ b/PeopleVille/Location/ILocation.cs @@ -1,4 +1,4 @@ -namespace PeopleVille.Location +namespace PeopleVille.Locations { public abstract class Location { diff --git a/PeopleVille/Location/Store.cs b/PeopleVille/Location/Store.cs index 12756f6..33757e6 100644 --- a/PeopleVille/Location/Store.cs +++ b/PeopleVille/Location/Store.cs @@ -1,6 +1,6 @@ using PeopleVille.Equipment; -namespace PeopleVille.Location +namespace PeopleVille.Locations { public class Store : Location { diff --git a/PeopleVille/Program.cs b/PeopleVille/Program.cs index 573b521..9003fb4 100644 --- a/PeopleVille/Program.cs +++ b/PeopleVille/Program.cs @@ -12,15 +12,22 @@ Console.WriteLine("Hello, World!"); /* burde i teorien virke? -var testCitizen = new AdultCitizen { Name = "", Health = 100 }; +var testCitizen = new AdultCitizen { Name = "Lars", Health = 100 }; testCitizen.Inventory.Add(new Gun { Name = "Glock", Damage = 50 }); */ -/* builder? -var builder = new CitizenBuilder(); +/* builders? byggemand-bob reference? +var cBuilder = new CitizenBuilder(); +var tBuilder = new TownBuilder(); -builder +cBuilder .CreateAdult("Lars", 100).WithGun("Glock", 20) .CreateAdult("Thomas", 100).WithGun("AK", 40).WithFood("Hvid Monster", 0) .CreateChild("Troels", 60).WithFood("Apple", 10); -var borgere = builder.Build(); */ \ No newline at end of file +tBuilder + .AddBank("PeopleVille Bank") + .AddGunStore("Gun Store") + .AddEggStore("Egg Store"); + +var borgere = cBuilder.BuildCitizens(); +var locations = tBuilder.BuildTown(); */ \ No newline at end of file diff --git a/PeopleVille/WorldBuilder/WorldBuilder.cs b/PeopleVille/WorldBuilder/WorldBuilder.cs index 9ed002b..bd7a4b8 100644 --- a/PeopleVille/WorldBuilder/WorldBuilder.cs +++ b/PeopleVille/WorldBuilder/WorldBuilder.cs @@ -1,4 +1,5 @@ using PeopleVille.Equipment; +using PeopleVille.Locations; using PeopleVille.Persons; using System; using System.Collections.Generic; @@ -38,9 +39,37 @@ namespace PeopleVille.WorldBuilder return this; } - public Person Build() + public Person BuildCitizens() { return person; } } + + public class TownBuilder : ITownBuilder + { + List locations = new List(); + + public ITownBuilder AddGunStore(string name) + { + locations.Add(new GunStore { Name = name, Inventory = new Dictionary() }); + return this; + } + + public ITownBuilder AddEggStore(string name) + { + locations.Add(new EggStore { Name = name, Inventory = new Dictionary() }); + return this; + } + + public ITownBuilder AddBank(string name) + { + locations.Add(new Bank { Name = name }); + return this; + } + + public List BuildTown() + { + return locations; + } + } } diff --git a/PeopleVille/WorldBuilder/WorldInterfaces.cs b/PeopleVille/WorldBuilder/WorldInterfaces.cs index 74fbe45..64a925c 100644 --- a/PeopleVille/WorldBuilder/WorldInterfaces.cs +++ b/PeopleVille/WorldBuilder/WorldInterfaces.cs @@ -1,4 +1,5 @@ -using PeopleVille.Persons; +using PeopleVille.Locations; +using PeopleVille.Persons; namespace PeopleVille.WorldBuilder { @@ -11,7 +12,10 @@ namespace PeopleVille.WorldBuilder public interface ITownBuilder { - + ITownBuilder AddGunStore(string name); + ITownBuilder AddEggStore(string name); + ITownBuilder AddBank(string name); + List BuildTown(); } public interface ICitizenBuilder @@ -20,7 +24,7 @@ namespace PeopleVille.WorldBuilder ICitizenBuilder CreateChild(string name, int health); ICitizenBuilder WithGun(string name, int damage); ICitizenBuilder WithFood(string name, int healthPoints); - Person Build(); + Person BuildCitizens(); } } }