small improvements

This commit is contained in:
2018-03-09 22:30:42 +01:00
parent d86e5d542a
commit d1617e9cf3

View File

@@ -295,6 +295,7 @@ public class Worm {
return this.actionPoints; return this.actionPoints;
} }
@Basic
public long getMaxActionPoints() { public long getMaxActionPoints() {
return this.maxActionPoints; return this.maxActionPoints;
} }
@@ -410,30 +411,11 @@ public class Worm {
* Return the name of the worm * Return the name of the worm
* the name of the worm expresses the identity of the worm * the name of the worm expresses the identity of the worm
*/ */
@Basic
public String getName() { public String getName() {
return this.name; return this.name;
} }
/**
* set the name of the worm tot the given name
*
* @param name
* the new name for the worm
* @post the new name of the worm is equal to the given name
* |new.GetName() == name
* @throws IllegalNameException
* the given name is not a valid name for any worm
* |! isValidName(name)
*/
public void setName(String name) throws IllegalNameException {
int validName = isValidName(name);
if (validName != -1)
throw new IllegalNameException(validName, name);
this.name = name;
}
/** /**
* check whether the given name is a valid name for all worms * check whether the given name is a valid name for all worms
* *
@@ -464,16 +446,36 @@ public class Worm {
return -1; return -1;
} }
/**
* set the name of the worm tot the given name
*
* @param name
* the new name for the worm
* @post the new name of the worm is equal to the given name
* |new.GetName() == name
* @throws IllegalNameException
* the given name is not a valid name for any worm
* |! isValidName(name)
*/
public void setName(String name) throws IllegalNameException {
int validName = isValidName(name);
if (validName != -1)
throw new IllegalNameException(validName, name);
this.name = name;
}
/** /**
* this variable contains the name of the worm * this variable contains the name of the worm
*/ */
private String name; private String name;
//=================================================================================== //===================================================================================
// endregion // endregion
// region move // region move
//=================================================================================== //===================================================================================
@@ -551,7 +553,7 @@ public class Worm {
/** /**
* *
* @param angle * @param angle
* @return * @return ...
*/ */
private boolean canTurn(double angle) { private boolean canTurn(double angle) {
return 0 <= angle && angle < (2 * PI) && return 0 <= angle && angle < (2 * PI) &&
@@ -596,17 +598,6 @@ public class Worm {
this.actionPoints = 0; this.actionPoints = 0;
} }
/**
* Return a boolean whether the worm can jump or not
*
* @return True if and only if the action actionPoints is bigger then 0 and the orientation
* is lower then pi
* |result == this.actionPoints > 0 && this.orientation < Math.PI
*/
private boolean canJump() {
return this.actionPoints > 0 && this.orientation < PI;
}
/** /**
* Return the time the worm will jump * Return the time the worm will jump
* *
@@ -635,6 +626,17 @@ public class Worm {
this.location.item2 + this.jumpVelocity() * sin(this.orientation) * deltaTime - 0.5 * G * pow(deltaTime, 2)); this.location.item2 + this.jumpVelocity() * sin(this.orientation) * deltaTime - 0.5 * G * pow(deltaTime, 2));
} }
/**
* Return a boolean whether the worm can jump or not
*
* @return True if and only if the action actionPoints is bigger then 0 and the orientation
* is lower then pi
* |result == this.actionPoints > 0 && this.orientation < Math.PI
*/
private boolean canJump() {
return this.actionPoints > 0 && this.orientation < PI;
}
/** /**
* Return the distance the worm will jump * Return the distance the worm will jump
* *