Release v2.1

Fixed a bug related to the radius of a newly created worm
This commit is contained in:
Koen Yskout
2018-03-22 19:18:38 +01:00
parent 5f5948795f
commit f45fa3fa96

View File

@@ -11,6 +11,9 @@ import worms.util.ModelException;
public class AddNewWorm extends InstantaneousCommand { public class AddNewWorm extends InstantaneousCommand {
private static final double MIN_RADIUS = 0.25;
private static final double MAX_RADIUS = Math.pow(2, 1.0/3.0) * MIN_RADIUS;
public AddNewWorm(IFacade facade, PlayGameScreen screen) { public AddNewWorm(IFacade facade, PlayGameScreen screen) {
super(facade, screen); super(facade, screen);
} }
@@ -26,8 +29,8 @@ public class AddNewWorm extends InstantaneousCommand {
Random random = getScreen().getGameState().getRandom(); Random random = getScreen().getGameState().getRandom();
int nbWorms = getFacade().getAllWorms(getWorld()).size(); int nbWorms = getFacade().getAllWorms(getWorld()).size();
String name = "Worm " + GUIUtils.numberToName(nbWorms++); String name = "Worm " + GUIUtils.numberToName(nbWorms++);
// ensures all worms have radius in [0.25, 0.50[, so minimum radius and team size conditions are always fulfilled // ensures minimum radius and team size conditions are always fulfilled
double radius = 0.25 * (1.0 + random.nextDouble()); double radius = MIN_RADIUS + (MAX_RADIUS - MIN_RADIUS) * random.nextDouble();
double[] p = GUIUtils.findFreeAdjacentSpot(getFacade(), getWorld(), radius, random); double[] p = GUIUtils.findFreeAdjacentSpot(getFacade(), getWorld(), radius, random);