예제 #1
0
        void OnTapGestureTapped(object sender, EventArgs args)
        {
            LifeCell lifeCell = (LifeCell)sender;

            lifeCell.IsAlive ^= true;
            lifeGrid.SetStatus(lifeCell.Col, lifeCell.Row, lifeCell.IsAlive);
        }
예제 #2
0
        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;
        }
예제 #3
0
 void UpdateLives()
 {
     foreach (View view in absoluteLayout.Children)
     {
         LifeCell lifeCell = view as LifeCell;
         lifeCell.IsAlive = lifeGrid.IsAlive(lifeCell.Col, lifeCell.Row);
     }
 }
예제 #4
0
        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);
        }
예제 #5
0
        public void AddItem(int x, int y)
        {
            var newcell = new LifeCell()
            {
                Coordinate = new Point(x, y)
            };

            Algoritm.Now.AliveCells.Add(newcell);
        }
예제 #6
0
        //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;
                }
            }
        }
예제 #7
0
        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);
        }
예제 #8
0
        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++;
                }
            }
        }