added castSpell
This commit is contained in:
@@ -34,6 +34,9 @@ public class Food extends GameObject {
|
|||||||
public void poison() {
|
public void poison() {
|
||||||
this.poisonous = true;
|
this.poisonous = true;
|
||||||
}
|
}
|
||||||
|
public void heal() {
|
||||||
|
this.poisonous = false;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean poisonous = false;
|
private boolean poisonous = false;
|
||||||
}
|
}
|
||||||
|
@@ -4,12 +4,15 @@ public class Projectile extends GameObject {
|
|||||||
private static double rho = 7800;
|
private static double rho = 7800;
|
||||||
private double hitpoints;
|
private double hitpoints;
|
||||||
private double force;
|
private double force;
|
||||||
|
private Type type;
|
||||||
|
|
||||||
public Projectile(World world, double[] location, double mass, double hitpoints, double force) {
|
public Projectile(World world, double[] location, double mass, double hitpoints, double force, Projectile.Type type) {
|
||||||
super(world, location, calcRadius(mass));
|
super(world, location, calcRadius(mass));
|
||||||
setHitPoints(hitpoints);
|
setHitPoints(hitpoints);
|
||||||
setMass(mass);
|
setMass(mass);
|
||||||
setForce(force);
|
setForce(force);
|
||||||
|
|
||||||
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double calcRadius(double mass) {
|
public static double calcRadius(double mass) {
|
||||||
@@ -20,6 +23,21 @@ public class Projectile extends GameObject {
|
|||||||
this.hitpoints = 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) {
|
public void setMass(double mass) {
|
||||||
this.mass = mass;
|
this.mass = mass;
|
||||||
}
|
}
|
||||||
@@ -28,5 +46,8 @@ public class Projectile extends GameObject {
|
|||||||
this.force = force;
|
this.force = force;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
RIFLE,
|
||||||
|
BAZOOKA;
|
||||||
|
}
|
||||||
}
|
}
|
@@ -527,25 +527,52 @@ public class World {
|
|||||||
|
|
||||||
|
|
||||||
if (item1 instanceof Worm && item2 instanceof Worm) {
|
if (item1 instanceof Worm && item2 instanceof Worm) {
|
||||||
System.out.println("test");
|
if (((Worm) item1).getTeam().getName().equals(((Worm) item2).getTeam().getName())) {
|
||||||
|
long hitpoints = (long) Math.floor((((Worm) item1).getHitPoints() + ((Worm) item2).getHitPoints()) / 2);
|
||||||
|
((Worm) item1).setHitPoints(hitpoints);
|
||||||
|
((Worm) item2).setHitPoints(hitpoints);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Worm lgWorm = (Worm) item1;
|
||||||
|
Worm smWorm = (Worm) item2;
|
||||||
|
|
||||||
|
if (item1.getRadius() < item2.getRadius()) {
|
||||||
|
lgWorm = (Worm) item2;
|
||||||
|
smWorm = (Worm) item1;
|
||||||
|
}
|
||||||
|
|
||||||
|
long lgHitPoints = lgWorm.getHitPoints();
|
||||||
|
if (lgHitPoints < 5) {
|
||||||
|
lgWorm.setHitPoints(0);
|
||||||
|
smWorm.incrementHitPoints(lgHitPoints);
|
||||||
|
} else {
|
||||||
|
smWorm.incrementHitPoints(5);
|
||||||
|
lgWorm.decreaseHitPoints(5);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (item1 instanceof Worm && item2 instanceof Food ||
|
else if (item1 instanceof Worm && item2 instanceof Food) {
|
||||||
item1 instanceof Food && item2 instanceof Worm) {
|
((Worm) item1).eat((Food) item2, false);
|
||||||
System.out.println("test");
|
|
||||||
}
|
}
|
||||||
else if (item1 instanceof Worm && item2 instanceof Projectile ||
|
else if (item1 instanceof Worm && item2 instanceof Projectile ||
|
||||||
item1 instanceof Projectile && item2 instanceof Worm) {
|
item1 instanceof Projectile && item2 instanceof Worm) {
|
||||||
System.out.println("test");
|
// TODO hit by projectile, projectile gets random hit points
|
||||||
}
|
}
|
||||||
else if (item1 instanceof Food && item2 instanceof Food) {
|
else if (item1 instanceof Food && item2 instanceof Food) {
|
||||||
System.out.println("test");
|
if (((Food) item1).isPoisonous()) ((Food) item1).heal();
|
||||||
|
else ((Food) item1).poison();
|
||||||
|
|
||||||
|
if (((Food) item2).isPoisonous()) ((Food) item2).heal();
|
||||||
|
else ((Food) item2).poison();
|
||||||
}
|
}
|
||||||
else if (item1 instanceof Food && item2 instanceof Projectile ||
|
else if (item1 instanceof Food && item2 instanceof Projectile ||
|
||||||
item1 instanceof Projectile && item2 instanceof Food) {
|
item1 instanceof Projectile && item2 instanceof Food) {
|
||||||
System.out.println("test");
|
item1.terminate();
|
||||||
|
item2.terminate();
|
||||||
}
|
}
|
||||||
else if (item1 instanceof Projectile && item2 instanceof Projectile) {
|
else if (item1 instanceof Projectile && item2 instanceof Projectile) {
|
||||||
System.out.println("test");
|
((Projectile) item1).increaseHitPoints(2);
|
||||||
|
((Projectile) item2).increaseHitPoints(2);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
|
@@ -981,7 +981,7 @@ public class Worm extends GameObject {
|
|||||||
* | new.getHitPoints() == hitpoints
|
* | new.getHitPoints() == hitpoints
|
||||||
*/
|
*/
|
||||||
@Raw
|
@Raw
|
||||||
private void setHitPoints(long hitPoints) {
|
public void setHitPoints(long hitPoints) {
|
||||||
if (hitPoints <= 0)
|
if (hitPoints <= 0)
|
||||||
terminate();
|
terminate();
|
||||||
this.hitPoints = hitPoints;
|
this.hitPoints = hitPoints;
|
||||||
@@ -1016,6 +1016,8 @@ public class Worm extends GameObject {
|
|||||||
setHitPoints(getHitPoints() + value);
|
setHitPoints(getHitPoints() + value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
@@ -1129,6 +1131,10 @@ public class Worm extends GameObject {
|
|||||||
// ===================================================================================
|
// ===================================================================================
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
public void eat(Food food) {
|
||||||
|
this.eat(food, true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The worm eats food and grows.
|
* The worm eats food and grows.
|
||||||
*
|
*
|
||||||
@@ -1150,9 +1156,9 @@ public class Worm extends GameObject {
|
|||||||
* @post Let the worm eat if necessary.
|
* @post Let the worm eat if necessary.
|
||||||
* |checkEat()
|
* |checkEat()
|
||||||
*/
|
*/
|
||||||
public void eat(Food food) {
|
public void eat(Food food, boolean terminate) {
|
||||||
|
|
||||||
food.terminate();
|
if (terminate) food.terminate();
|
||||||
|
|
||||||
double radius = getRadius();
|
double radius = getRadius();
|
||||||
double changeRadius = radius * 0.1;
|
double changeRadius = radius * 0.1;
|
||||||
@@ -1231,6 +1237,9 @@ public class Worm extends GameObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// region firing and projectiles
|
// region firing and projectiles
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
private double[] locationProj;
|
private double[] locationProj;
|
||||||
|
Reference in New Issue
Block a user