public void RemoveCell(Cell oldCell) { for (int index = 0; index < CellList.Count; index++) { if (oldCell.XPos == CellList[index].XPos && oldCell.YPos == CellList[index].YPos) { CellList.Remove(CellList[index]); return; } } }
//True = Added Cell, False = Removed Cell public bool AddOrRemoveCell(Cell newCell) { if (newCell.CheckForDuplicates(LivingCells.CellList)) { LivingCells.AddCell(newCell); return true; } else { LivingCells.RemoveCell(newCell); return false; } }
private void pix_Grid_MouseClick(object sender, MouseEventArgs e) { Cell newCell = new Cell(e.X / CellSize, e.Y / CellSize); //Todo: check that this works correctly if (Program.AddOrRemoveCell(newCell)) //If cell is added { DrawCells(Program.LivingCells); } else { if (chk_DrawGrid.Checked) DrawGrid(); else { Gpx.Clear(BackgroundColor); pix_Grid.Refresh(); } DrawCells(Program.LivingCells); } }
private void CheckLeftRight(Cell cell) { if(cell.YPos == YPos) { if (cell.XPos == XPos - 1 || cell.XPos == XPos + 1) NeighborCount++; } }
private void CheckBottom(Cell cell) { if (cell.YPos == YPos + 1) { if (cell.XPos == XPos || cell.XPos == XPos + 1 || cell.XPos == XPos - 1) NeighborCount++; } }
public Cell(Cell existingCell) { XPos = existingCell.XPos; YPos = existingCell.YPos; NeighborCount = existingCell.NeighborCount; }
private bool CheckReproduction(Population currentPop, Cell thisCell) { thisCell.CountNeighbors(currentPop.CellList); if (thisCell.NeighborCount >= Rules.BirthMinimum && thisCell.NeighborCount <= Rules.BirthMaximum) return true; return false; }
public void AddCell(Cell newCell) { CellList.Add(newCell); }
private bool Survive(Cell checkCell, Ruleset rules) { if (checkCell.NeighborCount >= rules.SurvivalMinimum && checkCell.NeighborCount <= rules.SurvivalMaximum) return true; return false; }
private void Nullify(Cell oldCell) { oldCell.XPos = -1; oldCell.YPos = -1; }
private Population MakeNewCells(Population currentPop, Cell thisCell) { Population spawn = new Population(this.Rules); for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { if (CheckReproduction(currentPop, new Cell(thisCell.XPos + x, thisCell.YPos + y))) spawn.AddCell(new Cell(thisCell.XPos + x, thisCell.YPos + y)); } } return spawn; }