public void Grow() { double newTailX = SnakeParts[SnakeParts.Count - 1].Position.X; double newTailY = SnakeParts[SnakeParts.Count - 1].Position.Y; switch (SnakeDirection) { case SnakeDirection.Left: newTailX -= Constants.SNAKESQUARESIZE; break; case SnakeDirection.Right: newTailX += Constants.SNAKESQUARESIZE; break; case SnakeDirection.Up: newTailY -= Constants.SNAKESQUARESIZE; break; case SnakeDirection.Down: newTailY += Constants.SNAKESQUARESIZE; break; } //Adding new tail to the snake to simulate its growth ISnakePart newTail = Factory.CreateSnakePart(); newTail.Position = new Point(newTailX, newTailY); SnakeParts.Add(newTail); }
private void GenerateSnakePart() { Point last = new Point(Canvas.GetLeft(SnakeParts.Last()), Canvas.GetTop(SnakeParts.Last())); Image snakePart = new Image { Source = new BitmapImage(new Uri(_colorPath)), Height = _height, Width = _height }; SnakeParts.Add(snakePart); switch (SnakeDriection) { case Direction.Right: last.X -= 20; break; case Direction.Left: last.X += 20; break; case Direction.Up: last.Y += 20; break; case Direction.Down: last.Y -= 20; break; } Canvas.SetTop(snakePart, last.Y); Canvas.SetLeft(snakePart, last.X); _playField.Children.Add(snakePart); }
public void GenerateSnake() { Image snakeHead = new Image { Source = new BitmapImage(new Uri(_colorPath)) }; snakeHead.Height = _height; snakeHead.Width = _height; SnakeParts.Add(snakeHead); _playField.Children.Add(snakeHead); }
//Constructor for new snake used at the beginning of each game public SnakeObject() { //Snake initially always consists of 3 tiles, the tile at position 0 is snakes head //Snake is initially positioned in the center of game area SnakeParts.Add(new SnakePart(isHead: true) { Position = new Point(Constants.SNAKESQUARESIZE * 11, Constants.SNAKESQUARESIZE * 10), }); SnakeParts.Add(new SnakePart() { Position = new Point(Constants.SNAKESQUARESIZE * 10, Constants.SNAKESQUARESIZE * 10) }); SnakeParts.Add(new SnakePart() { Position = new Point(Constants.SNAKESQUARESIZE * 9, Constants.SNAKESQUARESIZE * 10) }); }