package ge.edu.freeuni.sdp.arkanoid.model;

import ge.edu.freeuni.sdp.arkanoid.SoundPlayer;
import ge.edu.freeuni.sdp.arkanoid.model.geometry.Point;

public class ExpandCapsule extends Capsule {

    ExpandCapsule(Point position, Room room) {
        super(position, room);
    }

    public void interact(Gobj other) {
        super.interact(other);
        if (other instanceof Paddle) {
            Paddle oldPaddle = (Paddle) other;
            int oldPaddleWidth = oldPaddle.getShape().getSize().getWidth();
            int expandedPaddleWidth = getExpandedPaddleWidth();
            Point newPosition = getNewPosition(other.getPosition(), oldPaddleWidth, expandedPaddleWidth);
            Paddle newPaddle = new ExpandedPaddle(newPosition);
            oldPaddle.exchange(newPaddle);
            SoundPlayer.getInstance().play(SoundPlayer.EXTEND);
        }
    }

    private Point getNewPosition(Point oldPosition, int oldPaddleWidth, int expandedPaddleWidth) {
        Point newPosition = new Point(oldPosition);

        if (oldPosition.X <= 0) {
            newPosition.X += (expandedPaddleWidth - oldPaddleWidth) / 2;
        } else if (oldPosition.X + oldPaddleWidth >= Configuration.getInstance().getSize().getWidth()) {
            newPosition.X -= (expandedPaddleWidth - oldPaddleWidth) / 2;
        }

        return newPosition;
    }

    private int getExpandedPaddleWidth() {
        return new ExpandedPaddle(null).getShape().getSize().getWidth();
    }
}

@@ -446,1028 +446,184 @@
     
-int oldPaddleWidth = oldPaddle.getShape().getSize().getWidth();%0A            int expandedPaddleWidth = getExpandedPaddleWidth();%0A            Point newPosition = getNewPosition(other.getPosition(), oldPaddleWidth, expandedPaddleWidth);%0A            Paddle newPaddle = new ExpandedPaddle(newPosition);%0A            oldPaddle.exchange(newPaddle);%0A            SoundPlayer.getInstance().play(SoundPlayer.EXTEND);%0A        %7D%0A    %7D%0A%0A    private Point getNewPosition(Point oldPosition, int oldPaddleWidth, int expandedPaddleWidth) %7B%0A        Point newPosition = new Point(oldPosition);%0A%0A        if (oldPosition.X %3C= 0) %7B%0A            newPosition.X += (expandedPaddleWidth - oldPaddleWidth) / 2;%0A        %7D else if (oldPosition.X + oldPaddleWidth %3E= Configuration.getInstance().getSize().getWidth()) %7B%0A            newPosition.X -= (expandedPaddleWidth - oldPaddleWidth) / 2;%0A        %7D%0A%0A        return newPosition;%0A    %7D%0A%0A    private int getExpandedPaddleWidth() %7B%0A        return new ExpandedPaddle(null).getShape().getSize().getWidth();
+Paddle newPaddle = new ExpandedPaddle(other.getPosition());%0A            oldPaddle.exchange(newPaddle);%0A            SoundPlayer.getInstance().play(SoundPlayer.EXTEND);%0A        %7D
 %0A   

Clean up code