Added DoSomething logic, shoot, eat and intialize.

This commit is contained in:
aqys
2026-03-26 11:21:23 +01:00
parent 75ad3da5c5
commit 13ad815ce1
5 changed files with 58 additions and 4 deletions

View File

@@ -20,7 +20,7 @@ namespace PeopleVille.Equipment
public void Use(Person target)
{
target.Health -= this.Damage;
Console.WriteLine($"{target.Name} has been shot and took {Damage}");
Console.WriteLine($"{target.Name} er blevet skudt og mistede {Damage} liv");
}
}
}

View File

@@ -1,4 +1,6 @@
using PeopleVille.Equipment;
using PeopleVille.WorldBuilder;
using System.Diagnostics.CodeAnalysis;
namespace PeopleVille.Persons
{
@@ -7,7 +9,10 @@ namespace PeopleVille.Persons
public AdultCitizen()
{
Age = RNG.Range(20, 85);
}
public override void Initialize()
{
Manager.TickDone += DoSomething;
}
@@ -39,12 +44,22 @@ namespace PeopleVille.Persons
private void ShootRandomPerson()
{
//
var targets = World.People.Where(x => x != this && x.CurrentLocation == CurrentLocation).ToList();
if (targets.Count == 0)
return;
var target = targets[RNG.ThrowDice(new Die(targets.Count)) - 1];
var gun = Inventory.OfType<Gun>().First();
gun.Use(target);
}
private void EatFood()
{
//
var food = Inventory.OfType<Food>().First();
if (food == null)
return;
food.Use(this);
}
}
}

View File

@@ -1,5 +1,6 @@
using PeopleVille.Equipment;
using PeopleVille.Locations;
using PeopleVille.WorldBuilder;
namespace PeopleVille.Persons
{
@@ -17,6 +18,9 @@ namespace PeopleVille.Persons
public Location CurrentLocation { get; set; }
public GameManager Manager { get; set; }
public World World { get; set; }
public virtual void Initialize() { }
public void Walk(Location newLocation)
{

View File

@@ -11,4 +11,37 @@ var world = new WorldBuilder()
.EndWorldBuilding()
.Build();
await world.manager.StartClock();
await world.manager.StartClock();
/* DoSomething() test
using PeopleVille.Equipment;
using PeopleVille.Locations;
using PeopleVille.Persons;
using PeopleVille.WorldBuilder;
var location = new Bank { Name = "Banken" };
var thomas = new AdultCitizen { Name = "Thomas", Health = 100 };
thomas.Inventory.Add(new Gun { Name = "Glock", Damage = 30 });
thomas.CurrentLocation = location;
var emil = new AdultCitizen { Name = "Emil", Health = 100 };
emil.CurrentLocation = location;
var world = new WorldBuilder()
.AddGameManager()
.AddEquipment()
.AddLocations()
.FromRange([location])
.AddPersons()
.FromRange([thomas, emil])
.EndWorldBuilding()
.Build();
thomas.DoSomething();
thomas.DoSomething();
thomas.DoSomething();
Console.WriteLine($"Emils liv: {emil.Health}");*/

View File

@@ -63,6 +63,8 @@ namespace PeopleVille.WorldBuilder
foreach (var person in world.People)
{
person.Manager = world.manager;
person.World = world;
person.Initialize();
}
return world;