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