Class Ball

  • All Implemented Interfaces:
    IBall

    public class Ball
    extends java.lang.Object
    implements IBall
    This class contains the information about the balls characteristics and behavior
    Author:
    iSchumacher; modified by Gruppe 175 (Moritz Henseleit, Ruben Meyer)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.awt.Color color
      The balls color with default component color
      private Vector2D direction
      The balls direction
      private boolean hitsPaddle
      The balls hit state for paddles; custom implementation
      private Stone hitStone
      The stone which has been hit by the ball
      private boolean isLost
      The balls lost state for upper and lower borders
      private Position position
      The balls position on the playground
    • Constructor Summary

      Constructors 
      Constructor Description
      Ball()
      The constructor of a ball The balls position and direction are initialized here.
    • Field Detail

      • position

        private Position position
        The balls position on the playground
      • direction

        private Vector2D direction
        The balls direction
      • hitsPaddle

        private boolean hitsPaddle
        The balls hit state for paddles; custom implementation
      • isLost

        private boolean isLost
        The balls lost state for upper and lower borders
      • color

        private java.awt.Color color
        The balls color with default component color
      • hitStone

        private Stone hitStone
        The stone which has been hit by the ball
    • Constructor Detail

      • Ball

        public Ball()
        The constructor of a ball The balls position and direction are initialized here.
    • Method Detail

      • getPosition

        public Position getPosition()
        The getter for the balls position
        Specified by:
        getPosition in interface IBall
        Returns:
        position The balls current position
      • getDirection

        public Vector2D getDirection()
        The getter for the balls direction
        Specified by:
        getDirection in interface IBall
        Returns:
        direction The balls current direction
      • getColor

        public java.awt.Color getColor()
        The getter for the balls color
        Returns:
        color The balls current color
      • setColor

        public void setColor​(java.awt.Color color)
        The setter for the balls color
        Parameters:
        color - The balls new color
      • getHitState

        public boolean getHitState()
        The getter for the balls hit state
        Returns:
        hitsPaddle The balls current hit state
      • setHitState

        public void setHitState​(boolean state)
        The setter for the balls hit state
        Parameters:
        state - The balls new hit state
      • updatePosition

        public void updatePosition()
        updates ball position
        Specified by:
        updatePosition in interface IBall
      • reactOnBorder

        public void reactOnBorder()
        Ball reacts to contact with the borders
        Specified by:
        reactOnBorder in interface IBall
      • hitsPaddle

        public boolean hitsPaddle​(Paddle paddle)
        tests whether the ball touches the paddle's hit box.
        Specified by:
        hitsPaddle in interface IBall
        Parameters:
        paddle - paddle which will be tested
        Returns:
        true when ball hits the paddle
      • reflectOnPaddle

        public void reflectOnPaddle​(Paddle paddle)
        Ball got hit by Paddle paddle
        Specified by:
        reflectOnPaddle in interface IBall
        Parameters:
        paddle - hitbox mechanism of paddle
      • hitsStone

        public boolean hitsStone​(java.util.ArrayList<Stone> stones)
        tests whether the ball touches any stone's hit box
        Specified by:
        hitsStone in interface IBall
        Parameters:
        stones - list of stones on the playground
        Returns:
        true if the ball touches a stone
      • getHitStone

        public Stone getHitStone()
        returns the stone which got hit, can be null
        Specified by:
        getHitStone in interface IBall
        Returns:
        the stone which got hit
      • reflectOnStone

        public void reflectOnStone​(Stone stone)
        Ball got hit by Stone stone
        Parameters:
        stone - hitbox mechanism of stone
      • isLost

        public boolean isLost()
        The getter for balls lost state
        Specified by:
        isLost in interface IBall
        Returns:
        balls lost state
      • setLost

        public void setLost​(boolean lost)
        The setter for balls lost state
        Parameters:
        lost - balls lost state
      • resetPosition

        public void resetPosition()
        resets balls position
      • resetDirection

        public void resetDirection()
        resets balls direction