Skip to content
Snippets Groups Projects
Commit f6d8e3a0 authored by koz01's avatar koz01
Browse files

final solution

parent 23c878be
No related merge requests found
......@@ -113,4 +113,9 @@ public class BulletAnimated implements DrawableSimulable, Collisionable{
speed = initialSpeed;
}
public void setHitListener(HitListener hitListener) {
this.hitListener = hitListener;
System.out.println(hitListener.getClass());
}
}
package lab;
@FunctionalInterface
public interface HitListener {
void hit();
}
......@@ -27,7 +27,9 @@ public class World {
Cannon cannon = new Cannon(this, new Point2D(50, 50), new Point2D(100, 20));
entities = new DrawableSimulable[2 + NUMBER_OF_DRAGONS];
entities[0] = cannon;
entities[1] = new BulletAnimated(this, cannon, new Point2D(30, 60), new Point2D(0, 0), 40);
BulletAnimated bulletAnimated;
entities[1] = bulletAnimated = new BulletAnimated(this, cannon, new Point2D(30, 60), new Point2D(0, 0), 40);
bulletAnimated.setHitListener(this::hit);
Random rnd = new Random();
for (int i = 2; i < entities.length; i++) {
......@@ -118,5 +120,11 @@ public class World {
public void setGameListener(GameListener gameListener) {
this.gameListener = gameListener;
}
private void hit() {
hits++;
gameListener.stateChanged(shoots, hits);
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment