public void Grow() { var tail = this.Parts[this.Parts.Count - 1]; var x = tail.Position.X; var y = tail.Position.Y; var direction = tail.Direction; var size = tail.Size; var newX = x + BaseConstants.SquareSize * (-BaseConstants.DX[direction]); var newY = y + BaseConstants.SquareSize * (-BaseConstants.DY[direction]); var newTail = new SnakeSegment(new Position(newX, newY), size, Speed, tail.Direction); this.Parts.Add(newTail); this.OnPropertyChanged("Size"); }
public Snake(Position pos, int size, int speed) : base(pos, size) { this.Speed = speed; this.IsDestroyed = false; this.Parts = new ObservableCollection <SnakeSegment>(); var head = new SnakeHead(pos, BaseConstants.SquareSize, speed); this.Parts.Add(head); this.head = new ObservableCollection <SnakeSegment>() { head }; for (int i = 1; i < size; i++) { var position = new Position(pos.X - i * BaseConstants.SquareSize, pos.Y); var part = new SnakeSegment(position, BaseConstants.SquareSize, this.Speed); this.Parts.Add(part); } }