Class Lane


  • public class Lane
    extends java.lang.Object
    Represents a lane on the course.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.ArrayList<Obstacle> obstacles  
    • Constructor Summary

      Constructors 
      Constructor Description
      Lane​(int leftBoundary, int rightBoundary)
      Creates a lane instance.
      Lane​(int leftBoundary, int rightBoundary, int obstacleLimit)
      Creates a lane instance.
    • Field Detail

      • obstacles

        protected java.util.ArrayList<Obstacle> obstacles
    • Constructor Detail

      • Lane

        public Lane​(int leftBoundary,
                    int rightBoundary)
        Creates a lane instance.
        Parameters:
        leftBoundary - X-position for the left boundary of the lane.
        rightBoundary - X-position for the right boundary of the lane.
      • Lane

        public Lane​(int leftBoundary,
                    int rightBoundary,
                    int obstacleLimit)
        Creates a lane instance.
        Parameters:
        leftBoundary - X-position for the left boundary of the lane.
        rightBoundary - X-position for the right boundary of the lane.
        obstacleLimit - Limit for the number of obstacles in the lane.
    • Method Detail

      • SpawnObstacle

        public void SpawnObstacle​(int x,
                                  int y,
                                  java.lang.String obstacleType)

        Spawns obstacle in the lane.

        Spawns specified obstacle in the lane. Checks that the obstacle limit hasn't been reached, if not checks the obstacle type for Goose or Log and instantiates it as the corresponding obstacle, with the correct texture. Then adds it to the Lane's obstacle list.

        Parameters:
        x - X-position for the obstacle spawn location.
        y - Y-position for the obstacle spawn location.
        obstacleType - Obstacle type.
      • RemoveObstacle

        public void RemoveObstacle​(Obstacle obstacle)

        Removes obstacle from obstacle list.

        Obstacle should be removed upon collision with boat or leaving the course. area.

        Parameters:
        obstacle - Obstacle to be removed.
      • getLeftBoundary

        public int getLeftBoundary()
        Returns:
        Int representing the x-position of the lane's left boundary.
      • getRightBoundary

        public int getRightBoundary()
        Returns:
        Int representing the x-position of the lane's right boundary.