history is flowing
This commit is contained in:
@@ -20,7 +20,7 @@ namespace PeopleVille.Equipment
|
||||
public void Use(Person person)
|
||||
{
|
||||
person.Health += HealthPoints;
|
||||
Console.WriteLine($"{person} ate food and healed {HealthPoints}");
|
||||
Console.WriteLine($"{person.Name} ate food and healed {HealthPoints}");
|
||||
person.Inventory.Remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,33 +17,54 @@ namespace PeopleVille.Persons
|
||||
|
||||
public void DoSomething()
|
||||
{
|
||||
// 50/50 om vi gør noget eller ej
|
||||
if (RNG.ThrowDice(Dices.D2) == 1)
|
||||
return;
|
||||
if (this.Health <= 0 && !Dead)
|
||||
{
|
||||
this.Dead = true;
|
||||
|
||||
Console.WriteLine($"RIP: {this.Name} døde...");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// 50/50 om vi gør noget eller ej
|
||||
if (RNG.ThrowDice(Dices.D3) == 1)
|
||||
return;
|
||||
switch (RNG.ThrowDice(Dices.D3))
|
||||
{
|
||||
case 1:
|
||||
bool hasGun = Inventory.OfType<Gun>().Any();
|
||||
bool hasUnder100 = Health < 100;
|
||||
bool hasFood = Inventory.OfType<Food>().Any();
|
||||
|
||||
if (hasGun && hasUnder100)
|
||||
{
|
||||
if (RNG.ThrowDice(Dices.D2) == 1)
|
||||
ShootRandomPerson();
|
||||
else
|
||||
if (hasFood)
|
||||
EatFood();
|
||||
}
|
||||
else if (hasGun)
|
||||
{
|
||||
ShootRandomPerson();
|
||||
}
|
||||
else if (hasUnder100)
|
||||
else if (hasUnder100 && hasFood)
|
||||
{
|
||||
EatFood();
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
//Move location
|
||||
break;
|
||||
case 3:
|
||||
//Do nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ShootRandomPerson()
|
||||
{
|
||||
var targets = World.People.Where(x => x != this && x.CurrentLocation == CurrentLocation).ToList();
|
||||
var targets = World.People.Where(x => x != this && x.CurrentLocation == CurrentLocation && !x.Dead).ToList();
|
||||
if (targets.Count == 0)
|
||||
return;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace PeopleVille.Persons
|
||||
public abstract class Person
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int Health { get; set; }
|
||||
public int Health { get; set; } = 100;
|
||||
|
||||
// hellere at de starter med tomt inventory end et inventory der ikke eksisterer.
|
||||
public List<IEquipment> Inventory { get; set; } = [];
|
||||
@@ -19,6 +19,7 @@ namespace PeopleVille.Persons
|
||||
|
||||
public GameManager Manager { get; set; }
|
||||
public World World { get; set; }
|
||||
public bool Dead { get; set; } = false;
|
||||
|
||||
public virtual void Initialize() { }
|
||||
|
||||
|
||||
39
PeopleVille/Person/PersonBuilder.cs
Normal file
39
PeopleVille/Person/PersonBuilder.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
namespace PeopleVille.Persons
|
||||
{
|
||||
public class PeopleBuilder
|
||||
{
|
||||
readonly string[] maleNames = ["John", "Peter", "Mikkel", "Lars", "Benjamin"];
|
||||
readonly string[] femaleNames = ["Cirkeline", "Josefine", "Simone", "Gertrud", "Smilla"];
|
||||
readonly string[] lastNames = ["Petersen", "Rasmussen", "Madsen"];
|
||||
|
||||
public List<Person> CreatePeople(int number)
|
||||
{
|
||||
List<Person> people = [];
|
||||
|
||||
for (var i = 0; i < number; i++)
|
||||
{
|
||||
string name = String.Empty;
|
||||
switch (RNG.ThrowDice(Dices.D2))
|
||||
{
|
||||
case 1:
|
||||
name += maleNames[RNG.Range(0, maleNames.Length)];
|
||||
break;
|
||||
case 2:
|
||||
name += femaleNames[RNG.Range(0, femaleNames.Length)];
|
||||
break;
|
||||
default:
|
||||
throw new Exception("What happened?");
|
||||
}
|
||||
|
||||
name += " " + lastNames[RNG.Range(0, lastNames.Length)];
|
||||
|
||||
people.Add(new AdultCitizen()
|
||||
{
|
||||
Name = name
|
||||
});
|
||||
}
|
||||
|
||||
return people;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,33 @@
|
||||
using PeopleVille.WorldBuilder;
|
||||
using PeopleVille.Equipment;
|
||||
using PeopleVille.Locations;
|
||||
using PeopleVille.Persons;
|
||||
using PeopleVille.WorldBuilder;
|
||||
|
||||
var peopleBuilder = new PeopleBuilder();
|
||||
|
||||
var location = new Bank { Name = "Banken" };
|
||||
|
||||
var gun = new Gun()
|
||||
{
|
||||
Name = "Glock-18",
|
||||
Damage = 20
|
||||
};
|
||||
|
||||
var kage = new Food()
|
||||
{
|
||||
Name = "Kage",
|
||||
HealthPoints = 20
|
||||
};
|
||||
|
||||
var world = new WorldBuilder()
|
||||
.AddGameManager()
|
||||
.AddEquipment()
|
||||
.FromFile("/path/to/file")
|
||||
.FromRange([gun, kage])
|
||||
.AddLocations()
|
||||
.FromFolder("/path/to/folder")
|
||||
.FromRange([location])
|
||||
.AddPersons()
|
||||
.FromFile("/path/to/file")
|
||||
.FromRange(peopleBuilder.CreatePeople(15))
|
||||
.WithRandomItems(20)
|
||||
.EndWorldBuilding()
|
||||
.Build();
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace PeopleVille
|
||||
public static class Dices
|
||||
{
|
||||
public static Die D2 = new(2);
|
||||
public static Die D3 = new(3);
|
||||
public static Die D4 = new(4);
|
||||
public static Die D6 = new(6);
|
||||
}
|
||||
|
||||
@@ -140,5 +140,18 @@ namespace PeopleVille.WorldBuilder
|
||||
|
||||
return instances;
|
||||
}
|
||||
|
||||
IPersonBuilder IPersonBuilder.WithRandomItems(int number)
|
||||
{
|
||||
foreach (var person in world.People)
|
||||
{
|
||||
for (var i = 0; i < number; i++)
|
||||
{
|
||||
person.Inventory.Add(world.Equipment[RNG.Range(0, world.Equipment.Count)]);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace PeopleVille.WorldBuilder
|
||||
IPersonBuilder FromFolder(string pathToFolder);
|
||||
IPersonBuilder FromFile(string pathToFile);
|
||||
IPersonBuilder FromRange(IEnumerable<Person> people);
|
||||
IPersonBuilder WithRandomItems(int number);
|
||||
IWorldBuilder EndWorldBuilding();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user