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

Implement GameLister as common class.

parent 32ed8925
No related merge requests found
...@@ -40,6 +40,7 @@ public class GameController { ...@@ -40,6 +40,7 @@ public class GameController {
strengthSlider.valueProperty().addListener(this::strenghtChanged); strengthSlider.valueProperty().addListener(this::strenghtChanged);
world.setCannonStrength(strengthSlider.getValue()); world.setCannonStrength(strengthSlider.getValue());
world.setGameListener(new GameListenerImpl(this));
animationTimer.start(); animationTimer.start();
} }
...@@ -63,4 +64,12 @@ public class GameController { ...@@ -63,4 +64,12 @@ public class GameController {
, Number oldValue, Number newValue) { , Number oldValue, Number newValue) {
world.setCannonStrength(newValue.doubleValue()); world.setCannonStrength(newValue.doubleValue());
} }
public void setShoots(int shoots) {
this.shoots.setText(""+shoots);
}
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
}
}
...@@ -115,4 +115,8 @@ public class World { ...@@ -115,4 +115,8 @@ public class World {
} }
} }
public void setGameListener(GameListenerImpl gameListener) {
this.gameListener = gameListener;
}
} }
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