예제 #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;
         }
     }
 }
예제 #2
0
파일: Main.cs 프로젝트: FryDay/CellSharp
 //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;
     }
 }
예제 #3
0
파일: Form1.cs 프로젝트: FryDay/CellSharp
        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);
            }
        }
예제 #4
0
파일: Cell.cs 프로젝트: FryDay/CellSharp
 private void CheckLeftRight(Cell cell)
 {
     if(cell.YPos == YPos)
     {
         if (cell.XPos == XPos - 1 || cell.XPos == XPos + 1)
             NeighborCount++;
     }
 }
예제 #5
0
파일: Cell.cs 프로젝트: FryDay/CellSharp
 private void CheckBottom(Cell cell)
 {
     if (cell.YPos == YPos + 1)
     {
         if (cell.XPos == XPos || cell.XPos == XPos + 1 || cell.XPos == XPos - 1)
             NeighborCount++;
     }
 }
예제 #6
0
파일: Cell.cs 프로젝트: FryDay/CellSharp
 public Cell(Cell existingCell)
 {
     XPos = existingCell.XPos;
     YPos = existingCell.YPos;
     NeighborCount = existingCell.NeighborCount;
 }
예제 #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;
        }
예제 #8
0
 public void AddCell(Cell newCell)
 {
     CellList.Add(newCell);
 }
예제 #9
0
        private bool Survive(Cell checkCell, Ruleset rules)
        {
            if (checkCell.NeighborCount >= rules.SurvivalMinimum && checkCell.NeighborCount <= rules.SurvivalMaximum)
                return true;

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