diff --git a/OGP1718-Worms/src/worms/model/Food.java b/OGP1718-Worms/src/worms/model/Food.java index 2129851..379a8a1 100644 --- a/OGP1718-Worms/src/worms/model/Food.java +++ b/OGP1718-Worms/src/worms/model/Food.java @@ -1,5 +1,39 @@ package worms.model; +import static java.lang.Math.*; + public class Food { + // region location + //=================================================================================== + + //=================================================================================== + // endregion + + // region shape + //=================================================================================== + + final double radius = 0.20; + + public double getMass() { + return this.mass; + } + + public void setMass() { + final double rho = 150; + double m = rho * (4/3 * PI * pow(radius, 3)); + this.mass = m; + } + + public double mass; + + //=================================================================================== + // endregion + + // region eat + //=================================================================================== + + + //=================================================================================== + // endregion } diff --git a/OGP1718-Worms/src/worms/model/Team.java b/OGP1718-Worms/src/worms/model/Team.java index 2b725d2..e7ac7a8 100644 --- a/OGP1718-Worms/src/worms/model/Team.java +++ b/OGP1718-Worms/src/worms/model/Team.java @@ -2,93 +2,170 @@ package worms.model; import java.util.ArrayList; import java.util.Collections; +import java.util.List; + +import worms.util.IllegalNameException; +import worms.util.ModelException; +import worms.util.MustNotImplementException; public class Team { - public void addWorm(Worm worm) { - if (worm.getMass() > minMassTeam/2 && worm.getMass() < 2 * maxMassTeam && worm.isAlive()) { - listWorms.add(worm); - sortList(listWorms); + // region constructor + //=================================================================================== + + public Team (World world, String name) { + setName(name); + } + + //=================================================================================== + // endregion + + // region changesTeam + //=================================================================================== + + public void addWormsToTeam(Worm... worm) { + for (Worm w: worm) { + if (canHaveAsWorm(w)) { + team.add(w); + sortList(team); + } } } - public void sortList(ArrayList list) { - Collections.sort(list, - (el1, el2) -> el1.getName().compareToIgnoreCase(el2.getName())); - } - - public void removeWorm(Worm worm) { - listWorms.remove(worm); - } - - public boolean containsWorm(Worm worm) { - if (listWorms.contains(worm)) { + public boolean canHaveAsWorm(Worm worm) { + if (worm.getMass() > getMinMassTeam()/2 && worm.getMass() < 2 * getMaxMassTeam() + && worm.isAlive()) { + for (int i = 0; i < team.size(); i++) { + if ((team.get(i)).getName() == worm.getName()) + return false; + } return true; } return false; } - - public ArrayList returnTeam() { - return listWorms; + + public void sortList(ArrayList list) { + Collections.sort(list, + (el1, el2) -> el1.getName().compareToIgnoreCase(el2.getName())); } + + public void removeWormsFromTeam(Worm... worm) { + for (Worm w: worm) { + team.remove(w); + } + } + + public boolean containsWorm(Worm worm) { + if (team.contains(worm)) { + return true; + } + return false; + } + + public ArrayList getAllWormsOfTeam() { + return team; + } + + public void mergeTeams(Team recevingTeam, Team supplyingTeam) { + for (int i = 0; i < (supplyingTeam.team).size(); i++) { + addWormsToTeam((supplyingTeam.team).get(i)); + } + terminate(supplyingTeam); + } - private ArrayList listWorms; + private ArrayList team; + //=================================================================================== + // endregion + + // region mass + //=================================================================================== + public double getMinMassTeam() { return this.minMassTeam; } - + public void setMinMassTeam() { - for (int i = 0; i < listWorms.size() - 2; i++) { - Worm wormA = listWorms.get(i); - Worm wormB = listWorms.get(i+1); + for (int i = 0; i < team.size() - 1; i++) { + Worm wormA = team.get(i); + Worm wormB = team.get(i+1); if (wormA.getMass() < wormB.getMass()) { minMassTeam = wormA.getMass(); } } } - + private double minMassTeam; - + public double getMaxMassTeam() { return this.maxMassTeam; } - + public void setMaxMassTeam() { - for (int i = 0; i < listWorms.size() - 2; i++) { - Worm wormA = listWorms.get(i); - Worm wormB = listWorms.get(i+1); + for (int i = 0; i < team.size() - 1; i++) { + Worm wormA = team.get(i); + Worm wormB = team.get(i+1); if (wormA.getMass() > wormB.getMass()) { maxMassTeam = wormA.getMass(); } } } - + private double maxMassTeam; - public String getTeamName() { - return this.teamName; + //=================================================================================== + // endregion + + // region name + //=================================================================================== + + public String getName() { + return this.name; } - public void setTeamName() { - - } + public static int isValidName (String name) { + + if (name.length() < 2 || !Character.isUpperCase(name.charAt(0))) { + return 0; + } + String allowedCharacters = "'\" "; + + for (int i = 0; i < name.length(); i++) { + if (!Character.isLetter(name.charAt(i))) { + if (allowedCharacters.indexOf(name.charAt(i)) == -1) { + return i; + } + } + } + return -1; + } - private String teamName; + public void setName(String name) throws IllegalNameException { + + int validTeamName = isValidName(name); + if (validTeamName != -1) + throw new IllegalNameException(validTeamName, name); + + this.name = name; + } + + private String name; + //=================================================================================== + // endregion - public String getWinner(){ - return this.winner; - } + // region terminate + //=================================================================================== - public void setWinner() { - if (listWorms.size() == 1) { - winner = (listWorms.get(0)).getName(); - } - else { - winner = this.getTeamName(); - } - } + //TODO region terminate - private String winner; + public void terminate(Team team) { + + } + public boolean isTerminated(Team team) { + return false; + } + + //=================================================================================== + // endregion } diff --git a/OGP1718-Worms/src/worms/model/Worm.java b/OGP1718-Worms/src/worms/model/Worm.java index 9556626..8e99cc6 100644 --- a/OGP1718-Worms/src/worms/model/Worm.java +++ b/OGP1718-Worms/src/worms/model/Worm.java @@ -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 }