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

solution

parent b96c34b7
Branches 2022_Wed_7-45
No related merge requests found
Pipeline #76 failed with stages
in 0 seconds
......@@ -32,6 +32,7 @@ public class GameController {
}
public void startGame() {
this.world = new World(canvas.getWidth(), canvas.getHeight());
//Draw scene on a separate thread to avoid blocking UI.
animationTimer = new DrawingThread(canvas, world);
......@@ -40,6 +41,14 @@ public class GameController {
strengthSlider.valueProperty().addListener(this::strenghtChanged);
world.setCannonStrength(strengthSlider.getValue());
world.setGameListener(new EmptyGameListener() {
@Override
public void stateChanged(int shoots, int hits) {
GameController.this.setShoots(shoots);
GameController.this.setHits(hits);
}
});
animationTimer.start();
}
......@@ -63,4 +72,18 @@ public class GameController {
, Number oldValue, Number newValue) {
world.setCannonStrength(newValue.doubleValue());
}
private void setHits(int hits) {
this.hits.setText(""+hits);
}
private void setShoots(int shoots) {
this.shoots.setText(""+shoots);
}
}
package lab;
@FunctionalInterface
public interface HitListener {
void hit();
}
......@@ -21,13 +21,24 @@ public class World {
private DrawableSimulable []entities;
public World(double width, double height) {
super();
this.width = width;
this.height = height;
Cannon cannon = new Cannon(this, new Point2D(50, 50), new Point2D(100, 20));
BulletAnimated bullet;
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);
entities[1] = bullet = new BulletAnimated(this, cannon, new Point2D(30, 60), new Point2D(0, 0), 40);
bullet.setHitListener(this::hits);
/*new HitListener() {
@Override
public void hit() {
hits++;
gameListener.stateChanged(shoots, hits);
}
});*/
Random rnd = new Random();
for (int i = 2; i < entities.length; i++) {
......@@ -39,6 +50,11 @@ public class World {
}
}
private void hits() {
hits++;
gameListener.stateChanged(shoots, hits);
}
public Point2D getCanvasPoint(Point2D worldPoint) {
return new Point2D(worldPoint.getX(), height - worldPoint.getY());
}
......
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