private void PlaceFood() { TwoDPoint fp = RandomPoint(_emptyTiles); _field[fp.X, fp.Y] = Tile.food; _emptyTiles.Remove(fp); _food.Add(fp); }
public override bool Equals(object obj) { if (obj == null || obj.GetType() != this.GetType()) { return(false); } // If parameter cannot be cast to Point return false. TwoDPoint p = (TwoDPoint)obj; return(X == p.X && Y == p.Y); }
private void PlaceSnake() { _nextPos = RandomPoint(_emptyTiles); _snake = new Snake(_nextPos); DrawSnakeHeadOnTiles(); for (int i = 0; i < SnakeStartingLength - 1; i++) { _nextPos = RandomPoint(GetAdjacent(_nextPos)); _snake.Grow(_nextPos); DrawSnakeHeadOnTiles(); } }
void MoveTo(TwoDPoint p) { if (_food.Contains(p)) { _snake.Grow(p); _score++; _food.Remove(p); } else { _emptyTiles.Remove(p); _field[_snake.Tail.X, _snake.Tail.Y] = Tile.empty; _emptyTiles.Add(_snake.Tail); _snake.Move(p); } _field[p.X, p.Y] = Tile.snake; }
private bool isInvalid(TwoDPoint p) { return(p.X < 0 || p.Y < 0 || p.X >= Width || p.Y >= Height); }
private IEnumerable <TwoDPoint> GetAdjacent(TwoDPoint point) { return(_emptyTiles.Where(p => p.ManhattanDistance(point) == 1)); }
//public void UnGrow() //{ // _points.RemoveAt(_points.Count - 1); //} public void Move(TwoDPoint p) { _points.Dequeue(); _points.Enqueue(p); }
public void Grow(TwoDPoint p) { _points.Enqueue(p); }
public Snake(int x, int y) { TwoDPoint starting = new TwoDPoint(x, y); _points.Enqueue(starting); }
public Snake(TwoDPoint starting) { _points.Enqueue(starting); }
//readonly List<TwoDPoint> _points = new List<TwoDPoint>(); public Snake() { TwoDPoint p = new TwoDPoint(0, 0); _points.Enqueue(p); }
public bool Equals(TwoDPoint p) { return(X == p.X && Y == p.Y); }
internal int ManhattanDistance(TwoDPoint p) { return(Math.Abs(_x - p.X) + Math.Abs(_y - p.Y)); }