From 13ad815ce17d46caeef7e39bff179e48795589af Mon Sep 17 00:00:00 2001 From: aqys Date: Thu, 26 Mar 2026 11:21:23 +0100 Subject: [PATCH] Added DoSomething logic, shoot, eat and intialize. --- PeopleVille/Equipment/Gun.cs | 2 +- PeopleVille/Person/AdultCitizen.cs | 19 +++++++++++-- PeopleVille/Person/Person.cs | 4 +++ PeopleVille/Program.cs | 35 +++++++++++++++++++++++- PeopleVille/WorldBuilder/WorldBuilder.cs | 2 ++ 5 files changed, 58 insertions(+), 4 deletions(-) diff --git a/PeopleVille/Equipment/Gun.cs b/PeopleVille/Equipment/Gun.cs index 045a947..c309600 100644 --- a/PeopleVille/Equipment/Gun.cs +++ b/PeopleVille/Equipment/Gun.cs @@ -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"); } } } diff --git a/PeopleVille/Person/AdultCitizen.cs b/PeopleVille/Person/AdultCitizen.cs index 36d5900..6aa8d70 100644 --- a/PeopleVille/Person/AdultCitizen.cs +++ b/PeopleVille/Person/AdultCitizen.cs @@ -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().First(); + gun.Use(target); } private void EatFood() { - // + var food = Inventory.OfType().First(); + if (food == null) + return; + + food.Use(this); } } } \ No newline at end of file diff --git a/PeopleVille/Person/Person.cs b/PeopleVille/Person/Person.cs index bdb6d84..42420b1 100644 --- a/PeopleVille/Person/Person.cs +++ b/PeopleVille/Person/Person.cs @@ -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) { diff --git a/PeopleVille/Program.cs b/PeopleVille/Program.cs index b8d6ede..6896832 100644 --- a/PeopleVille/Program.cs +++ b/PeopleVille/Program.cs @@ -11,4 +11,37 @@ var world = new WorldBuilder() .EndWorldBuilding() .Build(); -await world.manager.StartClock(); \ No newline at end of file +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}");*/ \ No newline at end of file diff --git a/PeopleVille/WorldBuilder/WorldBuilder.cs b/PeopleVille/WorldBuilder/WorldBuilder.cs index 907f0d1..af81a83 100644 --- a/PeopleVille/WorldBuilder/WorldBuilder.cs +++ b/PeopleVille/WorldBuilder/WorldBuilder.cs @@ -63,6 +63,8 @@ namespace PeopleVille.WorldBuilder foreach (var person in world.People) { person.Manager = world.manager; + person.World = world; + person.Initialize(); } return world;