added projectile
This commit is contained in:
@@ -2,6 +2,9 @@ package worms.facade;
|
||||
|
||||
import worms.internal.gui.game.IActionHandler;
|
||||
import worms.model.*;
|
||||
import worms.model.Food;
|
||||
import worms.model.Projectile;
|
||||
import worms.model.Worm;
|
||||
import worms.programs.IProgramFactory;
|
||||
import worms.util.IllegalNameException;
|
||||
import worms.util.ModelException;
|
||||
@@ -9,7 +12,6 @@ import worms.util.Coordinate;
|
||||
import worms.util.MustNotImplementException;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -294,7 +296,7 @@ public class Facade implements IFacade {
|
||||
*/
|
||||
@Override
|
||||
public boolean isTerminated(Projectile projectile) throws ModelException {
|
||||
return false;
|
||||
return projectile.isTerminated();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -304,7 +306,7 @@ public class Facade implements IFacade {
|
||||
*/
|
||||
@Override
|
||||
public double getOrientation(Projectile projectile) throws ModelException {
|
||||
return 0;
|
||||
return projectile.getOrientation();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -316,7 +318,7 @@ public class Facade implements IFacade {
|
||||
*/
|
||||
@Override
|
||||
public double[] getLocation(Projectile projectile) throws ModelException {
|
||||
return new double[0];
|
||||
return projectile.getLocationArray();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -326,7 +328,7 @@ public class Facade implements IFacade {
|
||||
*/
|
||||
@Override
|
||||
public double getRadius(Projectile projectile) {
|
||||
return 0;
|
||||
return projectile.getRadius();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -336,7 +338,7 @@ public class Facade implements IFacade {
|
||||
*/
|
||||
@Override
|
||||
public int getNbHitPoints(Projectile projectile) throws ModelException {
|
||||
return 0;
|
||||
return projectile.getHitPoints();
|
||||
}
|
||||
|
||||
/**
|
||||
|
26
OGP1718-Worms/src/worms/model/Bazooka.java
Normal file
26
OGP1718-Worms/src/worms/model/Bazooka.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package worms.model;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class Bazooka extends Projectile {
|
||||
protected Bazooka(World world, double[] location, double force, double orientation) {
|
||||
super(world, location, 300, force, orientation);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getRandomHitPoints() {
|
||||
return ThreadLocalRandom.current().nextInt(15) / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setHitPoints(int value) throws IllegalArgumentException {
|
||||
if (value > 7 || value % 2 != 1) throw new IllegalArgumentException();
|
||||
super.hitPoints = value;
|
||||
}
|
||||
|
||||
public static double calcForce(double actionPoints) {
|
||||
double hp = 2.5 + actionPoints / 8.0;
|
||||
if (hp > 9.5) return 9.5;
|
||||
return hp;
|
||||
}
|
||||
}
|
@@ -1,7 +1,5 @@
|
||||
package worms.model;
|
||||
|
||||
import worms.util.Coordinate;
|
||||
|
||||
public class Food extends GameObject {
|
||||
|
||||
/**
|
||||
|
@@ -24,7 +24,7 @@ public abstract class GameObject {
|
||||
* @post ...
|
||||
* |setRadius(radius)
|
||||
*/
|
||||
GameObject(World world, double[] location, double radius) {
|
||||
protected GameObject(World world, double[] location, double radius) {
|
||||
setWorld(world);
|
||||
world.add(this);
|
||||
setLocation(location);
|
||||
@@ -163,7 +163,7 @@ public abstract class GameObject {
|
||||
/**
|
||||
* This variable contains the radius of the game object
|
||||
*/
|
||||
double radius;
|
||||
protected double radius;
|
||||
|
||||
/**
|
||||
* Return the radius of the game object
|
||||
@@ -181,7 +181,7 @@ public abstract class GameObject {
|
||||
* @post ...
|
||||
* |this.radius = radius
|
||||
*/
|
||||
void setRadius(double radius) {
|
||||
protected void setRadius(double radius) {
|
||||
if (!canHaveAsRadius(radius)) throw new IllegalArgumentException();
|
||||
this.radius = radius;
|
||||
}
|
||||
@@ -215,7 +215,7 @@ public abstract class GameObject {
|
||||
* | !(location.getY() - radius < 0 &&
|
||||
* | !getWorld().isPassable(location))
|
||||
*/
|
||||
boolean isValidLocation(Coordinate location) {
|
||||
protected boolean isValidLocation(Coordinate location) {
|
||||
double radius = getRadius();
|
||||
|
||||
if (world == null) {
|
||||
@@ -235,7 +235,7 @@ public abstract class GameObject {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
double mass;
|
||||
protected double mass;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@@ -1,53 +1,46 @@
|
||||
package worms.model;
|
||||
|
||||
public class Projectile extends GameObject {
|
||||
private static double rho = 7800;
|
||||
private double hitpoints;
|
||||
private double force;
|
||||
private Type type;
|
||||
|
||||
public Projectile(World world, double[] location, double mass, double hitpoints, double force, Projectile.Type type) {
|
||||
public abstract class Projectile extends GameObject {
|
||||
|
||||
private static final int rho = 7800;
|
||||
|
||||
|
||||
protected Projectile (World world, double location[], double mass, double force, double orientation) {
|
||||
super(world, location, calcRadius(mass));
|
||||
setHitPoints(hitpoints);
|
||||
setMass(mass);
|
||||
setForce(force);
|
||||
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public static double calcRadius(double mass) {
|
||||
return Math.cbrt(mass/(4/3*Math.PI*rho));
|
||||
}
|
||||
|
||||
public void setHitPoints(double value) {
|
||||
this.hitpoints = value;
|
||||
}
|
||||
|
||||
public void setRandomHitPoints() {
|
||||
|
||||
}
|
||||
|
||||
public double getHitPoints() {
|
||||
return this.hitpoints;
|
||||
}
|
||||
|
||||
public void increaseHitPoints(double value) {
|
||||
|
||||
this.hitpoints += value;
|
||||
if (this.type == Type.RIFLE && this.hitpoints > 10) this.hitpoints = 10;
|
||||
else if (this.type == Type.BAZOOKA && this.hitpoints > 7) this.hitpoints = 7;
|
||||
}
|
||||
|
||||
public void setMass(double mass) {
|
||||
this.mass = mass;
|
||||
}
|
||||
|
||||
public void setForce(double force) {
|
||||
super.mass = mass;
|
||||
this.force = force;
|
||||
this.orientation = orientation;
|
||||
this.hitPoints = getRandomHitPoints();
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
RIFLE,
|
||||
BAZOOKA;
|
||||
|
||||
public static double calcRadius(double mass) {
|
||||
return Math.pow(((mass / 1000.0 / rho) * (3.0 / (4.0 * Math.PI))), 1.0 / 3.0);
|
||||
}
|
||||
|
||||
public double getForce() {
|
||||
return this.force;
|
||||
}
|
||||
private final double force;
|
||||
|
||||
|
||||
protected int hitPoints;
|
||||
|
||||
protected abstract int getRandomHitPoints();
|
||||
|
||||
public int getHitPoints() {
|
||||
return this.hitPoints;
|
||||
}
|
||||
|
||||
protected abstract void setHitPoints(int value) throws IllegalArgumentException;
|
||||
|
||||
public void incrementHitPoints(int value) {
|
||||
setHitPoints(this.hitPoints + value);
|
||||
}
|
||||
|
||||
private final double orientation;
|
||||
|
||||
public double getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
}
|
23
OGP1718-Worms/src/worms/model/Rifle.java
Normal file
23
OGP1718-Worms/src/worms/model/Rifle.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package worms.model;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class Rifle extends Projectile {
|
||||
|
||||
|
||||
public Rifle(World world, double[] location, double orientation) {
|
||||
super(world, location, 10, 1.5, orientation);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getRandomHitPoints() {
|
||||
return ThreadLocalRandom.current().nextInt(6) * 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setHitPoints(int value) throws IllegalArgumentException {
|
||||
if (value > 10 || value % 2 != 0) throw new IllegalArgumentException();
|
||||
super.hitPoints = value;
|
||||
}
|
||||
|
||||
}
|
@@ -571,8 +571,8 @@ public class World {
|
||||
item2.terminate();
|
||||
}
|
||||
else if (item1 instanceof Projectile && item2 instanceof Projectile) {
|
||||
((Projectile) item1).increaseHitPoints(2);
|
||||
((Projectile) item2).increaseHitPoints(2);
|
||||
// ((Projectile) item1).increaseHitPoints(2);
|
||||
// ((Projectile) item2).increaseHitPoints(2);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException();
|
||||
|
@@ -1242,6 +1242,7 @@ public class Worm extends GameObject {
|
||||
|
||||
// region firing and projectiles
|
||||
//===================================================================================
|
||||
|
||||
private double[] locationProj;
|
||||
private double massProj;
|
||||
private long hitpointsProj;
|
||||
@@ -1250,9 +1251,9 @@ public class Worm extends GameObject {
|
||||
public void fire() {
|
||||
if (getActionPoints() >= 30 && getWorld() != null) {
|
||||
Random r = new Random();
|
||||
int random = r.nextInt((1 - 0) + 1);
|
||||
locationProj[0] = cos(getOrientation())*getRadius();
|
||||
locationProj[1] = sin(getOrientation())*getRadius();
|
||||
int random = r.nextInt((1) + 1);
|
||||
locationProj[0] = cos(getOrientation()) * getRadius();
|
||||
locationProj[1] = sin(getOrientation()) * getRadius();
|
||||
if (random == 0) {
|
||||
propertiesRifle();
|
||||
decreaseActionPoints(10);
|
||||
@@ -1261,7 +1262,7 @@ public class Worm extends GameObject {
|
||||
propertiesBazooka();
|
||||
decreaseActionPoints(25);
|
||||
}
|
||||
new Projectile(this.getWorld(), locationProj, massProj, hitpointsProj, forceProj);
|
||||
//new Projectile(this.getWorld(), locationProj, massProj, hitpointsProj, forceProj);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user