Skip to content

Commit 41b8187

Browse files
committed
Added class hierarchies.
1 parent 2029609 commit 41b8187

File tree

6 files changed

+78
-0
lines changed

6 files changed

+78
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.iluwatar;
2+
3+
public class Asteroid extends Meteoroid {
4+
5+
public Asteroid(int left, int top, int right, int bottom) {
6+
super(left, top, right, bottom);
7+
}
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.iluwatar;
2+
3+
public abstract class GameObject extends Rectangle {
4+
5+
public GameObject(int left, int top, int right, int bottom) {
6+
super(left, top, right, bottom);
7+
}
8+
9+
@Override
10+
public String toString() {
11+
return this.getClass().getSimpleName();
12+
}
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.iluwatar;
2+
3+
public class Meteoroid extends GameObject {
4+
5+
public Meteoroid(int left, int top, int right, int bottom) {
6+
super(left, top, right, bottom);
7+
}
8+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.iluwatar;
2+
3+
public class Rectangle {
4+
5+
private int left;
6+
private int top;
7+
private int right;
8+
private int bottom;
9+
10+
public Rectangle(int left, int top, int right, int bottom) {
11+
this.left = left;
12+
this.top = top;
13+
this.right = right;
14+
this.bottom = bottom;
15+
}
16+
17+
public int getLeft() {
18+
return left;
19+
}
20+
public int getTop() {
21+
return top;
22+
}
23+
public int getRight() {
24+
return right;
25+
}
26+
public int getBottom() {
27+
return bottom;
28+
}
29+
30+
boolean intersectsWith(Rectangle r) {
31+
return !(r.getLeft() > getRight() || r.getRight() < getLeft() || r.getTop() > getBottom() || r.getBottom() < getTop());
32+
}
33+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.iluwatar;
2+
3+
public class SpaceStationIss extends SpaceStationMir {
4+
5+
public SpaceStationIss(int left, int top, int right, int bottom) {
6+
super(left, top, right, bottom);
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.iluwatar;
2+
3+
public class SpaceStationMir extends GameObject {
4+
5+
public SpaceStationMir(int left, int top, int right, int bottom) {
6+
super(left, top, right, bottom);
7+
}
8+
}

0 commit comments

Comments
 (0)