Worm class: fight, hitPoints, fall, collision
This commit is contained in:
@@ -12,9 +12,6 @@ public class Team {
|
|||||||
// region constructor
|
// region constructor
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new team for the given world with given name and with no members yet.
|
|
||||||
*/
|
|
||||||
public Team (World world, String name) {
|
public Team (World world, String name) {
|
||||||
setName(name);
|
setName(name);
|
||||||
}
|
}
|
||||||
@@ -22,14 +19,9 @@ public class Team {
|
|||||||
//===================================================================================
|
//===================================================================================
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region changeTeam
|
// region changesTeam
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param worm
|
|
||||||
*/
|
|
||||||
public void addWormsToTeam(Worm... worm) {
|
public void addWormsToTeam(Worm... worm) {
|
||||||
for (Worm w: worm) {
|
for (Worm w: worm) {
|
||||||
if (canHaveAsWorm(w)) {
|
if (canHaveAsWorm(w)) {
|
||||||
@@ -50,53 +42,29 @@ public class Team {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param list
|
|
||||||
*/
|
|
||||||
public void sortList(ArrayList<Worm> list) {
|
public void sortList(ArrayList<Worm> list) {
|
||||||
Collections.sort(list,
|
Collections.sort(list,
|
||||||
(el1, el2) -> el1.getName().compareToIgnoreCase(el2.getName()));
|
(el1, el2) -> el1.getName().compareToIgnoreCase(el2.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param worm
|
|
||||||
*/
|
|
||||||
public void removeWormsFromTeam(Worm... worm) {
|
public void removeWormsFromTeam(Worm... worm) {
|
||||||
for (Worm w: worm) {
|
for (Worm w: worm) {
|
||||||
team.remove(w);
|
team.remove(w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param worm
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean containsWorm(Worm worm) {
|
public boolean containsWorm(Worm worm) {
|
||||||
if (team.contains(worm)) {
|
if (team.contains(worm)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a list of all the worms in the given team, sorted alphabetically.
|
|
||||||
* This method must run in linear time.
|
|
||||||
*
|
|
||||||
* @return listWorms
|
|
||||||
*/
|
|
||||||
public ArrayList<Worm> getAllWormsOfTeam() {
|
public ArrayList<Worm> getAllWormsOfTeam() {
|
||||||
return team;
|
return team;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Merge the given teams.
|
|
||||||
* - All the worms of the supplying team are transferred to the receiving team.
|
|
||||||
*/
|
|
||||||
public void mergeTeams(Team recevingTeam, Team supplyingTeam) {
|
public void mergeTeams(Team recevingTeam, Team supplyingTeam) {
|
||||||
for (int i = 0; i < (supplyingTeam.team).size(); i++) {
|
for (int i = 0; i < (supplyingTeam.team).size(); i++) {
|
||||||
addWormsToTeam((supplyingTeam.team).get(i));
|
addWormsToTeam((supplyingTeam.team).get(i));
|
||||||
@@ -104,9 +72,6 @@ public class Team {
|
|||||||
terminate(supplyingTeam);
|
terminate(supplyingTeam);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private ArrayList<Worm> team;
|
private ArrayList<Worm> team;
|
||||||
|
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
@@ -114,18 +79,11 @@ public class Team {
|
|||||||
|
|
||||||
// region mass
|
// region mass
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public double getMinMassTeam() {
|
public double getMinMassTeam() {
|
||||||
return this.minMassTeam;
|
return this.minMassTeam;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void setMinMassTeam() {
|
public void setMinMassTeam() {
|
||||||
for (int i = 0; i < team.size() - 1; i++) {
|
for (int i = 0; i < team.size() - 1; i++) {
|
||||||
Worm wormA = team.get(i);
|
Worm wormA = team.get(i);
|
||||||
@@ -135,23 +93,13 @@ public class Team {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private double minMassTeam;
|
private double minMassTeam;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public double getMaxMassTeam() {
|
public double getMaxMassTeam() {
|
||||||
return this.maxMassTeam;
|
return this.maxMassTeam;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void setMaxMassTeam() {
|
public void setMaxMassTeam() {
|
||||||
for (int i = 0; i < team.size() - 1; i++) {
|
for (int i = 0; i < team.size() - 1; i++) {
|
||||||
Worm wormA = team.get(i);
|
Worm wormA = team.get(i);
|
||||||
@@ -161,10 +109,7 @@ public class Team {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private double maxMassTeam;
|
private double maxMassTeam;
|
||||||
|
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
@@ -173,19 +118,10 @@ public class Team {
|
|||||||
// region name
|
// region name
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param teamName
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static int isValidName (String name) {
|
public static int isValidName (String name) {
|
||||||
|
|
||||||
if (name.length() < 2 || !Character.isUpperCase(name.charAt(0))) {
|
if (name.length() < 2 || !Character.isUpperCase(name.charAt(0))) {
|
||||||
@@ -203,11 +139,6 @@ public class Team {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param teamName
|
|
||||||
* @throws IllegalNameException
|
|
||||||
*/
|
|
||||||
public void setName(String name) throws IllegalNameException {
|
public void setName(String name) throws IllegalNameException {
|
||||||
|
|
||||||
int validTeamName = isValidName(name);
|
int validTeamName = isValidName(name);
|
||||||
@@ -217,10 +148,6 @@ public class Team {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
@@ -231,16 +158,10 @@ public class Team {
|
|||||||
|
|
||||||
//TODO region terminate
|
//TODO region terminate
|
||||||
|
|
||||||
/**
|
|
||||||
* Terminate the given team.
|
|
||||||
*/
|
|
||||||
public void terminate(Team team) {
|
public void terminate(Team team) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether the given portion of food is terminated.
|
|
||||||
*/
|
|
||||||
public boolean isTerminated(Team team) {
|
public boolean isTerminated(Team team) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -593,14 +593,30 @@ public class Worm {
|
|||||||
subtractActionPoints(cost);
|
subtractActionPoints(cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void collision(Worm smallestWorm, Worm largestWorm) {
|
public Coordinate getFurthestLocationInDirection() {
|
||||||
long total = 1 + (new Random().nextLong() * (10 - 1));
|
|
||||||
long loseSmallest = (long) (total / (largestWorm.getOrientation() / (smallestWorm.getOrientation() + largestWorm.getOrientation())));
|
|
||||||
long loseLargest = total - loseSmallest;
|
|
||||||
smallestWorm.incrementHitPoints(loseSmallest);
|
|
||||||
largestWorm.incrementHitPoints(loseLargest);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void collision(Worm basicWorm, Worm... worm) {
|
||||||
|
Worm largestWorm;
|
||||||
|
Worm smallestWorm;
|
||||||
|
for (Worm w1: worm) {
|
||||||
|
if (w1.getMass() > basicWorm.getMass()) {
|
||||||
|
largestWorm = w1;
|
||||||
|
smallestWorm = basicWorm;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
largestWorm = basicWorm;
|
||||||
|
smallestWorm = w1;
|
||||||
|
}
|
||||||
|
long total = 1 + (new Random().nextLong() * (10 - 1));
|
||||||
|
long loseSmallest = (long) (total / (largestWorm.getOrientation() / (smallestWorm.getOrientation() + largestWorm.getOrientation())));
|
||||||
|
long loseLargest = total - loseSmallest;
|
||||||
|
smallestWorm.incrementHitPoints(loseSmallest);
|
||||||
|
largestWorm.incrementHitPoints(loseLargest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
@@ -764,6 +780,27 @@ public class Worm {
|
|||||||
double force = 5 * getActionPoints() + getMass() * G;
|
double force = 5 * getActionPoints() + getMass() * G;
|
||||||
return force / getMass() * FORCE_TIME;
|
return force / getMass() * FORCE_TIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void fight(Worm worm1, Worm... worm2) {
|
||||||
|
for (Worm wormB: worm2) {
|
||||||
|
Worm attackedWorm;
|
||||||
|
Worm attacker;
|
||||||
|
Random rand = new Random();
|
||||||
|
int coin = rand.nextInt((1 - 0) + 1) + 0;
|
||||||
|
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.incrementHitPoints(loseAttackedWorm);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
@@ -780,7 +817,7 @@ public class Worm {
|
|||||||
@Raw
|
@Raw
|
||||||
private void setHitPoints(long hitPoints) {
|
private void setHitPoints(long hitPoints) {
|
||||||
if (hitPoints <= 0)
|
if (hitPoints <= 0)
|
||||||
// TODO worm sterft + weghalen van gamewereld
|
terminate();
|
||||||
this.hitPoints = hitPoints;
|
this.hitPoints = hitPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -790,11 +827,27 @@ public class Worm {
|
|||||||
setHitPoints(getHitPoints() - value);
|
setHitPoints(getHitPoints() - value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* terminate the worm
|
||||||
|
*/
|
||||||
|
public void terminate() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
//TODO nog te implementeren
|
|
||||||
public boolean isAlive() {
|
public boolean isAlive() {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// region falling
|
||||||
|
//===================================================================================
|
||||||
|
|
||||||
|
public void fall() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//===================================================================================
|
||||||
|
// endregion
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user