Example #1
0
 public CellStatus ValidateSection(SnakeSection snakeSection)
 {
     if (snakeSection.X < 0 || snakeSection.Y < 0 || snakeSection.X >= FieldWidth || snakeSection.Y >= FieldHeight)
     {
         return(CellStatus.Border);
     }
     if (snakeSection.X == AppleX && snakeSection.Y == AppleY)
     {
         return(CellStatus.Apple);
     }
     if (_used[snakeSection.X, snakeSection.Y])
     {
         return(CellStatus.Border);
     }
     return(CellStatus.Empty);
 }
Example #2
0
        public bool Move()
        {
            SnakeSection newSection = _sections.First.Value.GetNeighbor(_direction);
            CellStatus   status     = _engine.ValidateSection(newSection);

            if (status == CellStatus.Border)
            {
                return(false);
            }
            if (status == CellStatus.Apple)
            {
                _engine.MoveApple();
            }
            else
            {
                _engine.DeleteSection(_sections.Last.Value);
                _sections.RemoveLast();
            }
            _engine.AddSection(newSection);
            _sections.AddFirst(newSection);
            return(true);
        }
Example #3
0
 public void DeleteSection(SnakeSection snakeSection)
 {
     _used[snakeSection.X, snakeSection.Y] = false;
     _notUsed++;
 }
Example #4
0
 public void AddSection(SnakeSection snakeSection)
 {
     _used[snakeSection.X, snakeSection.Y] = true;
     _notUsed--;
 }