private bool CheckIllness(FormOfLife speciment) { if (speciment is Carnivore) { if (wolf.Count() > (size * size) / 4 || wolf.Count() > (rabbit.Count() * 2)) { return(true); } } else if (speciment is Herbivore) { if (rabbit.Count() > (size * size) / 3 || rabbit.Count() > (flower.Count() * 2)) { return(true); } } else if (speciment is Plant) { if (flower.Count() > ((size * size) / 3)) { return(true); } } return(false); }
void Death(FormOfLife dying) { world[dying.x, dying.y] = '.'; if (dying.symbol == 'w') { wolf.Remove((Carnivore)dying); } else if (dying.symbol == 'r') { rabbit.Remove((Herbivore)dying); } else if (dying.symbol == 177) { flower.Remove((Plant)dying); } }
int Reproduction(FormOfLife reproductor) { Plant prototypeOfFlower; int x = 0, y = 0; int reproduced = 0; int xMode = 0, yMode = 0; if (reproductor.x == (size - 1)) { xMode = 1; } else if (reproductor.x == 0) { xMode = 2; } if (reproductor.y == (size - 1)) { yMode = 1; } else if (reproductor.y == 0) { yMode = 2; } if (reproduced == 0 && (xMode != 1)) { if (world[reproductor.x + 1, reproductor.y] == '.') { x = 1; reproduced = 1; } } if (reproduced == 0 && (xMode != 2)) { if (world[reproductor.x - 1, reproductor.y] == '.') { x = -1; reproduced = 1; } } if (reproduced == 0 && (yMode != 1)) { if (world[reproductor.x, reproductor.y + 1] == '.') { y = 1; reproduced = 1; } } if (reproduced == 0 && (yMode != 2)) { if (world[reproductor.x, reproductor.y - 1] == '.') { y = -1; reproduced = 1; } } if (reproduced == 0 && xMode != 1 && yMode != 1) { if (world[reproductor.x + 1, reproductor.y + 1] == '.') { x = 1; y = 1; reproduced = 1; } } if (reproduced == 0 && xMode != 1 && yMode != 2) { if (world[reproductor.x + 1, reproductor.y - 1] == '.') { x = 1; y = -1; reproduced = 1; } } if (reproduced == 0 && xMode != 2 && yMode != 1) { if (world[reproductor.x - 1, reproductor.y + 1] == '.') { x = -1; y = 1; reproduced = 1; } } if (reproduced == 0 && xMode != 2 && yMode != 2) { if (world[reproductor.x - 1, reproductor.y - 1] == '.') { x = -1; y = -1; reproduced = 1; } } if (reproduced == 1) { prototypeOfFlower = new Plant(1); prototypeOfFlower.symbol = Convert.ToChar(177); prototypeOfFlower.x = reproductor.x + x; prototypeOfFlower.y = reproductor.y + y; prototypeOfFlower.reproductedToday = -1; world[prototypeOfFlower.x, prototypeOfFlower.y] = prototypeOfFlower.symbol; flower.Add(prototypeOfFlower); } return(reproduced); }
double CheckDystans(Animal seeker, FormOfLife target) { return(System.Math.Sqrt((target.x - seeker.x) * (target.x - seeker.x) + (target.y - seeker.y) * (target.y - seeker.y))); }