fixes
This commit is contained in:
@@ -239,7 +239,7 @@ public class Worm extends GameObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the given radius is a valid radius for the worm
|
* Check whether the given radius is a valid radius for the worm
|
||||||
*
|
*
|
||||||
* @param radius
|
* @param radius
|
||||||
* the radius to check
|
* the radius to check
|
||||||
* @return True if and only if the radius is bigger then the minimum radius
|
* @return True if and only if the radius is bigger then the minimum radius
|
||||||
@@ -653,12 +653,13 @@ public class Worm extends GameObject {
|
|||||||
|
|
||||||
if (!canJump())
|
if (!canJump())
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
|
double distance = jumpDistance(this.jumpVelocity());
|
||||||
|
Coordinate newLocation = Coordinate.create( getLocation().getX() + distance, getLocation().getY());
|
||||||
|
|
||||||
setLocation(Coordinate.create( getLocation().getX() + jumpDistance(this.jumpVelocity()), getLocation().getY()));
|
if (getWorld().isAdjacent(newLocation, getRadius()) && canHaveAsJumpDistance(distance)) {
|
||||||
setActionPoints(0);
|
if (!isValidLocation(newLocation)) terminate();
|
||||||
|
setLocation(newLocation);
|
||||||
if (!getWorld().isAdjacent(getLocation(), getRadius())) {
|
setActionPoints(0);
|
||||||
fall();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -726,6 +727,16 @@ public class Worm extends GameObject {
|
|||||||
return (pow(v, 2) * sin(2 * getOrientation())) / G;
|
return (pow(v, 2) * sin(2 * getOrientation())) / G;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param distance
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean canHaveAsJumpDistance(double distance) {
|
||||||
|
|
||||||
|
return Math.abs(distance) >= getRadius();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the velocity of the jump
|
* Return the velocity of the jump
|
||||||
*
|
*
|
||||||
@@ -741,25 +752,33 @@ public class Worm extends GameObject {
|
|||||||
return force / getMass() * FORCE_TIME;
|
return force / getMass() * FORCE_TIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fight(Worm worm1, Worm... worm2) {
|
/**
|
||||||
for (Worm wormB: worm2) {
|
*
|
||||||
Worm attackedWorm;
|
* @param newLocation
|
||||||
Worm attacker;
|
* @param oldLocation
|
||||||
Random rand = new Random();
|
* @param worm1
|
||||||
int coin = rand.nextInt(2);
|
* @param worm2
|
||||||
if (coin == 1) {
|
*/
|
||||||
attackedWorm = worm1;
|
public void fight(Coordinate newLocation, Coordinate oldLocation, Worm worm1, Worm... worm2) {
|
||||||
attacker = wormB;
|
if (! worm1.isTerminated() && newLocation != oldLocation) {
|
||||||
|
for (Worm wormB: worm2) {
|
||||||
|
Worm attackedWorm;
|
||||||
|
Worm attacker;
|
||||||
|
Random rand = new Random();
|
||||||
|
int coin = rand.nextInt(2);
|
||||||
|
if (coin == 1) {
|
||||||
|
attackedWorm = worm1;
|
||||||
|
attacker = wormB;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
attackedWorm = wormB;
|
||||||
|
attacker = worm1;
|
||||||
|
}
|
||||||
|
double N = 10 * ceil((attacker.getRadius())/(attackedWorm.getRadius()));
|
||||||
|
long loseAttackedWorm = (long) rand.nextInt((((int) N) - 1) + 1) + 1;
|
||||||
|
attackedWorm.decreaseHitPoints(loseAttackedWorm);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
attackedWorm = wormB;
|
|
||||||
attacker = worm1;
|
|
||||||
}
|
|
||||||
double N = 10 * ceil((attacker.getRadius())/(attackedWorm.getRadius()));
|
|
||||||
long loseAttackedWorm = (long) rand.nextInt((((int) N) - 1) + 1) + 1;
|
|
||||||
attackedWorm.incrementHitPoints(loseAttackedWorm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -792,7 +811,7 @@ public class Worm extends GameObject {
|
|||||||
*/
|
*/
|
||||||
@Raw
|
@Raw
|
||||||
private void setHitPoints(long hitPoints) {
|
private void setHitPoints(long hitPoints) {
|
||||||
if (hitPoints < 0)
|
if (hitPoints <= 0)
|
||||||
terminate();
|
terminate();
|
||||||
this.hitPoints = hitPoints;
|
this.hitPoints = hitPoints;
|
||||||
}
|
}
|
||||||
@@ -831,7 +850,7 @@ public class Worm extends GameObject {
|
|||||||
for (double y = oldLocation.getY(); y <= heigth; y = y - 0.01) {
|
for (double y = oldLocation.getY(); y <= heigth; y = y - 0.01) {
|
||||||
Coordinate newLoc = Coordinate.create(oldLocation.getX(), y);
|
Coordinate newLoc = Coordinate.create(oldLocation.getX(), y);
|
||||||
|
|
||||||
if (y - radius < 0) {
|
if (!isValidLocation(newLoc)) {
|
||||||
terminate();
|
terminate();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -841,14 +860,6 @@ public class Worm extends GameObject {
|
|||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// for (double i = y; i >= y - 1; i = i - 0.1) {
|
|
||||||
// double[] newLocation = {oldLocation.getX(), i};
|
|
||||||
// if (! getWorld().isPassable(newLocation, getRadius())) {
|
|
||||||
// setLocation(newLocation);
|
|
||||||
// endY = i;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user