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{ ...@@ -113,4 +113,9 @@ public class BulletAnimated implements DrawableSimulable, Collisionable{
speed = initialSpeed; speed = initialSpeed;
} }
public void setHitListener(HitListener hitListener) {
this.hitListener = hitListener;
System.out.println(hitListener.getClass());
}
} }
package lab; package lab;
@FunctionalInterface
public interface HitListener { public interface HitListener {
void hit(); void hit();
} }
...@@ -27,7 +27,9 @@ public class World { ...@@ -27,7 +27,9 @@ public class World {
Cannon cannon = new Cannon(this, new Point2D(50, 50), new Point2D(100, 20)); Cannon cannon = new Cannon(this, new Point2D(50, 50), new Point2D(100, 20));
entities = new DrawableSimulable[2 + NUMBER_OF_DRAGONS]; entities = new DrawableSimulable[2 + NUMBER_OF_DRAGONS];
entities[0] = cannon; 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(); Random rnd = new Random();
for (int i = 2; i < entities.length; i++) { for (int i = 2; i < entities.length; i++) {
...@@ -118,5 +120,11 @@ public class World { ...@@ -118,5 +120,11 @@ public class World {
public void setGameListener(GameListener gameListener) { public void setGameListener(GameListener gameListener) {
this.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