示例#1
0
        public Field(int size)
        {
            var cells = new Cell[size,size];
            for (int i = 0; i < size; i++)
                for (int j = 0; j < size; j++)
                    cells[i, j] = new Cell(i, j);

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                    Console.Out.Write("{0}", cells[i, j].IsAlive ? 1 : 0);
                Console.Out.WriteLine();
            }
        }
示例#2
0
        public void ChangeCellItem(int aCellIndex)
        {
            lock (GameFieldLocker)
            {
                Life.Cell _selectedCell = this.Game.GameField[aCellIndex];
                if (_selectedCell.CellItem == null)
                {
                    this.Game.InitialCell(aCellIndex);
                }
                else
                {
                    _selectedCell.Clear();
                }
            }

            GameFieldChanged();
            //this.FRunCommand.CanExecute(this);
            //this.FStepCommand.CanExecute(this);
        }
示例#3
0
        //private double FMaxX = 0;
        //public double MaxX
        //{
        //    get { return this.FMaxX; }
        //}

        //private double FMaxY = 0;
        //public double MaxY
        //{
        //    get { return this.FMaxY; }
        //}

        public virtual void DrawItems(GameField aCells)
        {
            DrawingVisual _itemsVisual = new DrawingVisual();

            using (DrawingContext _context = _itemsVisual.RenderOpen())
            {
                for (int i = 0; i < aCells.Count; i++)
                {
                    Life.Cell _cell = aCells[i];
                    if (_cell.CellItem != null)
                    {
                        Point _center = this.ConvertCellIndexToCenter(i);
                        this.DrawItem(_center, _cell.CellItem.Age, _context);
                    }
                }
            }

            this.FItemsVisual.Clear();
            this.FItemsVisual.Add(_itemsVisual);
        }
        private KeyValuePair<Location, Cell> AddCellToWorld(Location touched_location, Cell created_cell)
        {
            if (cell_locations.Exists(x => x.Key.Equals(touched_location)))
              {
            throw new InvalidOperationException("cell location already exists! Something terrible happened.");
              }
              created_cell.When_it_dies = () => this.A_cell_died(touched_location);
              created_cell.When_its_born = () => this.A_cell_was_born(touched_location);

              var cell_location = new KeyValuePair<Location, Cell>(touched_location, created_cell);
              cell_locations.Add(cell_location);
              return cell_location;
        }
示例#5
0
        public void BuildGrid()
        {
            if (Cells != null)
            {
                foreach (var cell in Cells)
                {
                    cell.Display.Dispose();
                }
                Cells = null;
            }
            Cells = new Cell[Width * Height];
            Size cellSize    = new Size(Convert.ToInt32(NumCellWidth.Value), Convert.ToInt32(NumCellHeight.Value));
            int  cellSpacing = 1;
            var  xLoc        = 0;
            var  yLoc        = -Height;

            for (int i = 0; i < Cells.Length; i++)
            {
                Cells[i] = new Cell(cellSize);
            }
            for (int i = 0; i < Cells.Length; i++)
            {
                if (i % Width == 0)
                {
                    xLoc  = 0 + cellSpacing;
                    yLoc += cellSize.Height + (cellSpacing);
                }
                else
                {
                    xLoc += cellSize.Width + cellSpacing;
                }
                var cellLocation = new Point(xLoc, yLoc);
                var cell         = Cells[i];
                cell.Display.Location = cellLocation;
                if (i == 0 || i % Width == 0)
                {
                }
                else
                {
                    //left
                    cell.Siblings[0] = Cells[i - 1];
                }
                if (i > (Width - 1) && i % Width != 0)
                {
                    //has top left
                    var topLeftIndex = i - Width - 1;
                    cell.Siblings[1] = Cells[topLeftIndex];
                }
                if (i > (Width - 1))
                {
                    //has top
                    var topIndex = i - Width;
                    cell.Siblings[2] = Cells[topIndex];
                }
                if (i > (Width - 1) && i % Width != Width - 1)
                {
                    //has top right
                    var topRightIndex = i - Width + 1;
                    cell.Siblings[3] = Cells[topRightIndex];
                }
                if (i != Cells.Length - 1 && i % Width != Width - 1)
                {
                    //has right
                    cell.Siblings[4] = Cells[i + 1];
                }
                if (i % Width != Width - 1 && i < (Width * (Height - 1)))
                {
                    //has bottom right
                    cell.Siblings[5] = Cells[i + Width + 1];
                }
                if (i < (Width * (Height - 1)))
                {
                    //has bottom
                    cell.Siblings[6] = Cells[i + Width];
                }
                if (i < (Width * (Height - 1)) && i % Width != 0)
                {
                    //has bottom left
                    cell.Siblings[7] = Cells[i + Width - 1];
                }
                PanelLife.Controls.Add(cell.Display);
            }
        }