a new version wich is so much worse that i cant just delete it

This commit is contained in:
M.Rohmer
2022-03-03 20:17:36 +01:00
parent 3a561f2d0a
commit 413c6213ce
3 changed files with 157 additions and 130 deletions
+41 -41
View File
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace PropagationRemasteredBeta
{
public class Human:ICloneable
public class Human : ICloneable
{
//State values
public Color SAIN_COLOR = Color.Green;
@@ -34,8 +34,9 @@ namespace PropagationRemasteredBeta
{
get { return _state; }
//We set the counter of infection whenever we set it to infected
set {
_state = value;
set
{
_state = value;
if (_state == INFECTED) { _InfectedTimeCounter = 1; }
switch (_state)
{
@@ -73,7 +74,7 @@ namespace PropagationRemasteredBeta
}
//we dont have any constructor with only default values because the human needs his position in the field to process the infection
public void ChangeBaseColors(Color sainColor,Color infectedColor,Color immuneColor,Color deadColor)
public void ChangeBaseColors(Color sainColor, Color infectedColor, Color immuneColor, Color deadColor)
{
SAIN_COLOR = sainColor;
IMMUNE_COLOR = immuneColor;
@@ -81,91 +82,90 @@ namespace PropagationRemasteredBeta
INFECTED_COLOR = infectedColor;
}
public void Propagate(Human[,] previousTerrain, Human[,] nextTerrain, int infectiosity, int deathRate, int cureTime, Random rnd)
public void Propagate(Terrain terrain)
{
Human target;
Point location;
//target = previousTerrain[Position.X, Position.Y];
LifeTimeCounter++;
InfectedTimeCounter++;
if (this.State == INFECTED)
if (terrain.Rnd.Next(0, 100) <= terrain.DeathRate)
{
InfectedTimeCounter++;
if (rnd.Next(0, 100) <= deathRate)
{
this.State = DEAD;
nextTerrain[this.Position.X, this.Position.Y] = this;
}
if (LifeTimeCounter >= cureTime)
this.State = DEAD;
terrain.InfectedPeoples.Remove(this);
terrain.DeadPeoples.Add(this);
}
else
{
if (LifeTimeCounter >= terrain.CureTime)
{
this.State = IMMUNE;
terrain.ImmunesPeoples.Add(this);
terrain.InfectedPeoples.Remove(this);
}
else
{
//we need to check if we are not in a corner
if (Position.X > 0 && Position.Y > 0 && Position.X < (previousTerrain.GetLength(0) - 1) && Position.Y < (previousTerrain.GetLength(1) - 1))
if (Position.X > 0 && Position.Y > 0 && Position.X < (terrain.TerrainSize.Width - 1) && Position.Y < (terrain.TerrainSize.Height - 1))
{
//check top left
location = new Point(Position.X - 1, Position.Y + 1);
target = previousTerrain[location.X, location.Y];
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd);
target = terrain.Population[location.X, location.Y];
CheckInfection(terrain, target, terrain.InfectionRate, terrain.Rnd);
//check top
location = new Point(Position.X, Position.Y + 1);
target = previousTerrain[location.X, location.Y];
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd);
target = terrain.Population[location.X, location.Y];
CheckInfection(terrain, target, terrain.InfectionRate, terrain.Rnd);
//check top left
location = new Point(Position.X + 1, Position.Y + 1);
target = previousTerrain[location.X, location.Y];
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd);
target = terrain.Population[location.X, location.Y];
CheckInfection(terrain, target, terrain.InfectionRate, terrain.Rnd);
//check left
location = new Point(Position.X - 1, Position.Y);
target = previousTerrain[location.X, location.Y];
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd);
target = terrain.Population[location.X, location.Y];
CheckInfection(terrain, target, terrain.InfectionRate, terrain.Rnd);
//check right
location = new Point(Position.X + 1, Position.Y);
target = previousTerrain[location.X, location.Y];
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd);
target = terrain.Population[location.X, location.Y];
CheckInfection(terrain, target, terrain.InfectionRate, terrain.Rnd);
//check bottom left
location = new Point(Position.X - 1, Position.Y - 1);
target = previousTerrain[location.X, location.Y];
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd);
target = terrain.Population[location.X, location.Y];
CheckInfection(terrain, target, terrain.InfectionRate, terrain.Rnd);
//check bottom
location = new Point(Position.X, Position.Y - 1);
target = previousTerrain[location.X, location.Y];
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd);
target = terrain.Population[location.X, location.Y];
CheckInfection(terrain, target, terrain.InfectionRate, terrain.Rnd);
//check bottom right
location = new Point(Position.X + 1, Position.Y - 1);
target = previousTerrain[location.X, location.Y];
CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd);
target = terrain.Population[location.X, location.Y];
CheckInfection(terrain, target, terrain.InfectionRate, terrain.Rnd);
}
}
}
}
private void CheckInfection(Human[,] nextTerrain, Human target, int infectiosity, int deathRate, Random rnd)
private void CheckInfection(Terrain terrain, Human target, int infectiosity, Random rnd)
{
if (target.State == SAIN)
//if (terrain.OldSainPeoples.Contains(target) && rnd.Next(0, 100) <= infectiosity)
if(target.State == Human.SAIN && rnd.Next(0, 100) <= infectiosity)
{
if (rnd.Next(0, 100) <= infectiosity)
{
target.State = INFECTED;
}
target.State = INFECTED;
terrain.InfectedPeoples.Add(target);
terrain.SainPeoples.Remove(target);
}
nextTerrain[target.Position.X, target.Position.Y] = target;
}
public object Clone()
{
Human newHuman = new Human(Position,State);
Human newHuman = new Human(Position, State);
newHuman.HumanSize = HumanSize;
newHuman.InfectedTimeCounter = InfectedTimeCounter;
newHuman.LifeTimeCounter = LifeTimeCounter;