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 = (int) getHeight();
        Size size = new Size(1, height);
        return new Rectangle(getPosition(), size);
    }

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

    private double getHeight() {
        Brick lowestBrick = null;

        for(obj:_room.getGobjs().stream().filter(obj -> obj instanceof Brick)) {
            Brick brick = (Brick) obj;
            double brickY = brick.getPosition().Y;
            //Todo get lowest brick position at piont.Y
            int brickWidth = brick.getShape().getSize().getWidth();
            double beamY = getPosition().Y;
            if (beamY >= brickY && beamY <= brickY + brickWidth) {
                if (lowestBrick == null)
                    lowestBrick = brick;
                else if (lowestBrick.getPosition().X > brick.getPosition().X)
                    lowestBrick = brick;
            }
        }
        //Todo return distance from lowest brick to paddle

        return lowestBrick.getPosition().X - getPosition().X;
    }

}

@@ -907,12 +907,19 @@
 for(
+G
 obj
-:
+ obj : 
 _roo
@@ -934,32 +934,27 @@
 js()
-.stream().filter(obj -%3E 
+) %7B%0A            if(
 obj 
@@ -968,18 +968,22 @@
 eof 
+ 
 Brick)
-)
  %7B%0A
+    
     
@@ -1021,32 +1021,36 @@
 bj;%0A            
+   
+ 
 double brickY = 
@@ -1064,32 +1064,36 @@
 etPosition().Y;%0A
+    
             //To
@@ -1140,24 +1140,28 @@
             
+  
+  
 int brickWid
@@ -1200,24 +1200,28 @@
 getWidth();%0A
+    
             
@@ -1260,24 +1260,28 @@
             
+    
 if (beamY %3E=
@@ -1335,24 +1335,28 @@
             
+   
+ 
 if (lowestBr
@@ -1380,32 +1380,36 @@
                 
+    
 lowestBrick = br
@@ -1429,16 +1429,20 @@
         
+ 
+   
 else if 
@@ -1507,32 +1507,36 @@
                 
+    
 lowestBrick = br
@@ -1544,33 +1544,52 @@
 ck;%0A            
-%7D
+    %7D%0A            %7D%0A
 %0A        %7D%0A     

Change getHeight method