docs: update double dispatch

This commit is contained in:
Ilkka Seppälä
2024-05-25 15:51:33 +03:00
parent 4e0382ca9f
commit 30cb525c04
2 changed files with 52 additions and 12 deletions
@@ -56,6 +56,7 @@ public class App {
*/
public static void main(String[] args) {
// initialize game objects and print their status
LOGGER.info("Init objects and print their status");
var objects = List.of(
new FlamingAsteroid(0, 0, 5, 5),
new SpaceStationMir(1, 1, 2, 2),
@@ -63,18 +64,17 @@ public class App {
new SpaceStationIss(12, 12, 14, 14)
);
objects.forEach(o -> LOGGER.info(o.toString()));
LOGGER.info("");
// collision check
LOGGER.info("Collision check");
objects.forEach(o1 -> objects.forEach(o2 -> {
if (o1 != o2 && o1.intersectsWith(o2)) {
o1.collision(o2);
}
}));
LOGGER.info("");
// output eventual object statuses
LOGGER.info("Print object status after collision checks");
objects.forEach(o -> LOGGER.info(o.toString()));
LOGGER.info("");
}
}