Completed Double Dispatch example.
This commit is contained in:
@ -8,9 +8,17 @@ public class App {
|
||||
public static void main( String[] args ) {
|
||||
List<GameObject> objects = new ArrayList<>();
|
||||
objects.add(new FlamingAsteroid(0, 0, 5, 5));
|
||||
objects.add(new SpaceStationMir(1, 1, 4, 4));
|
||||
objects.add(new SpaceStationMir(1, 1, 2, 2));
|
||||
objects.add(new Meteoroid(10, 10, 15, 15));
|
||||
objects.add(new SpaceStationIss(12, 11, 14, 15));
|
||||
objects.stream().forEach(o1 -> objects.stream().forEach(o2 -> { if (o1 != o2) System.out.println(String.format("%s -> %s", o1, o2)); } ));
|
||||
objects.add(new SpaceStationIss(12, 12, 14, 14));
|
||||
|
||||
objects.stream().forEach(o -> System.out.println(o));
|
||||
System.out.println("");
|
||||
|
||||
objects.stream().forEach(o1 -> objects.stream().forEach(o2 -> { if (o1 != o2 && o1.intersectsWith(o2)) o1.collision(o2); } ));
|
||||
System.out.println("");
|
||||
|
||||
objects.stream().forEach(o -> System.out.println(o));
|
||||
System.out.println("");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user