Exemple #1
0
 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;
         }
     }
 }
Exemple #2
0
 //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;
     }
 }
Exemple #3
0
        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);
            }
        }
Exemple #4
0
 private void CheckLeftRight(Cell cell)
 {
     if(cell.YPos == YPos)
     {
         if (cell.XPos == XPos - 1 || cell.XPos == XPos + 1)
             NeighborCount++;
     }
 }
Exemple #5
0
 private void CheckBottom(Cell cell)
 {
     if (cell.YPos == YPos + 1)
     {
         if (cell.XPos == XPos || cell.XPos == XPos + 1 || cell.XPos == XPos - 1)
             NeighborCount++;
     }
 }
Exemple #6
0
 public Cell(Cell existingCell)
 {
     XPos = existingCell.XPos;
     YPos = existingCell.YPos;
     NeighborCount = existingCell.NeighborCount;
 }
Exemple #7
0
        private bool CheckReproduction(Population currentPop, Cell thisCell)
        {
            thisCell.CountNeighbors(currentPop.CellList);

            if (thisCell.NeighborCount >= Rules.BirthMinimum && thisCell.NeighborCount <= Rules.BirthMaximum)
                return true;

            return false;
        }
Exemple #8
0
 public void AddCell(Cell newCell)
 {
     CellList.Add(newCell);
 }
Exemple #9
0
        private bool Survive(Cell checkCell, Ruleset rules)
        {
            if (checkCell.NeighborCount >= rules.SurvivalMinimum && checkCell.NeighborCount <= rules.SurvivalMaximum)
                return true;

            return false;
        }
Exemple #10
0
 private void Nullify(Cell oldCell)
 {
     oldCell.XPos = -1;
     oldCell.YPos = -1;
 }
Exemple #11
0
        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;
        }