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

GameListener implemented as inner class

parent fea00718
No related merge requests found
......@@ -40,7 +40,7 @@ public class GameController {
strengthSlider.valueProperty().addListener(this::strenghtChanged);
world.setCannonStrength(strengthSlider.getValue());
world.setGameListener(new GameListenerImpl(this));
world.setGameListener(new GameListenerImpl());
animationTimer.start();
}
......@@ -65,11 +65,21 @@ public class GameController {
world.setCannonStrength(newValue.doubleValue());
}
public void setShoots(int shoots) {
this.shoots.setText(""+shoots);
}
private class GameListenerImpl implements GameListener {
@Override
public void stateChanged(int shoots, int hits) {
GameController.this.shoots.setText("" + shoots);
GameController.this.hits.setText("" + hits);
}
@Override
public void gameOver() {
// TODO Auto-generated method stub
}
public void setHits(int hits) {
this.hits.setText("" + hits);
}
}
package lab;
public class GameListenerImpl implements GameListener {
private final GameController controller;
public GameListenerImpl(GameController controller) {
this.controller = controller;
}
@Override
public void stateChanged(int shoots, int hits) {
controller.setHits(hits);
controller.setShoots(shoots);
}
@Override
public void gameOver() {
// TODO Auto-generated method stub
}
}
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