Example #1
0
 public static IGrid PreConfiguredGrid()
 {
     var grid = new Grid(new GridSize(4, 3));
     var cell = new Cell(new Position(2, 2), true);
     grid.MakeCell(cell);
     cell = new Cell(new Position(3, 1), true);
     grid.MakeCell(cell);
     return grid;
 }
Example #2
0
 public ICell GetCell(IGridPosition gridPosition)
 {
     if (gridPosition == null) throw new ArgumentNullException("gridPosition");
     if (!IsValidGridPosition(gridPosition)) throw new ArgumentOutOfRangeException("gridPosition");
     var isCellAlive = IsCellAlive(gridPosition);
     //int getNumberOfAdjacentCells = GetNumberOfAdjacentCells(gridPosition);
     var cell = new Cell(new Position(gridPosition.Row, gridPosition.Column), isCellAlive);
     //cell.Neighbours = getNumberOfAdjacentCells;
     return cell;
 }
 /// <summary>
 /// Toggle the state of a Cell array and update its generation to the current generation
 /// </summary>
 /// <param name="ChangeStatusCell"></param>
 public void UpdateGrid(Cell[] ChangeStatusCell)
 {
     GenerationCount++;
     foreach (Cell cell in ChangeStatusCell)
     {
         cell.IsAlive = !cell.IsAlive;
         cell.Generation = GenerationCount;
     }
 }
        public Cell[] Start(Coordinates[] ListInitialCells, Game game)
        {
            inputGrid = new Grid(inputGrid.GridWidth, inputGrid.GridHeight);
            for (int x = 0; x < inputGrid.GridHeight; x++)
            {
                Row newRow = new Row();

                for (int y = 0; y < inputGrid.GridWidth; y++)
                {
                    Cell newCell = new Cell(new Coordinates(x, y), 0, false, game.StartGame_Id);
                    newCell.type = GridHelper.GetCellType(inputGrid, newCell.Coor);
                    newRow.CellsList.Add(newCell);
                }
                inputGrid.RowsList.Add(newRow);
            }
            foreach (Coordinates coor in ListInitialCells)
            {
                //inputGrid[coor.X, coor.Y].IsAlive = true;
                ListAmendedCell.Add(inputGrid[coor.X, coor.Y]);
            }
            return ListAmendedCell.ToArray();
        }
 public void SaveCell(Cell[] Cellarray)
 {
     DAL dal = new DAL();
     dal.SaveCell(Cellarray);
 }
        public void SaveCell(Cell[] Cellarray)
        {
            try
            {
                foreach (Cell cell in Cellarray)
                {

                    if (cell != null)
                    {
                        repository.CellList.Add(cell);

                    }
                    else throw new ArgumentNullException("The parameter cell cannot be null");
                }
                repository.SaveChanges();

            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
            }
        }
Example #7
0
 public void MakeCellTest()
 {
     var cell = new Cell(new Position(2, 1), true);
     _grid.MakeCell(cell);
     Assert.IsTrue(_grid.GetCurrentCellInfo(cell.Position).Alive);
 }
Example #8
0
 public ICell GetCurrentCellInfo(IPosition position)
 {
     if (position == null) throw new ArgumentNullException("position");
     if (!IsValidPosition(position)) throw new ArgumentOutOfRangeException("position");
     var gridPosition = CreateGridPositionFrom(position);
     var isCellAlive = _gridStorage.IsCellAlive(gridPosition);
     var newCell = new Cell(position, isCellAlive);
     return newCell;
 }