using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PropagationRemasteredBeta { public class Human:ICloneable { //State values public Color SAIN_COLOR = Color.Green; public Color INFECTED_COLOR = Color.Red; public Color IMMUNE_COLOR = Color.Blue; public Color DEATH_COLOR = Color.Black; public const int SAIN = 0; public const int INFECTED = 1; public const int IMMUNE = 2; public const int DEAD = 3; const int DEFAULT_HUMAN_SIZE = 1; private Point _position; private int _state; private Size _humanSize; private int _lifeTimeCounter; private int _InfectedTimeCounter; private Color _sprite; public Point Position { get => _position; set => _position = value; } public int State { get { return _state; } //We set the counter of infection whenever we set it to infected set { _state = value; if (_state == INFECTED) { _InfectedTimeCounter = 1; } switch (_state) { case INFECTED: Sprite = INFECTED_COLOR; break; case SAIN: Sprite = SAIN_COLOR; break; case DEAD: Sprite = DEATH_COLOR; break; case IMMUNE: Sprite = IMMUNE_COLOR; break; } } } public Size HumanSize { get => _humanSize; set => _humanSize = value; } public int LifeTimeCounter { get => _lifeTimeCounter; set => _lifeTimeCounter = value; } public int InfectedTimeCounter { get => _InfectedTimeCounter; set => _InfectedTimeCounter = value; } public Color Sprite { get => _sprite; set => _sprite = value; } public Human(Point position, int state, Size humanSize) { HumanSize = humanSize; Position = position; State = state; LifeTimeCounter = 1; InfectedTimeCounter = 0; } public Human(Point position, int state) : this(position, state, new Size(DEFAULT_HUMAN_SIZE, DEFAULT_HUMAN_SIZE)) { } //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) { SAIN_COLOR = sainColor; IMMUNE_COLOR = immuneColor; DEATH_COLOR = deadColor; INFECTED_COLOR = infectedColor; } public void Propagate(Human[,] previousTerrain, Human[,] nextTerrain, int infectiosity, int deathRate, int cureTime, Random rnd) { Human target; Point location; //target = previousTerrain[Position.X, Position.Y]; LifeTimeCounter++; if (this.State == INFECTED) { InfectedTimeCounter++; if (rnd.Next(0, 100) <= deathRate) { this.State = DEAD; nextTerrain[this.Position.X, this.Position.Y] = this; } if (LifeTimeCounter >= cureTime) { this.State = IMMUNE; } 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)) { //check top left location = new Point(Position.X - 1, Position.Y + 1); target = previousTerrain[location.X, location.Y]; CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd); //check top location = new Point(Position.X, Position.Y + 1); target = previousTerrain[location.X, location.Y]; CheckInfection(nextTerrain, target, infectiosity, deathRate, 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); //check left location = new Point(Position.X - 1, Position.Y); target = previousTerrain[location.X, location.Y]; CheckInfection(nextTerrain, target, infectiosity, deathRate, rnd); //check right location = new Point(Position.X + 1, Position.Y); target = previousTerrain[location.X, location.Y]; CheckInfection(nextTerrain, target, infectiosity, deathRate, 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); //check bottom location = new Point(Position.X, Position.Y - 1); target = previousTerrain[location.X, location.Y]; CheckInfection(nextTerrain, target, infectiosity, deathRate, 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); } } } } private void CheckInfection(Human[,] nextTerrain, Human target, int infectiosity, int deathRate, Random rnd) { if (target.State == SAIN) { if (rnd.Next(0, 100) <= infectiosity) { target.State = INFECTED; } } nextTerrain[target.Position.X, target.Position.Y] = target; } public object Clone() { Human newHuman = new Human(Position,State); newHuman.HumanSize = HumanSize; newHuman.InfectedTimeCounter = InfectedTimeCounter; newHuman.LifeTimeCounter = LifeTimeCounter; return newHuman; } } }