small improvements
This commit is contained in:
@@ -5,8 +5,6 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import worms.util.IllegalNameException;
|
import worms.util.IllegalNameException;
|
||||||
import worms.util.ModelException;
|
|
||||||
import worms.util.MustNotImplementException;
|
|
||||||
|
|
||||||
public class Team {
|
public class Team {
|
||||||
// region constructor
|
// region constructor
|
||||||
@@ -33,8 +31,8 @@ public class Team {
|
|||||||
public void addWormsToTeam(Worm... worm) throws IllegalArgumentException {
|
public void addWormsToTeam(Worm... worm) throws IllegalArgumentException {
|
||||||
for (Worm w: worm) {
|
for (Worm w: worm) {
|
||||||
if (canHaveAsWorm(w)) {
|
if (canHaveAsWorm(w)) {
|
||||||
team.add(w);
|
wormArrayList.add(w);
|
||||||
sortList(team);
|
sortList(wormArrayList);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
@@ -53,8 +51,8 @@ public class Team {
|
|||||||
public boolean canHaveAsWorm(Worm worm) {
|
public boolean canHaveAsWorm(Worm worm) {
|
||||||
if (worm.getMass() > getMinMassTeam()/2 && worm.getMass() < 2 * getMaxMassTeam()
|
if (worm.getMass() > getMinMassTeam()/2 && worm.getMass() < 2 * getMaxMassTeam()
|
||||||
&& !worm.isTerminated()) {
|
&& !worm.isTerminated()) {
|
||||||
for (int i = 0; i < team.size(); i++) {
|
for (int i = 0; i < wormArrayList.size(); i++) {
|
||||||
if ((team.get(i)).getName() == worm.getName())
|
if ((wormArrayList.get(i)).getName() == worm.getName())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -81,7 +79,7 @@ public class Team {
|
|||||||
*/
|
*/
|
||||||
public void removeWormsFromTeam(Worm... worm) {
|
public void removeWormsFromTeam(Worm... worm) {
|
||||||
for (Worm w: worm) {
|
for (Worm w: worm) {
|
||||||
team.remove(w);
|
wormArrayList.remove(w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,14 +90,14 @@ public class Team {
|
|||||||
* |result == team.contains(worm)
|
* |result == team.contains(worm)
|
||||||
*/
|
*/
|
||||||
public boolean containsWorm(Worm worm) {
|
public boolean containsWorm(Worm worm) {
|
||||||
if (team.contains(worm)) {
|
if (wormArrayList.contains(worm)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Worm> getAllWormsOfTeam() {
|
public ArrayList<Worm> getAllWormsOfTeam() {
|
||||||
return team;
|
return wormArrayList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -112,13 +110,13 @@ public class Team {
|
|||||||
* |supplyingTeam.isTerminated() == true
|
* |supplyingTeam.isTerminated() == true
|
||||||
*/
|
*/
|
||||||
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.wormArrayList).size(); i++) {
|
||||||
addWormsToTeam((supplyingTeam.team).get(i));
|
addWormsToTeam((supplyingTeam.wormArrayList).get(i));
|
||||||
}
|
}
|
||||||
terminate(supplyingTeam);
|
terminate(supplyingTeam);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<Worm> team;
|
private ArrayList<Worm> wormArrayList;
|
||||||
|
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
// endregion
|
// endregion
|
||||||
@@ -141,9 +139,9 @@ public class Team {
|
|||||||
* | new.getMinMassTeam() == worm.getMass()
|
* | new.getMinMassTeam() == worm.getMass()
|
||||||
*/
|
*/
|
||||||
public void setMinMassTeam() {
|
public void setMinMassTeam() {
|
||||||
minMassTeam = (team.get(0)).getMass();
|
minMassTeam = (wormArrayList.get(0)).getMass();
|
||||||
for (int i = 1; i < team.size() - 1; i++) {
|
for (int i = 1; i < wormArrayList.size() - 1; i++) {
|
||||||
Worm worm = team.get(i);
|
Worm worm = wormArrayList.get(i);
|
||||||
if (worm.getMass() < minMassTeam) {
|
if (worm.getMass() < minMassTeam) {
|
||||||
minMassTeam = worm.getMass();
|
minMassTeam = worm.getMass();
|
||||||
}
|
}
|
||||||
@@ -167,9 +165,9 @@ public class Team {
|
|||||||
* | new.getMaxMassTeam() == worm.getMass()
|
* | new.getMaxMassTeam() == worm.getMass()
|
||||||
*/
|
*/
|
||||||
public void setMaxMassTeam() {
|
public void setMaxMassTeam() {
|
||||||
maxMassTeam = (team.get(0)).getMass();
|
maxMassTeam = (wormArrayList.get(0)).getMass();
|
||||||
for (int i = 1; i < team.size() - 1; i++) {
|
for (int i = 1; i < wormArrayList.size() - 1; i++) {
|
||||||
Worm worm = team.get(i);
|
Worm worm = wormArrayList.get(i);
|
||||||
if (worm.getMass() > maxMassTeam) {
|
if (worm.getMass() > maxMassTeam) {
|
||||||
minMassTeam = worm.getMass();
|
minMassTeam = worm.getMass();
|
||||||
}
|
}
|
||||||
@@ -249,7 +247,7 @@ public class Team {
|
|||||||
* |new.terminate == true
|
* |new.terminate == true
|
||||||
*/
|
*/
|
||||||
public void terminate(Team team) {
|
public void terminate(Team team) {
|
||||||
terminate = true;
|
this.terminated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -262,13 +260,10 @@ public class Team {
|
|||||||
* | result == false
|
* | result == false
|
||||||
*/
|
*/
|
||||||
public boolean isTerminated(Team team) {
|
public boolean isTerminated(Team team) {
|
||||||
if (terminate == true) {
|
return this.terminated;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean terminate = false;
|
private boolean terminated = false;
|
||||||
|
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
// endregion
|
// endregion
|
||||||
|
Reference in New Issue
Block a user