added projectile
This commit is contained in:
@@ -2,6 +2,9 @@ package worms.facade;
|
|||||||
|
|
||||||
import worms.internal.gui.game.IActionHandler;
|
import worms.internal.gui.game.IActionHandler;
|
||||||
import worms.model.*;
|
import worms.model.*;
|
||||||
|
import worms.model.Food;
|
||||||
|
import worms.model.Projectile;
|
||||||
|
import worms.model.Worm;
|
||||||
import worms.programs.IProgramFactory;
|
import worms.programs.IProgramFactory;
|
||||||
import worms.util.IllegalNameException;
|
import worms.util.IllegalNameException;
|
||||||
import worms.util.ModelException;
|
import worms.util.ModelException;
|
||||||
@@ -9,7 +12,6 @@ import worms.util.Coordinate;
|
|||||||
import worms.util.MustNotImplementException;
|
import worms.util.MustNotImplementException;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -294,7 +296,7 @@ public class Facade implements IFacade {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isTerminated(Projectile projectile) throws ModelException {
|
public boolean isTerminated(Projectile projectile) throws ModelException {
|
||||||
return false;
|
return projectile.isTerminated();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -304,7 +306,7 @@ public class Facade implements IFacade {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public double getOrientation(Projectile projectile) throws ModelException {
|
public double getOrientation(Projectile projectile) throws ModelException {
|
||||||
return 0;
|
return projectile.getOrientation();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -316,7 +318,7 @@ public class Facade implements IFacade {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public double[] getLocation(Projectile projectile) throws ModelException {
|
public double[] getLocation(Projectile projectile) throws ModelException {
|
||||||
return new double[0];
|
return projectile.getLocationArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -326,7 +328,7 @@ public class Facade implements IFacade {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public double getRadius(Projectile projectile) {
|
public double getRadius(Projectile projectile) {
|
||||||
return 0;
|
return projectile.getRadius();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -336,7 +338,7 @@ public class Facade implements IFacade {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getNbHitPoints(Projectile projectile) throws ModelException {
|
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;
|
package worms.model;
|
||||||
|
|
||||||
import worms.util.Coordinate;
|
|
||||||
|
|
||||||
public class Food extends GameObject {
|
public class Food extends GameObject {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -24,7 +24,7 @@ public abstract class GameObject {
|
|||||||
* @post ...
|
* @post ...
|
||||||
* |setRadius(radius)
|
* |setRadius(radius)
|
||||||
*/
|
*/
|
||||||
GameObject(World world, double[] location, double radius) {
|
protected GameObject(World world, double[] location, double radius) {
|
||||||
setWorld(world);
|
setWorld(world);
|
||||||
world.add(this);
|
world.add(this);
|
||||||
setLocation(location);
|
setLocation(location);
|
||||||
@@ -163,7 +163,7 @@ public abstract class GameObject {
|
|||||||
/**
|
/**
|
||||||
* This variable contains the radius of the game object
|
* This variable contains the radius of the game object
|
||||||
*/
|
*/
|
||||||
double radius;
|
protected double radius;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the radius of the game object
|
* Return the radius of the game object
|
||||||
@@ -181,7 +181,7 @@ public abstract class GameObject {
|
|||||||
* @post ...
|
* @post ...
|
||||||
* |this.radius = radius
|
* |this.radius = radius
|
||||||
*/
|
*/
|
||||||
void setRadius(double radius) {
|
protected void setRadius(double radius) {
|
||||||
if (!canHaveAsRadius(radius)) throw new IllegalArgumentException();
|
if (!canHaveAsRadius(radius)) throw new IllegalArgumentException();
|
||||||
this.radius = radius;
|
this.radius = radius;
|
||||||
}
|
}
|
||||||
@@ -215,7 +215,7 @@ public abstract class GameObject {
|
|||||||
* | !(location.getY() - radius < 0 &&
|
* | !(location.getY() - radius < 0 &&
|
||||||
* | !getWorld().isPassable(location))
|
* | !getWorld().isPassable(location))
|
||||||
*/
|
*/
|
||||||
boolean isValidLocation(Coordinate location) {
|
protected boolean isValidLocation(Coordinate location) {
|
||||||
double radius = getRadius();
|
double radius = getRadius();
|
||||||
|
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
@@ -235,7 +235,7 @@ public abstract class GameObject {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
double mass;
|
protected double mass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@@ -1,53 +1,46 @@
|
|||||||
package worms.model;
|
package worms.model;
|
||||||
|
|
||||||
public class Projectile extends GameObject {
|
public abstract 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) {
|
private static final int rho = 7800;
|
||||||
|
|
||||||
|
|
||||||
|
protected Projectile (World world, double location[], double mass, double force, double orientation) {
|
||||||
super(world, location, calcRadius(mass));
|
super(world, location, calcRadius(mass));
|
||||||
setHitPoints(hitpoints);
|
super.mass = mass;
|
||||||
setMass(mass);
|
this.force = force;
|
||||||
setForce(force);
|
this.orientation = orientation;
|
||||||
|
this.hitPoints = getRandomHitPoints();
|
||||||
this.type = type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static double calcRadius(double mass) {
|
public static double calcRadius(double mass) {
|
||||||
return Math.cbrt(mass/(4/3*Math.PI*rho));
|
return Math.pow(((mass / 1000.0 / rho) * (3.0 / (4.0 * Math.PI))), 1.0 / 3.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHitPoints(double value) {
|
public double getForce() {
|
||||||
this.hitpoints = value;
|
return this.force;
|
||||||
|
}
|
||||||
|
private final double force;
|
||||||
|
|
||||||
|
|
||||||
|
protected int hitPoints;
|
||||||
|
|
||||||
|
protected abstract int getRandomHitPoints();
|
||||||
|
|
||||||
|
public int getHitPoints() {
|
||||||
|
return this.hitPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRandomHitPoints() {
|
protected abstract void setHitPoints(int value) throws IllegalArgumentException;
|
||||||
|
|
||||||
}
|
public void incrementHitPoints(int value) {
|
||||||
|
setHitPoints(this.hitPoints + value);
|
||||||
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) {
|
private final double orientation;
|
||||||
this.force = force;
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Type {
|
public double getOrientation() {
|
||||||
RIFLE,
|
return orientation;
|
||||||
BAZOOKA;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
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();
|
item2.terminate();
|
||||||
}
|
}
|
||||||
else if (item1 instanceof Projectile && item2 instanceof Projectile) {
|
else if (item1 instanceof Projectile && item2 instanceof Projectile) {
|
||||||
((Projectile) item1).increaseHitPoints(2);
|
// ((Projectile) item1).increaseHitPoints(2);
|
||||||
((Projectile) item2).increaseHitPoints(2);
|
// ((Projectile) item2).increaseHitPoints(2);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
|
@@ -1242,6 +1242,7 @@ public class Worm extends GameObject {
|
|||||||
|
|
||||||
// region firing and projectiles
|
// region firing and projectiles
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
|
|
||||||
private double[] locationProj;
|
private double[] locationProj;
|
||||||
private double massProj;
|
private double massProj;
|
||||||
private long hitpointsProj;
|
private long hitpointsProj;
|
||||||
@@ -1250,9 +1251,9 @@ public class Worm extends GameObject {
|
|||||||
public void fire() {
|
public void fire() {
|
||||||
if (getActionPoints() >= 30 && getWorld() != null) {
|
if (getActionPoints() >= 30 && getWorld() != null) {
|
||||||
Random r = new Random();
|
Random r = new Random();
|
||||||
int random = r.nextInt((1 - 0) + 1);
|
int random = r.nextInt((1) + 1);
|
||||||
locationProj[0] = cos(getOrientation())*getRadius();
|
locationProj[0] = cos(getOrientation()) * getRadius();
|
||||||
locationProj[1] = sin(getOrientation())*getRadius();
|
locationProj[1] = sin(getOrientation()) * getRadius();
|
||||||
if (random == 0) {
|
if (random == 0) {
|
||||||
propertiesRifle();
|
propertiesRifle();
|
||||||
decreaseActionPoints(10);
|
decreaseActionPoints(10);
|
||||||
@@ -1261,7 +1262,7 @@ public class Worm extends GameObject {
|
|||||||
propertiesBazooka();
|
propertiesBazooka();
|
||||||
decreaseActionPoints(25);
|
decreaseActionPoints(25);
|
||||||
}
|
}
|
||||||
new Projectile(this.getWorld(), locationProj, massProj, hitpointsProj, forceProj);
|
//new Projectile(this.getWorld(), locationProj, massProj, hitpointsProj, forceProj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -12,7 +12,6 @@ import org.junit.*;
|
|||||||
import worms.facade.Facade;
|
import worms.facade.Facade;
|
||||||
import worms.facade.IFacade;
|
import worms.facade.IFacade;
|
||||||
import worms.internal.gui.game.IActionHandler;
|
import worms.internal.gui.game.IActionHandler;
|
||||||
import worms.programs.IProgramFactory;
|
|
||||||
import worms.programs.ProgramFactory;
|
import worms.programs.ProgramFactory;
|
||||||
import worms.programs.ProgramParser;
|
import worms.programs.ProgramParser;
|
||||||
import worms.util.*;
|
import worms.util.*;
|
||||||
|
@@ -7,7 +7,6 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import worms.facade.Facade;
|
import worms.facade.Facade;
|
||||||
import worms.facade.IFacade;
|
import worms.facade.IFacade;
|
||||||
import worms.model.Worm;
|
|
||||||
|
|
||||||
public class PartialPart2FacadeTest {
|
public class PartialPart2FacadeTest {
|
||||||
|
|
||||||
|
@@ -57,6 +57,7 @@ Eten kost 8 action points als niet genoeg -> niet eten
|
|||||||
- hitpoints bepalen impact op doelwit
|
- hitpoints bepalen impact op doelwit
|
||||||
- mogen gedeeltelijk of volledig op impassable
|
- mogen gedeeltelijk of volledig op impassable
|
||||||
- **NIET** adjacent
|
- **NIET** adjacent
|
||||||
|
- radius hangt van massa af
|
||||||
|
|
||||||
|
|
||||||
#### locatie
|
#### locatie
|
||||||
|
Reference in New Issue
Block a user