added abstract class

This commit is contained in:
2018-04-07 20:47:32 +02:00
parent 7ffe8803c2
commit d2fac7e27b
3 changed files with 64 additions and 4 deletions

View 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;
}

View File

@@ -127,7 +127,7 @@ public class World {
if (location[0] / lengthX >= getMap()[0].length || location[0] < 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)];
}

View File

@@ -1,7 +1,6 @@
package worms.model;
import be.kuleuven.cs.som.annotate.*;
import jdk.jshell.spi.ExecutionControl;
import worms.util.Coordinate;
import worms.util.IllegalNameException;
@@ -239,8 +238,6 @@ public class Worm {
// endregion
// region Shape mass/radius
//===================================================================================