void OnTapGestureTapped(object sender, EventArgs args) { LifeCell lifeCell = (LifeCell)sender; lifeCell.IsAlive ^= true; lifeGrid.SetStatus(lifeCell.Col, lifeCell.Row, lifeCell.IsAlive); }
private void ProcessRules(LifeCell lifeCell) { var result = false; if (lifeCell.IsAlive && lifeCell.Neighbours < 2) { result = false; } if (lifeCell.IsAlive && lifeCell.Neighbours > 3) { result = false; } if (lifeCell.IsAlive && (lifeCell.Neighbours == 2 || lifeCell.Neighbours == 3)) { result = true; } if (!lifeCell.IsAlive && lifeCell.Neighbours == 3) { result = true; } lifeCell.IsAlive = result; }
void UpdateLives() { foreach (View view in absoluteLayout.Children) { LifeCell lifeCell = view as LifeCell; lifeCell.IsAlive = lifeGrid.IsAlive(lifeCell.Col, lifeCell.Row); } }
public IEnumerable <LifeCell> Get(LifeCell cell) { var area = Surroundigs(cell.Coordinate); var result = Cells.AliveCells.Where(x => area.Where(y => y.X == x.Coordinate.X && y.Y == x.Coordinate.Y).Count() != 0).Take(Rule.CountNeibours); return(result); }
public void AddItem(int x, int y) { var newcell = new LifeCell() { Coordinate = new Point(x, y) }; Algoritm.Now.AliveCells.Add(newcell); }
//TODO: //Constructor public LifeGrid(int rowsNum, int columnNum) { grid = new LifeCell[rowsNum, columnNum]; width = columnNum; height = rowsNum; for(int i = 0; i < rowsNum; i++) { for(int j = 0; j < columnNum; j++) { grid[i, j] = new LifeCell(); grid[i, j].X = i; grid[i, j].Y = j; } } }
public IEnumerable <LifeCell> GetPotential(LifeCell cell) { var result = new List <LifeCell>(); var area = Surroundigs(cell.Coordinate); var notlive = area.Where(x => Cells.AliveCells.Where(y => y.Coordinate.X == x.X && x.Y == y.Coordinate.Y).Count() == 0); foreach (var point in notlive) { result.Add(new LifeCell() { Coordinate = point }); } return(result); }
void UpdateLayout() { // TODO: Put up Activity Indicator int count = rows * cols; System.Diagnostics.Debug.WriteLine("Count = " + count); // Remove unneeded LifeCell children while (absoluteLayout.Children.Count > count) { absoluteLayout.Children.RemoveAt(0); } // Possibly add more LifeCell children while (absoluteLayout.Children.Count < count) { LifeCell lifeCell = new LifeCell(); lifeCell.Tapped += OnTapGestureTapped; absoluteLayout.Children.Add(lifeCell); } int index = 0; for (int x = 0; x < cols; x++) { for (int y = 0; y < rows; y++) { LifeCell lifeCell = lifeCell = (LifeCell)absoluteLayout.Children[index]; lifeCell.Col = x; lifeCell.Row = y; lifeCell.IsAlive = lifeGrid.IsAlive(x, y); Rectangle rect = new Rectangle(x * cellSize + xMargin + CellSpacing / 2, y * cellSize + yMargin + CellSpacing / 2, cellSize - CellSpacing, cellSize - CellSpacing); AbsoluteLayout.SetLayoutBounds(lifeCell, rect); index++; } } }