Esempio n. 1
0
 private void searchForTarget() {
   Point2D closestBonus = null;
   double longestPath = 0;
   double shortestHealPath = Double.POSITIVE_INFINITY;
   Point2D closestHealth = null;
   for (RoundGameObject object : visibleObjectsBuffer) {
     if (object instanceof Bonus) {
       double path =
           euclideanSpaceDistance(getPlayerTank().getCenterPoint(), object.getCenterPoint());
       if (getPlayerTank().getHealthPoints() < 700
           && ((Bonus) object).getBonusType() == BonusType.HEALTH) {
         if (shortestHealPath < path) {
           closestHealth = new Point2D(object.getCenterX(), object.getCenterY());
           break;
         }
       }
       if (path > longestPath) {
         longestPath = path;
         closestBonus = new Point2D(object.getCenterX(), object.getCenterY());
       }
     }
   }
   if (closestHealth != null) {
     target = closestHealth;
   } else {
     target = closestBonus;
   }
 }
Esempio n. 2
0
 private boolean checkWhetherTheTargetExists() {
   for (RoundGameObject object : visibleObjectsBuffer) {
     if (euclideanSpaceDistance(target, object.getCenterPoint()) < 0.1) {
       return true;
     }
   }
   return false;
 }