Example #1
0
        //Methods
        private async Task CreateCells()
        {
            Cells.Clear();
            _SourceAndSink.Clear();
            var x     = new CellViewmodel[_NumberOfRows, _NumberOfColumns];
            var cells = new List <CellViewmodel>();
            await Task.Run(() =>
            {
                for (int c = 0; c < _NumberOfColumns; c++)
                {
                    for (int r = 0; r < _NumberOfRows; r++)
                    {
                        x[r, c] = new CellViewmodel();
                        if (c > 0)
                        {
                            //add left neighbour cell
                            x[r, c].AddNeighbour(x[r, c - 1]);
                        }
                        if (r > 0)
                        {
                            //add upper neighbour
                            x[r, c].AddNeighbour(x[r - 1, c]);
                        }
                        cells.Add(x[r, c]);
                    }
                }
            });

            Cells = new ObservableCollection <CellViewmodel>(cells);
            RaisePropertyChanged(nameof(Cells));
            ShowField = true;
        }
Example #2
0
 public void AddNeighbour(CellViewmodel cellViewmodel)
 {
     if (!Neighbours.Contains(cellViewmodel))
     {
         Neighbours.Add(cellViewmodel);
     }
     if (!cellViewmodel.Neighbours.Contains(this))
     {
         cellViewmodel.Neighbours.Add(this);
     }
 }