public void start() { resetFood(); SnakeBody head = new SnakeBody(); head.setX(rnd.Next(0, this.Size.Width - 50)); head.setY(rnd.Next(0, this.Size.Height - 50)); head.Direction = rnd.Next(0, 4); snake.Add(head); addBody(); addBody(); reDraw(); }
public void redirect(SnakeBody s, int index) { switch (snake[index - 1].Direction) { case 0: case 1: if (s.getX() == snake[index - 1].getX()) { s.Direction = snake[index - 1].Direction; } break; case 2: case 3: if (s.getY() == snake[index - 1].getY()) { s.Direction = snake[index - 1].Direction; } break; } }