TownBuilder, og lidt refactoring

This commit is contained in:
aqys
2026-03-25 11:19:52 +01:00
parent 44577a2ff0
commit 09998f8e07
9 changed files with 55 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
using PeopleVille.Location;
using PeopleVille.Locations;
namespace PeopleVille
{

View File

@@ -1,4 +1,4 @@
namespace PeopleVille.Location
namespace PeopleVille.Locations
{
public class Bank : Location
{

View File

@@ -1,4 +1,4 @@
namespace PeopleVille.Location
namespace PeopleVille.Locations
{
public class EggStore : Store
{

View File

@@ -1,4 +1,4 @@
namespace PeopleVille.Location
namespace PeopleVille.Locations
{
public class GunStore : Store
{

View File

@@ -1,4 +1,4 @@
namespace PeopleVille.Location
namespace PeopleVille.Locations
{
public abstract class Location
{

View File

@@ -1,6 +1,6 @@
using PeopleVille.Equipment;
namespace PeopleVille.Location
namespace PeopleVille.Locations
{
public class Store : Location
{

View File

@@ -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(); */
tBuilder
.AddBank("PeopleVille Bank")
.AddGunStore("Gun Store")
.AddEggStore("Egg Store");
var borgere = cBuilder.BuildCitizens();
var locations = tBuilder.BuildTown(); */

View File

@@ -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<Location> locations = new List<Location>();
public ITownBuilder AddGunStore(string name)
{
locations.Add(new GunStore { Name = name, Inventory = new Dictionary<object, int>() });
return this;
}
public ITownBuilder AddEggStore(string name)
{
locations.Add(new EggStore { Name = name, Inventory = new Dictionary<object, int>() });
return this;
}
public ITownBuilder AddBank(string name)
{
locations.Add(new Bank { Name = name });
return this;
}
public List<Location> BuildTown()
{
return locations;
}
}
}

View File

@@ -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<Location> 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();
}
}
}