added abstract class
This commit is contained in:
63
OGP1718-Worms/src/worms/model/GameObject.java
Normal file
63
OGP1718-Worms/src/worms/model/GameObject.java
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
package worms.model;
|
||||||
|
|
||||||
|
import worms.util.Coordinate;
|
||||||
|
|
||||||
|
import static java.lang.Math.PI;
|
||||||
|
import static java.lang.Math.pow;
|
||||||
|
import static java.lang.Math.round;
|
||||||
|
|
||||||
|
public abstract class GameObject {
|
||||||
|
|
||||||
|
public GameObject(World world, Coordinate location, double radius) {
|
||||||
|
|
||||||
|
this.world = world;
|
||||||
|
this.location = location;
|
||||||
|
this.radius = radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
private World world;
|
||||||
|
|
||||||
|
public World getWorld() {
|
||||||
|
return this.world;
|
||||||
|
}
|
||||||
|
public void setWorld(World world) {
|
||||||
|
this.world = world;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isTerminated() {
|
||||||
|
return this.terminated;
|
||||||
|
}
|
||||||
|
public void terminate() {
|
||||||
|
this.terminated = true;
|
||||||
|
}
|
||||||
|
private boolean terminated = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private Coordinate location;
|
||||||
|
public double[] getLocation() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setLocation(Coordinate location) {
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double radius;
|
||||||
|
public double getRadius(){
|
||||||
|
return this.radius;
|
||||||
|
}
|
||||||
|
abstract void setRadius();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private double mass;
|
||||||
|
public double getMass() {
|
||||||
|
return this.mass;
|
||||||
|
}
|
||||||
|
private void setMass() {
|
||||||
|
this.mass = (double) round(rho * (4.0 / 3.0 * PI * pow(radius, 3)));
|
||||||
|
}
|
||||||
|
private final double rho = 0;
|
||||||
|
}
|
@@ -127,7 +127,7 @@ public class World {
|
|||||||
|
|
||||||
if (location[0] / lengthX >= getMap()[0].length || location[0] < 0.0 ||
|
if (location[0] / lengthX >= getMap()[0].length || location[0] < 0.0 ||
|
||||||
location[1] / lengthY >= getMap().length || location[1] < 0.0) {
|
location[1] / lengthY >= getMap().length || location[1] < 0.0) {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
return this.map[(int) Math.floor(location[1] / lengthY)][(int) Math.floor(location[0] / lengthX)];
|
return this.map[(int) Math.floor(location[1] / lengthY)][(int) Math.floor(location[0] / lengthX)];
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
package worms.model;
|
package worms.model;
|
||||||
|
|
||||||
import be.kuleuven.cs.som.annotate.*;
|
import be.kuleuven.cs.som.annotate.*;
|
||||||
import jdk.jshell.spi.ExecutionControl;
|
|
||||||
import worms.util.Coordinate;
|
import worms.util.Coordinate;
|
||||||
import worms.util.IllegalNameException;
|
import worms.util.IllegalNameException;
|
||||||
|
|
||||||
@@ -239,8 +238,6 @@ public class Worm {
|
|||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// region Shape mass/radius
|
// region Shape mass/radius
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user