Пример #1
0
        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);
        }
Пример #2
0
        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);
                }
            }
        }
Пример #3
0
        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;
            }
        }
Пример #4
0
        private GrassCell GetRandomGrassCell(GrassCell headLocation)
        {
            var grassCells = GrassBoard.GetOptionalCells(headLocation).ToArray();

            return(grassCells[_random.Next(grassCells.Length)]);
        }
Пример #5
0
 public void AddNewCell(GrassCell cell)
 {
     HeadLocation = cell;
     Locations.Enqueue(cell);
 }