Added iteration logic.
This commit is contained in:
parent
41b818771e
commit
fba664ba49
@ -1,7 +1,16 @@
|
||||
package com.iluwatar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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 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)); } ));
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
package com.iluwatar;
|
||||
|
||||
public class Asteroid extends Meteoroid {
|
||||
|
||||
public Asteroid(int left, int top, int right, int bottom) {
|
||||
super(left, top, right, bottom);
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.iluwatar;
|
||||
|
||||
public class FlamingAsteroid extends Meteoroid {
|
||||
|
||||
public FlamingAsteroid(int left, int top, int right, int bottom) {
|
||||
super(left, top, right, bottom);
|
||||
setOnFire(true);
|
||||
}
|
||||
}
|
@ -2,12 +2,32 @@ package com.iluwatar;
|
||||
|
||||
public abstract class GameObject extends Rectangle {
|
||||
|
||||
private boolean damaged;
|
||||
private boolean onFire;
|
||||
|
||||
public GameObject(int left, int top, int right, int bottom) {
|
||||
super(left, top, right, bottom);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getClass().getSimpleName();
|
||||
return String.format("%s at %s damaged=%b onFire=%b", this.getClass().getSimpleName(),
|
||||
super.toString(), isDamaged(), isOnFire());
|
||||
}
|
||||
|
||||
public boolean isOnFire() {
|
||||
return onFire;
|
||||
}
|
||||
|
||||
public void setOnFire(boolean onFire) {
|
||||
this.onFire = onFire;
|
||||
}
|
||||
|
||||
public boolean isDamaged() {
|
||||
return damaged;
|
||||
}
|
||||
|
||||
public void setDamaged(boolean damaged) {
|
||||
this.damaged = damaged;
|
||||
}
|
||||
}
|
||||
|
@ -30,4 +30,9 @@ public class Rectangle {
|
||||
boolean intersectsWith(Rectangle r) {
|
||||
return !(r.getLeft() > getRight() || r.getRight() < getLeft() || r.getTop() > getBottom() || r.getBottom() < getTop());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("[%d,%d,%d,%d]", getLeft(), getTop(), getRight(), getBottom());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user