public GrassCell[] GetOptionalCells(GrassCell headLocation) { var allCells = GrassCells.GetDirations(headLocation.RowIndex, headLocation.ColumnIndex).ToArray(); var aliveCells = allCells.Where(x => x.IsAlive).ToArray(); return(aliveCells.Any() ? aliveCells : allCells); }
public GrassBoard(Params currParams, int rowLength, int columnLength) { Params = currParams; RowLength = rowLength; ColumnLength = columnLength; GrassCells = new GrassCell[RowLength][]; for (int i = 0; i < RowLength; i++) { GrassCells[i] = new GrassCell[ColumnLength]; for (int j = 0; j < ColumnLength; j++) { GrassCells[i][j] = new GrassCell(Params, i, j); } } }
public void MoveSnake(GrassCell cell) { AddNewCell(cell); CheckGrassEaten(cell.EnteredBySnake()); if (GrassCellsEaten <= Params.SnakeCellsForGrow) { Locations.Dequeue(); } else { GrassCellsEaten = 0; } if (Locations.Count > Params.SnakeLengthToStop && TurnsHasNotEaten == Params.SnakeTurnsToShrink) { Locations.Dequeue(); TurnsHasNotEaten = 0; } }
private GrassCell GetRandomGrassCell(GrassCell headLocation) { var grassCells = GrassBoard.GetOptionalCells(headLocation).ToArray(); return(grassCells[_random.Next(grassCells.Length)]); }
public void AddNewCell(GrassCell cell) { HeadLocation = cell; Locations.Enqueue(cell); }