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); }
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); }
public void DeleteSection(SnakeSection snakeSection) { _used[snakeSection.X, snakeSection.Y] = false; _notUsed++; }
public void AddSection(SnakeSection snakeSection) { _used[snakeSection.X, snakeSection.Y] = true; _notUsed--; }