public void HandleEndOfRound() { for (int x = 0; x < maxX; x++) { for (int y = 0; y < maxY; y++) { Pixel CurrentCell = returnCell(x, y); CurrentCell.hasMovedThisRound = false; if (CurrentCell.isAlive) { ISpecies currentCreature = CurrentCell.returnCreature(); currentCreature.EndOfTurnHealthChange(); if (currentCreature.health < 0) { CurrentCell.removeOldCreature(); continue; } if (currentCreature.health > currentCreature.SpawningHealth) { currentCreature.health -= currentCreature.SpawningHealth / 2; //Spawn new creature int[,] spawningPosition = getNewMove(CurrentCell, true); Pixel spawningCell = returnCell(spawningPosition[0, 0], spawningPosition[0, 1]); if (spawningCell != CurrentCell) // If no spawning space available, by default returns same cell. Quick check to prevent this { CurrentCell.hasMovedThisRound = true; if (currentCreature.GetType() == typeof(Species.Predator)) { spawningCell.addNewCreature(new Predator()); } else { spawningCell.addNewCreature(new Prey()); } } } } } } }