示例#1
0
 private Point2D validateCoordinate(Point2D possibleNewLocation) {
   double maxY = armyAllegiance.getScene().getHeight();
   double maxX = armyAllegiance.getScene().getWidth();
   double myX = possibleNewLocation.getX();
   double myY = possibleNewLocation.getY();
   double newX = 0.0;
   double newY = 0.0;
   if ((myX < 0) && (myY < 0)) {
     newX = SingletonRandom.instance.getNormalDistribution(0.0, (0.25 * maxX), 2.0);
     newY = SingletonRandom.instance.getNormalDistribution(0.0, (0.25 * maxY), 2.0);
     return new Point2D(newX, newY);
   } else if ((0 < myX) && (myX < maxX) && (myY < 0)) {
     newY = SingletonRandom.instance.getNormalDistribution(0.0, (0.25 * maxY), 2.0);
     return new Point2D(myX, newY);
   } else if ((myX > maxX) && (myY < 0)) {
     newX = SingletonRandom.instance.getNormalDistribution(0.0, (0.75 * maxX), 2.0);
     newY = SingletonRandom.instance.getNormalDistribution(0.0, (0.75 * maxY), 2.0);
     return new Point2D(newX, newY);
   } else if ((0 < myX) && (myY < maxY) && (myY > 0)) {
     newX = SingletonRandom.instance.getNormalDistribution(0.0, (0.25 * maxX), 2.0);
     return new Point2D(newX, myY);
   } else if ((myX > maxX) && (myY < maxY) && (myY > 0)) {
     newX = SingletonRandom.instance.getNormalDistribution(0.0, (0.75 * maxX), 2.0);
     return new Point2D(newX, myY);
   }
   if ((myX < 0) && (myY > maxY)) {
     newX = SingletonRandom.instance.getNormalDistribution(0.0, (0.25 * maxX), 2.0);
     newY = SingletonRandom.instance.getNormalDistribution(0.0, (0.75 * maxY), 2.0);
     return new Point2D(newX, newY);
   } else if ((0 < myX) && (myX < maxX) && (myY > maxY)) {
     newY = SingletonRandom.instance.getNormalDistribution(0.0, (0.75 * maxY), 2.0);
     return new Point2D(myX, newY);
   } else if ((myX > maxX) && (myY > maxY)) {
     newX = SingletonRandom.instance.getNormalDistribution(0.0, (0.75 * maxX), 2.0);
     newY = SingletonRandom.instance.getNormalDistribution(0.0, (0.75 * maxY), 2.0);
     return new Point2D(newX, newY);
   } else {
     return new Point2D(myX, myY);
   }
 }