Module project.pong

Class Ball

java.lang.Object
project.pong.model.Ball
All Implemented Interfaces:
Runnable, Resizable

public class Ball extends Object implements Resizable, Runnable
The Ball class represents the ball in the Pong game.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Ball(int x, int y, double speed, double directionX, double directionY, double increaseSpeed)
    Constructs a Ball object with the specified parameters.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Reverses the direction of movement along the x-axis.
    void
    Reverses the direction of movement along the y-axis.
    double
    Gets the base speed of the ball.
    double
    Gets the direction of movement along the x-axis.
    double
    Gets the direction of movement along the y-axis.
    double
    Gets the speed increase factor of the ball.
    double
    Gets the speed of the ball.
    double
    Gets the width of the ball.
    double
    Gets the x-coordinate of the ball.
    double
    Gets the y-coordinate of the ball.
    void
    Increases the speed of the ball.
    void
    Moves the ball based on its current speed and direction.
    void
    Resets the speed of the ball to its base speed.
    void
    resizeHeight(double factor)
    Resizes the height of the ball.
    void
    resizeWidth(double factor)
    Resizes the width of the ball.
    void
    run()
    Runs the thread for the ball's movement.
    void
    setBaseSpeed(double baseSpeed)
    Sets the base speed of the ball.
    void
    setDirectionX(double directionX)
    Sets the direction of movement along the x-axis.
    void
    setDirectionY(double directionY)
    Sets the direction of movement along the y-axis.
    void
    setIncreaseSpeed(double increaseSpeed)
    Sets the speed increase factor of the ball.
    void
    setSpeed(double speed)
    Sets the speed of the ball.
    void
    setX(double x)
    Sets the x-coordinate of the ball.
    void
    setY(double y)
    Sets the y-coordinate of the ball.
    void
    Stops the ball movement thread.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Ball

      public Ball(int x, int y, double speed, double directionX, double directionY, double increaseSpeed)
      Constructs a Ball object with the specified parameters.
      Parameters:
      x - The x-coordinate of the ball's initial position.
      y - The y-coordinate of the ball's initial position.
      speed - The speed of the ball.
      directionX - The direction of movement along the x-axis.
      directionY - The direction of movement along the y-axis.
      increaseSpeed - The speed increase factor.
  • Method Details

    • getBaseSpeed

      public double getBaseSpeed()
      Gets the base speed of the ball.
      Returns:
      The base speed of the ball.
    • setBaseSpeed

      public void setBaseSpeed(double baseSpeed)
      Sets the base speed of the ball.
      Parameters:
      baseSpeed - The base speed to set.
    • reset

      public void reset()
      Resets the speed of the ball to its base speed.
    • getX

      public double getX()
      Gets the x-coordinate of the ball.
      Returns:
      The x-coordinate of the ball.
    • setX

      public void setX(double x)
      Sets the x-coordinate of the ball.
      Parameters:
      x - The x-coordinate to set.
    • getY

      public double getY()
      Gets the y-coordinate of the ball.
      Returns:
      The y-coordinate of the ball.
    • setY

      public void setY(double y)
      Sets the y-coordinate of the ball.
      Parameters:
      y - The y-coordinate to set.
    • getSpeed

      public double getSpeed()
      Gets the speed of the ball.
      Returns:
      The speed of the ball.
    • setSpeed

      public void setSpeed(double speed)
      Sets the speed of the ball.
      Parameters:
      speed - The speed to set.
    • getDirectionX

      public double getDirectionX()
      Gets the direction of movement along the x-axis.
      Returns:
      The direction of movement along the x-axis.
    • setDirectionX

      public void setDirectionX(double directionX)
      Sets the direction of movement along the x-axis.
      Parameters:
      directionX - The direction to set.
    • getDirectionY

      public double getDirectionY()
      Gets the direction of movement along the y-axis.
      Returns:
      The direction of movement along the y-axis.
    • setDirectionY

      public void setDirectionY(double directionY)
      Sets the direction of movement along the y-axis.
      Parameters:
      directionY - The direction to set.
    • move

      public void move()
      Moves the ball based on its current speed and direction.
    • changeDirectionX

      public void changeDirectionX()
      Reverses the direction of movement along the x-axis.
    • changeDirectionY

      public void changeDirectionY()
      Reverses the direction of movement along the y-axis.
    • getIncreaseSpeed

      public double getIncreaseSpeed()
      Gets the speed increase factor of the ball.
      Returns:
      The speed increase factor of the ball.
    • setIncreaseSpeed

      public void setIncreaseSpeed(double increaseSpeed)
      Sets the speed increase factor of the ball.
      Parameters:
      increaseSpeed - The speed increase factor to set.
    • increaseSpeed

      public void increaseSpeed()
      Increases the speed of the ball.
    • getWidth

      public double getWidth()
      Gets the width of the ball.
      Returns:
      The width of the ball.
    • resizeWidth

      public void resizeWidth(double factor)
      Resizes the width of the ball.
      Specified by:
      resizeWidth in interface Resizable
      Parameters:
      factor - The factor by which to resize the width.
    • resizeHeight

      public void resizeHeight(double factor)
      Resizes the height of the ball.
      Specified by:
      resizeHeight in interface Resizable
      Parameters:
      factor - The factor by which to resize the height.
    • run

      public void run()
      Runs the thread for the ball's movement.
      Specified by:
      run in interface Runnable
    • stop

      public void stop()
      Stops the ball movement thread.