Merge branch 'master' of gitlab.principis.be:OGP/worms
This commit is contained in:
@@ -1,5 +1,39 @@
|
|||||||
package worms.model;
|
package worms.model;
|
||||||
|
|
||||||
public class Food {
|
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
|
||||||
}
|
}
|
||||||
|
@@ -2,13 +2,45 @@ package worms.model;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import worms.util.IllegalNameException;
|
||||||
|
import worms.util.ModelException;
|
||||||
|
import worms.util.MustNotImplementException;
|
||||||
|
|
||||||
public class Team {
|
public class Team {
|
||||||
public void addWorm(Worm worm) {
|
// region constructor
|
||||||
if (worm.getMass() > minMassTeam/2 && worm.getMass() < 2 * maxMassTeam && worm.isAlive()) {
|
//===================================================================================
|
||||||
listWorms.add(worm);
|
|
||||||
sortList(listWorms);
|
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 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 void sortList(ArrayList<Worm> list) {
|
public void sortList(ArrayList<Worm> list) {
|
||||||
@@ -16,31 +48,46 @@ public class Team {
|
|||||||
(el1, el2) -> el1.getName().compareToIgnoreCase(el2.getName()));
|
(el1, el2) -> el1.getName().compareToIgnoreCase(el2.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeWorm(Worm worm) {
|
public void removeWormsFromTeam(Worm... worm) {
|
||||||
listWorms.remove(worm);
|
for (Worm w: worm) {
|
||||||
|
team.remove(w);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean containsWorm(Worm worm) {
|
public boolean containsWorm(Worm worm) {
|
||||||
if (listWorms.contains(worm)) {
|
if (team.contains(worm)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Worm> returnTeam() {
|
public ArrayList<Worm> getAllWormsOfTeam() {
|
||||||
return listWorms;
|
return team;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<Worm> listWorms;
|
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<Worm> team;
|
||||||
|
|
||||||
|
//===================================================================================
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region mass
|
||||||
|
//===================================================================================
|
||||||
|
|
||||||
public double getMinMassTeam() {
|
public double getMinMassTeam() {
|
||||||
return this.minMassTeam;
|
return this.minMassTeam;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMinMassTeam() {
|
public void setMinMassTeam() {
|
||||||
for (int i = 0; i < listWorms.size() - 2; i++) {
|
for (int i = 0; i < team.size() - 1; i++) {
|
||||||
Worm wormA = listWorms.get(i);
|
Worm wormA = team.get(i);
|
||||||
Worm wormB = listWorms.get(i+1);
|
Worm wormB = team.get(i+1);
|
||||||
if (wormA.getMass() < wormB.getMass()) {
|
if (wormA.getMass() < wormB.getMass()) {
|
||||||
minMassTeam = wormA.getMass();
|
minMassTeam = wormA.getMass();
|
||||||
}
|
}
|
||||||
@@ -54,9 +101,9 @@ public class Team {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxMassTeam() {
|
public void setMaxMassTeam() {
|
||||||
for (int i = 0; i < listWorms.size() - 2; i++) {
|
for (int i = 0; i < team.size() - 1; i++) {
|
||||||
Worm wormA = listWorms.get(i);
|
Worm wormA = team.get(i);
|
||||||
Worm wormB = listWorms.get(i+1);
|
Worm wormB = team.get(i+1);
|
||||||
if (wormA.getMass() > wormB.getMass()) {
|
if (wormA.getMass() > wormB.getMass()) {
|
||||||
maxMassTeam = wormA.getMass();
|
maxMassTeam = wormA.getMass();
|
||||||
}
|
}
|
||||||
@@ -65,30 +112,60 @@ public class Team {
|
|||||||
|
|
||||||
private double maxMassTeam;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
// region terminate
|
||||||
|
//===================================================================================
|
||||||
|
|
||||||
|
//TODO region terminate
|
||||||
|
|
||||||
|
public void terminate(Team team) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String teamName;
|
public boolean isTerminated(Team team) {
|
||||||
|
return false;
|
||||||
|
|
||||||
public String getWinner(){
|
|
||||||
return this.winner;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWinner() {
|
//===================================================================================
|
||||||
if (listWorms.size() == 1) {
|
// endregion
|
||||||
winner = (listWorms.get(0)).getName();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
winner = this.getTeamName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String winner;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -593,13 +593,29 @@ public class Worm {
|
|||||||
subtractActionPoints(cost);
|
subtractActionPoints(cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void collision(Worm smallestWorm, Worm largestWorm) {
|
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 total = 1 + (new Random().nextLong() * (10 - 1));
|
||||||
long loseSmallest = (long) (total / (largestWorm.getOrientation() / (smallestWorm.getOrientation() + largestWorm.getOrientation())));
|
long loseSmallest = (long) (total / (largestWorm.getOrientation() / (smallestWorm.getOrientation() + largestWorm.getOrientation())));
|
||||||
long loseLargest = total - loseSmallest;
|
long loseLargest = total - loseSmallest;
|
||||||
smallestWorm.incrementHitPoints(loseSmallest);
|
smallestWorm.incrementHitPoints(loseSmallest);
|
||||||
largestWorm.incrementHitPoints(loseLargest);
|
largestWorm.incrementHitPoints(loseLargest);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
// endregion
|
// endregion
|
||||||
@@ -765,6 +781,27 @@ public class Worm {
|
|||||||
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
// endregion
|
// endregion
|
||||||
@@ -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