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

import ge.edu.freeuni.sdp.arkanoid.model.geometry.Point;
import ge.edu.freeuni.sdp.arkanoid.model.geometry.Rectangle;
import ge.edu.freeuni.sdp.arkanoid.model.geometry.Size;

public class Beam extends Gobj<Rectangle> {

    private boolean _isAlive;
    private Room _room;

    Beam(Point position, Room room) {
        super(position);
        _isAlive = true;
        _room = room;
    }

    @Override
    public GobjKind getKind() {
        return GobjKind.Beam;
    }

    public void interact(Gobj other) {

    }

    @Override
    public Rectangle getShape() {
        int height = getHeight();
        Size size = new Size(1, height);
        return new Rectangle(getPosition(), size);
    }

    @Override
    public boolean isAlive() {
        return _isAlive;
    }

    private int getHeight() {
        _room.getGobjs().stream().filter(obj -> obj instanceof Brick).forEach(obj -> {
            Brick brick = (Brick) obj;
            Point brickPosition = brick.getPosition();
            //Todo get lowest brick position at piont.Y
        });
        //Todo return distance from lowest brick to paddle
        return 10;
    }

}

@@ -843,24 +843,58 @@
 tHeight() %7B%0A
+        Brick lowestBrick = null;%0A
         _roo
@@ -1019,18 +1019,16 @@
         
-Po
 int bric
@@ -1028,24 +1028,17 @@
 nt brick
-Position
+Y
  = brick
@@ -1051,16 +1051,18 @@
 sition()
+.Y
 ;%0A      
@@ -1111,16 +1111,406 @@
 piont.Y%0A
+            int brickWidth = brick.getShape().getSize().getWidth();%0A            int beamY = getPosition().Y;%0A            if (beamY %3E= brickY && beamY %3C= brickY + brickWidth)%7B%0A                if (lowestBrick == null)%0A                    lowestBrick = brick;%0A                else if (lowestBrick.getPosition().X %3E brick.getPosition().X)%0A                    lowestBrick = brick;%0A            %7D%0A
         
@@ -1572,16 +1572,17 @@
  paddle%0A
+%0A
         
@@ -1592,10 +1592,53 @@
 urn 
-10
+lowestBrick.getPosition().X - getPosition().X
 ;%0A  

Add Beam height from paddle to lowest brick