@Override
  protected void process(Entity e) {
    final Buildable buildable = bm.get(e);
    if (!buildable.built) {
      final Bounds bounds = om.get(e);
      final Pos pos = pm.get(e);

      boolean affordable = buildable.resourceCost <= walletCash;
      assetSystem.font.setColor(affordable ? HOLO_COLOR : HOLO_COLOR_RED);
      String cost = "" + buildable.resourceCost + "$";
      assetSystem.font.draw(
          batch,
          cost,
          pos.x + bounds.cx() - assetSystem.font.getBounds(cost).width / 2,
          pos.y + bounds.y2 + 20);

      if (collisionSystem.overlaps(player, e) && affordable) {
        String msg = "'e' to purchase";
        assetSystem.font.draw(
            batch,
            msg,
            pos.x + bounds.cx() - assetSystem.font.getBounds(msg).width / 2,
            pos.y + bounds.y2 + 32);
      }
    }
  }
  @Nullable
  @Override
  public IJailSession imprison(Player player, Date expires) {
    PreCon.notNull(player);

    checkDisposed();

    // teleport player to jail
    Location teleport = getRandomTeleport();
    if (teleport == null) {

      if (!_bounds.isDefined()) {
        NucMsg.debug(
            getPlugin(),
            "Cannot imprison player in jail '{0}' because its coordinates "
                + "are undefined and no teleport location has been assigned.");
        return null;
      }

      teleport = _bounds.getCenter();
    }

    // register session
    IJailSession session = _provider.createSession(this, player.getUniqueId(), expires);

    if (session == null) return null;

    player.teleport(teleport);
    player.setGameMode(GameMode.SURVIVAL);

    return session;
  }
示例#3
0
  /**
   * Generate new colors. This method is executed by the callback action when the player selects a
   * valid rectangle. The purpose of this method is to regenerate the board and apply any required
   * checks to make sure that the game doesn't enter in an infinite loop.
   *
   * @param bounds the bounds that have to be regenerated.
   */
  private void generate(Bounds bounds) {
    // Generate new balls;
    game.getState()
        .getBoard()
        .randomize(
            new Coordinate(bounds.minX, bounds.minY), new Coordinate(bounds.maxX, bounds.maxY));

    // Check the new board for valid combinations.
    CombinationFinder newFinder = CombinationFinder.create(game.getState().getBoard());
    if (newFinder.getPossibleBounds().size() == 1) {
      // Only one combination? This is trouble.
      Bounds newCombinationBounds = newFinder.getCombination();
      if (newCombinationBounds.equals(bounds)) {
        // Oh, oh, in the same spot! So, they must be of the same color.
        // Therefore, we need to randomize some balls to avoid enter
        // an infinite loop.
        timer.setRunning(false);
        board.setColoured(false);
        game.getState().resetBoard();
        board.addAction(
            Actions.sequence(
                board.shake(10, 5, 0.05f),
                Actions.run(
                    new Runnable() {
                      @Override
                      public void run() {
                        board.setColoured(true);
                        timer.setRunning(true);
                      }
                    })));
      }
    }
    board.addAction(board.showRegion(bounds));
  }
  @Nullable
  @Override
  public Location getReleaseLocation() {
    if (_releaseLocation == null && _bounds.getWorld() != null) {
      return _bounds.getWorld().getSpawnLocation();
    }

    return _releaseLocation != null ? _releaseLocation.clone() : null;
  }
 /**
  * Transform the input bound by the current LocalToVWorld, this one overwrite the one defined in
  * NodeRetained since for TransformGroup, it has to use currentChildLocalToVworld instead of
  * currentLocalToVworld
  */
 void transformBounds(SceneGraphPath path, Bounds bound) {
   if (!((NodeRetained) path.item.retained).inSharedGroup) {
     bound.transform(getCurrentChildLocalToVworld());
   } else {
     HashKey key = new HashKey("");
     path.getHashKey(key);
     bound.transform(getCurrentChildLocalToVworld(key));
   }
 }
示例#6
0
 static void drawALU(Graphics g, Bounds bds) {
   int wid = bds.getWidth();
   int ht = bds.getHeight();
   int x0 = bds.getX();
   int x1 = x0 + wid;
   int y0 = bds.getY();
   int y1 = y0 + ht;
   int xp[] = {x0, x1, x1, x0, x0, x0 + 20, x0};
   int yp[] = {y0, y0 + 30, y1 - 30, y1, y1 - 40, y1 - 50, y1 - 60};
   GraphicsUtil.switchToWidth(g, 2);
   g.drawPolygon(xp, yp, 7);
 }
示例#7
0
 /** Infers as precise a fixed point as possible. */
 @Action
 public void inferBounds() {
   int deductions = 1;
   while (deductions > 0) {
     bounds_.startAnalysis();
     pred_.inferBounds(bounds_);
     bounds_.endAnalysis();
     deductions = bounds_.getDeductions();
     debug("inferBounds did " + deductions + " deductions, bounds=" + bounds_);
   }
   state_ = State.NoMode;
 }
  // the bounds argument is already transformed
  @Override
  boolean intersect(Bounds targetBound) {
    int i = 0;
    int j, count = 0;
    Point3d[] pnts = new Point3d[2];
    int scount;
    pnts[0] = new Point3d();
    pnts[1] = new Point3d();

    switch (targetBound.getPickType()) {
      case PickShape.PICKBOUNDINGBOX:
        BoundingBox box = (BoundingBox) targetBound;

        while (i < stripIndexCounts.length) {
          getVertexData(indexCoord[count++], pnts[0]);
          scount = stripIndexCounts[i++];
          for (j = 1; j < scount; j++) {
            getVertexData(indexCoord[count++], pnts[1]);
            if (intersectBoundingBox(pnts, box, null, null)) {
              return true;
            }
            pnts[0].set(pnts[1]);
          }
        }
        break;
      case PickShape.PICKBOUNDINGSPHERE:
        BoundingSphere bsphere = (BoundingSphere) targetBound;

        while (i < stripIndexCounts.length) {
          getVertexData(indexCoord[count++], pnts[0]);
          scount = stripIndexCounts[i++];
          for (j = 1; j < scount; j++) {
            getVertexData(indexCoord[count++], pnts[1]);
            if (intersectBoundingSphere(pnts, bsphere, null, null)) {
              return true;
            }
            pnts[0].set(pnts[1]);
          }
        }
        break;
      case PickShape.PICKBOUNDINGPOLYTOPE:
        BoundingPolytope bpolytope = (BoundingPolytope) targetBound;

        while (i < stripIndexCounts.length) {
          getVertexData(indexCoord[count++], pnts[0]);
          scount = stripIndexCounts[i++];
          for (j = 1; j < scount; j++) {
            getVertexData(indexCoord[count++], pnts[1]);
            if (intersectBoundingPolytope(pnts, bpolytope, null, null)) {
              return true;
            }
            pnts[0].set(pnts[1]);
          }
        }
        break;
      default:
        throw new RuntimeException("Bounds not supported for intersection " + targetBound);
    }
    return false;
  }
示例#9
0
文件: FlatTuple.java 项目: pollow/czt
 /* (non-Javadoc)
  * @see net.sourceforge.czt.animation.eval.flatpred.FlatPred#inferBounds(net.sourceforge.czt.animation.eval.flatpred.Bounds)
  */
 @Override
 public boolean inferBounds(Bounds bnds) {
   for (int i = 0; i < args_.size() - 1; i++) {
     bnds.addStructureArg(getLastArg(), Integer.valueOf(i + 1), args_.get(i));
   }
   return false;
 }
 @Override
 public double getStdDeviationBound(Bounds bound) {
   if (bound.equals(Bounds.UPPER)) {
     return getAvg() + (getStdDeviation() * sigma);
   } else {
     return getAvg() - (getStdDeviation() * sigma);
   }
 }
示例#11
0
  // the bounds argument is already transformed
  @Override
  boolean intersect(Bounds targetBound) {
    Point3d[] points = new Point3d[4];
    int i =
        ((vertexFormat & GeometryArray.BY_REFERENCE) == 0 ? initialVertexIndex : initialCoordIndex);

    points[0] = new Point3d();
    points[1] = new Point3d();
    points[2] = new Point3d();
    points[3] = new Point3d();

    switch (targetBound.getPickType()) {
      case PickShape.PICKBOUNDINGBOX:
        BoundingBox box = (BoundingBox) targetBound;

        while (i < validVertexCount) {
          getVertexData(i++, points[0]);
          getVertexData(i++, points[1]);
          getVertexData(i++, points[2]);
          getVertexData(i++, points[3]);
          if (intersectBoundingBox(points, box, null, null)) {
            return true;
          }
        }
        break;
      case PickShape.PICKBOUNDINGSPHERE:
        BoundingSphere bsphere = (BoundingSphere) targetBound;

        while (i < validVertexCount) {
          getVertexData(i++, points[0]);
          getVertexData(i++, points[1]);
          getVertexData(i++, points[2]);
          getVertexData(i++, points[3]);
          if (intersectBoundingSphere(points, bsphere, null, null)) {
            return true;
          }
        }
        break;
      case PickShape.PICKBOUNDINGPOLYTOPE:
        BoundingPolytope bpolytope = (BoundingPolytope) targetBound;

        while (i < validVertexCount) {
          getVertexData(i++, points[0]);
          getVertexData(i++, points[1]);
          getVertexData(i++, points[2]);
          getVertexData(i++, points[3]);
          if (intersectBoundingPolytope(points, bpolytope, null, null)) {
            return true;
          }
        }
        break;
      default:
        throw new RuntimeException("Bounds not supported for intersection " + targetBound);
    }
    return false;
  }
示例#12
0
  public PointTranslator(Bounds source, Bounds dest, AbstractPointTranslator other) {
    _source = source;
    _dest = dest;

    _sourceCenter = _source.center();
    _destCenter = dest.center();
    double scale = _dest.xDiff() / _source.xDiff();
    if (Math.abs(dest.yDiff() / _source.yDiff()) < Math.abs(scale)) {
      scale = dest.yDiff() / _source.yDiff();
    }
    this.scale = scale;
  }
示例#13
0
  @Override
  void computeCombineBounds(Bounds bounds) {

    if (boundsAutoCompute) {
      sharedGroup.computeCombineBounds(bounds);
    } else {
      // Should this be lock too ? ( MT safe  ? )
      synchronized (localBounds) {
        bounds.combine(localBounds);
      }
    }
  }
示例#14
0
    /**
     * Get source's bounds. Checks if object is an instance of Bounded, otherwise checks if the
     * object is an AVList and contains a value for AVKey.SECTOR.
     *
     * @param source
     * @return source's bounds, or null if they couldn't be determined
     */
    public static Bounds getBounds(Object source) {
      if (source instanceof Bounded) {
        return ((Bounded) source).getBounds();
      } else if (source instanceof AVList) {
        Object o = ((AVList) source).getValue(AVKey.SECTOR);
        if (o instanceof Sector) {
          return Bounds.fromSector((Sector) o);
        }
      }

      return null;
    }
  // the bounds argument is already transformed
  @Override
  boolean intersect(Bounds targetBound) {
    Point3d[] pnts = new Point3d[3];
    // NVaidya
    // Bug 447: correction for loop indices
    int i = initialIndexIndex;
    int loopStopIndex = initialIndexIndex + validIndexCount;
    pnts[0] = new Point3d();
    pnts[1] = new Point3d();
    pnts[2] = new Point3d();

    switch (targetBound.getPickType()) {
      case PickShape.PICKBOUNDINGBOX:
        BoundingBox box = (BoundingBox) targetBound;

        while (i < loopStopIndex) {
          getVertexData(indexCoord[i++], pnts[0]);
          getVertexData(indexCoord[i++], pnts[1]);
          getVertexData(indexCoord[i++], pnts[2]);
          if (intersectBoundingBox(pnts, box, null, null)) {
            return true;
          }
        }
        break;
      case PickShape.PICKBOUNDINGSPHERE:
        BoundingSphere bsphere = (BoundingSphere) targetBound;

        while (i < loopStopIndex) {
          getVertexData(indexCoord[i++], pnts[0]);
          getVertexData(indexCoord[i++], pnts[1]);
          getVertexData(indexCoord[i++], pnts[1]);
          if (intersectBoundingSphere(pnts, bsphere, null, null)) {
            return true;
          }
        }
        break;
      case PickShape.PICKBOUNDINGPOLYTOPE:
        BoundingPolytope bpolytope = (BoundingPolytope) targetBound;

        while (i < loopStopIndex) {
          getVertexData(indexCoord[i++], pnts[0]);
          getVertexData(indexCoord[i++], pnts[1]);
          getVertexData(indexCoord[i++], pnts[2]);
          if (intersectBoundingPolytope(pnts, bpolytope, null, null)) {
            return true;
          }
        }
        break;
      default:
        throw new RuntimeException("Bounds not supported for intersection " + targetBound);
    }
    return false;
  }
示例#16
0
 public void add(double[] point) {
   bounds.add(point);
   count++;
   if (splitter.test(point)) {
     if (null != left) {
       left.add(point);
     }
   } else {
     if (null != right) {
       right.add(point);
     }
   }
 }
  void computeCombineBounds(Bounds bounds) {
    // Issue 514 : NPE in Wonderland : triggered in cached bounds computation
    if (validCachedBounds && boundsAutoCompute) {
      Bounds b = (Bounds) cachedBounds.clone();
      // Should this be lock too ? ( MT safe  ? )
      // Thoughts :
      // Make a temp copy with lock :  transform.getWithLock(trans);, but this will cause gc ...
      synchronized (transform) {
        b.transform(transform);
      }
      bounds.combine(b);
      return;
    }

    NodeRetained child;
    // issue 544
    Bounds boundingObject = null;
    if (VirtualUniverse.mc.useBoxForGroupBounds) {
      boundingObject = new BoundingBox((Bounds) null);
    } else {
      boundingObject = new BoundingSphere();
      ((BoundingSphere) boundingObject).setRadius(-1.0);
    }
    if (boundsAutoCompute) {
      for (int i = children.size() - 1; i >= 0; i--) {
        child = (NodeRetained) children.get(i);
        if (child != null) child.computeCombineBounds(boundingObject);
      }

      if (VirtualUniverse.mc.cacheAutoComputedBounds) {
        cachedBounds = (Bounds) boundingObject.clone();
      }
    } else {
      // Should this be lock too ? ( MT safe  ? )
      synchronized (localBounds) {
        boundingObject.set(localBounds);
      }
    }

    // Should this be lock too ? ( MT safe  ? )
    // Thoughts :
    // Make a temp copy with lock :  transform.getWithLock(trans);, but this will cause gc ...
    synchronized (transform) {
      boundingObject.transform(transform);
    }
    bounds.combine(boundingObject);
  }
示例#18
0
 public double getWeight(double[] point) {
   double w = 0;
   if (bounds.contains(point)) {
     if (null == right && null == left) {
       w += count;
     } else {
       if (null != right) {
         w += right.getWeight(point);
       }
       if (null != left) {
         w += left.getWeight(point);
       }
     }
   }
   return w;
 }
示例#19
0
 public double getWeight(Bounds b) {
   double w = 0;
   if (bounds.intersects(b)) {
     if (null == right && null == left) {
       w += count;
     } else {
       if (null != right) {
         w += right.getWeight(b);
       }
       if (null != left) {
         w += left.getWeight(b);
       }
     }
   }
   return w;
 }
示例#20
0
文件: Bounds.java 项目: JoaPiep/VRL
  /**
   * Indicates whether the specified bounding box intersects with this bounding box (check includes
   * box boundary).
   *
   * @param b box to check
   * @return {@code true} if the bounding box intersects this bounding box; {@code false} otherwise
   */
  public boolean intersects(Bounds b) {

    if (b.getMin().x > this.getMax().x || b.getMax().x < this.getMin().x) {
      return false;
    }
    if (b.getMin().y > this.getMax().y || b.getMax().y < this.getMin().y) {
      return false;
    }
    if (b.getMin().z > this.getMax().z || b.getMax().z < this.getMin().z) {
      return false;
    }

    return true;
  }
示例#21
0
  @Override
  protected void render(GL g) {
    GL2 gl = g.getGL2();

    gl.glColor3f(.5f, .5f, .5f);

    // =======================================\\
    // Retained Mode \\
    // =======================================\\
    gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
    gl.glVertexPointer(3, GL2.GL_FLOAT, 0, vertexBuffer);

    if (normal) {
      gl.glEnableClientState(GL2.GL_NORMAL_ARRAY);
      gl.glNormalPointer(GL2.GL_FLOAT, 0, normalBuffer);
    }

    if (texture) {
      gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
      gl.glTexCoordPointer(2, GL2.GL_FLOAT, 0, textureBuffer);
    } else gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE);

    for (IntBuffer face : faces) {
      if (face.capacity() == 3)
        gl.glDrawElements(GL2.GL_TRIANGLES, face.capacity(), GL2.GL_UNSIGNED_INT, face);
      else if (face.capacity() == 4)
        gl.glDrawElements(GL2.GL_QUADS, face.capacity(), GL2.GL_UNSIGNED_INT, face);
      else gl.glDrawElements(GL2.GL_POLYGON, face.capacity(), GL2.GL_UNSIGNED_INT, face);
    }

    gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);

    if (normal) gl.glDisableClientState(GL2.GL_NORMAL_ARRAY);

    if (texture) gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY);

    if (drawBox) bbox.draw(gl);
  }
示例#22
0
 /**
  * Creates a new rectangle that fits perfectly in the bounding box bounds.
  *
  * @param bounds
  */
 public RectangularShape(Bounds bounds) {
   x = bounds.getX();
   y = bounds.getY();
   width = bounds.getWidth();
   height = bounds.getHeight();
 }
示例#23
0
  public void initMMBean() throws InvalidBoundsException {
    PKNames.clear();
    circlePoints.clear();
    PKBean.setAlpha(inp.getAlpha());
    PKBean.setBeta(inp.getBeta());
    PKBean.setEccintricity(inp.getEccintricity());
    PKBean.setKa(inp.getKa());
    PKBean.setPb(inp.getPb());
    PKBean.setPbGal(inp.getPbGal());
    PKBean.setPbKin(inp.getPbKin());
    PKBean.setePbGal(inp.getePbGal());
    PKBean.setePbKin(inp.getePbKin());
    PKBean.setAlphaPulsar(inp.getAlphaPulsar());
    PKBean.setAlphaCompanion(inp.getAlphaCompanion());
    PKBean.setBetaPulsar(inp.getBetaPulsar());
    PKBean.setBetaCompanion(inp.getBetaCompanion());
    Bounds linBounds = new Bounds(inp.getMinMp(), inp.getMaxMp(), inp.getNumPts(), false);
    Bounds logBounds = new Bounds(inp.getMinMp(), inp.getMaxMp(), inp.getNumPts(), true);
    Bounds ratioBounds =
        new Bounds(
            inp.getMinMp() / inp.getMaxMp(),
            inp.getMaxMp() / inp.getMinMp(),
            inp.getNumPts(),
            true);
    Bounds ratioLinBounds =
        new Bounds(
            inp.getMinMp() / (double) inp.getMaxMp(),
            inp.getMaxMp() / (double) inp.getMinMp(),
            inp.getNumPts(),
            false);

    if (inp.isPlotMassFunc()) {
      PKBean massFunc =
          new PKBean(Constants.massfunc, inp.getMassFunc(), inp.geteMassFunc(), ratioBounds.copy());
      MMLine massFuncLine = new MMLine(Constants.massfunc);
      massFuncLine.setColor(Color.MEDIUMAQUAMARINE);
      massFuncLine.setActive(true);
      pkBeanMap.put(Constants.massfunc, massFunc);
      mmLinesMap.put(Constants.massfunc, massFuncLine);
    }

    if (inp.isPlotMassRatio()) {
      PKBean massRatio =
          new PKBean(Constants.massratio, inp.getMassRatio(), inp.geteMassFunc(), linBounds.copy());
      MMLine massRatioLine = new MMLine(Constants.massratio);
      massRatioLine.setColor(Color.MEDIUMPURPLE);
      massRatioLine.setActive(true);
      pkBeanMap.put(Constants.massratio, massRatio);
      mmLinesMap.put(Constants.massratio, massRatioLine);
      leastErrorPKName = Constants.massratio;
      PKNames.add(Constants.massratio);
      // System.err.println("****** Least Error Line: "+leastErrorPKName);
    }

    if (inp.isPlotPbDot()) {
      PKBean pbDot = new PKBean(Constants.pbdot, inp.getPbDot(), inp.getePbDot(), ratioBounds);
      MMLine pbDotLine = new MMLine(Constants.pbdot);
      pbDotLine.setColor(Color.MEDIUMVIOLETRED);
      pbDotLine.setActive(true);
      pkBeanMap.put(Constants.pbdot, pbDot);
      mmLinesMap.put(Constants.pbdot, pbDotLine);
      leastErrorPKName = getLeastErrorLine(pkBeanMap.get(leastErrorPKName), pbDot);
      PKNames.add(Constants.pbdot);
      // System.err.println("****** Least Error Line: "+leastErrorPKName);

      //			PKBean pbDotFreire = new PKBean(Constants.pbdotFreire, inp.getPbDot(), inp.getePbDot(),
      // ratioLinBounds.copy());
      //			MMLine pbDotFreireLine = new MMLine(Constants.pbdotFreire);
      //			pbDotFreireLine.setColor(Color.MEDIUMAQUAMARINE);
      //			pbDotFreireLine.setActive(true);
      //			pkBeanMap.put(Constants.pbdotFreire, pbDotFreire);
      //			mmLinesMap.put(Constants.pbdotFreire, pbDotFreireLine);
      //			System.err.println("****** Least Error Line: "+leastErrorPKName);
      //
    }

    if (inp.isPlotOmDot()) {
      PKBean omDot =
          new PKBean(Constants.omdot, inp.getOmDot(), inp.geteOmDot(), ratioBounds.copy());
      MMLine omDotLine = new MMLine(Constants.omdot);
      omDotLine.setColor(Color.DARKGOLDENROD);
      omDotLine.setActive(true);
      pkBeanMap.put(Constants.omdot, omDot);
      mmLinesMap.put(Constants.omdot, omDotLine);
      leastErrorPKName = getLeastErrorLine(pkBeanMap.get(leastErrorPKName), omDot);
      PKNames.add(Constants.omdot);
      // System.err.println("****** Least Error Line: "+leastErrorPKName);
    }

    if (inp.isPlotGamma()) {
      PKBean gamma =
          new PKBean(Constants.gamma, inp.getGamma(), inp.geteGamma(), ratioBounds.copy());
      MMLine gammaLine = new MMLine(Constants.gamma);
      gammaLine.setColor(Color.DARKSALMON);
      gammaLine.setActive(true);
      pkBeanMap.put(Constants.gamma, gamma);
      mmLinesMap.put(Constants.gamma, gammaLine);
      leastErrorPKName = getLeastErrorLine(pkBeanMap.get(leastErrorPKName), gamma);
      PKNames.add(Constants.gamma);
      //	System.err.println("****** Least Error Line: "+leastErrorPKName);

    }

    // System.err.println("mmLinesMap"+mmLinesMap.size());

  }
示例#24
0
 /** Return true if shape intersect with bounds. The point of intersection is stored in pickPos. */
 @Override
 final boolean intersect(Bounds bounds, Point4d pickPos) {
   return bounds.intersect(start, end, pickPos);
 }
示例#25
0
  private void reorganizeGridAbove(int x, int y, int w) {
    Set<IFormField> fieldsToReorganize = new HashSet<IFormField>();
    Map<MatrixIndex, Cell> occupiedCells = new HashMap<MatrixIndex, Cell>();
    Bounds reorgBounds = new Bounds(x, 0, w, y + 1);

    int minY = y;
    int usedCells = 0;
    boolean continueLoop = true;
    for (int yi = y; yi >= 0 && continueLoop; yi--) {
      for (int xi = x; xi < x + w && continueLoop; xi++) {
        MatrixIndex matrixIndex = new MatrixIndex(xi, yi);
        Cell cell = m_cells.get(matrixIndex);
        if (cell != null && !cell.isEmpty()) {
          GridData gd = cell.fieldGridData;

          if (horizontalMatchesOrOverlaps(reorgBounds, gd)) {
            continueLoop = false;
          } else if (horizontalOverlapsOnSide(reorgBounds, gd)) {
            // freeze the cells for reorganization
            occupiedCells.put(matrixIndex, cell);
            usedCells++;
            minY = Math.min(matrixIndex.y, minY);
          }
          // includes
          else {
            // add field to reorganization
            m_cells.remove(matrixIndex);
            fieldsToReorganize.add(cell.field);
            usedCells++;
            minY = Math.min(matrixIndex.y, minY);
          }
        }
      }
    }
    if (fieldsToReorganize.isEmpty()) {
      return;
    }
    // sort fields
    List<IFormField> sortedFieldsToReorganize = new ArrayList<IFormField>(fieldsToReorganize);
    Collections.sort(
        sortedFieldsToReorganize,
        new Comparator<IFormField>() {
          @Override
          public int compare(IFormField o1, IFormField o2) {
            Integer i1 = m_formFieldIndexes.get(o1);
            Integer i2 = m_formFieldIndexes.get(o2);
            return i1.compareTo(i2);
          }
        });
    reorgBounds.y = minY;

    VerticalGridMatrix reorgMatrix =
        new VerticalGridMatrix(
            reorgBounds.x,
            reorgBounds.y,
            reorgBounds.w,
            (usedCells + reorgBounds.w - 1) / reorgBounds.w);
    reorgMatrix.addCells(occupiedCells);
    while (!reorgMatrix.computeGridData(sortedFieldsToReorganize)) {
      reorgMatrix.resetAll(reorgMatrix.getColumnCount(), reorgMatrix.getRowCount() + 1);
    }
    m_cursor.reset();
    m_cells.putAll(reorgMatrix.getCells());
    m_fieldGridDatas.putAll(reorgMatrix.getFieldGridDatas());
  }
示例#26
0
 public Generation(final Bounds bounds) {
   this.bounds = bounds;
   this.world = new BitSet(bounds.size());
 }
示例#27
0
 public Bounds getOffsetBounds(AttributeSet attrs) {
   return Bounds.create(-30, -50, 60, 100);
 }
示例#28
0
  @Override
  public void onSelectionSucceeded(final List<BallActor> selection) {
    // Extract the data from the selection.
    List<Ball> balls = new ArrayList<>();
    for (BallActor selectedBall : selection) balls.add(selectedBall.getBall());
    final Bounds bounds = Bounds.fromBallList(balls);

    // Change the colors of the selected region.
    board.addAction(
        Actions.sequence(
            board.hideRegion(bounds),
            Actions.run(
                new Runnable() {
                  @Override
                  public void run() {
                    for (BallActor selectedBall : selection) {
                      selectedBall.setColor(Color.WHITE);
                    }
                    generate(bounds);
                    // Reset the cheat
                    game.getState().setCheatSeen(false);
                    game.getState().setWiggledBounds(null);
                  }
                })));

    // Give some score to the user.
    ScoreCalculator calculator = new ScoreCalculator(game.getState().getBoard(), bounds);
    int givenScore = calculator.calculate();
    game.getState().addScore(givenScore);
    score.giveScore(givenScore);

    // Put information about this combination in the stats.
    int rows = bounds.maxY - bounds.minY + 1;
    int cols = bounds.maxX - bounds.minX + 1;
    String size = Math.max(rows, cols) + "x" + Math.min(rows, cols);
    game.statistics.getSizesData().incrementValue(size);

    BallColor color = board.getBall(bounds.minX, bounds.minY).getBall().getColor();
    game.statistics.getColorData().incrementValue(color.toString().toLowerCase());
    game.statistics.getTotalData().incrementValue("balls", rows * cols);
    game.statistics.getTotalData().incrementValue("combinations");

    // Now, display the score to the user. If the combination is a
    // PERFECT combination, just display PERFECT.
    int boardSize = game.getState().getBoard().getSize() - 1;
    if (bounds.equals(new Bounds(0, 0, boardSize, boardSize))) {
      // Give score
      Label label = new Label("PERFECT", game.getSkin(), "monospace");
      label.setX((getStage().getViewport().getWorldWidth() - label.getWidth()) / 2);
      label.setY((getStage().getViewport().getWorldHeight() - label.getHeight()) / 2);
      label.setFontScale(3);
      label.setAlignment(Align.center);
      label.addAction(Actions.sequence(Actions.moveBy(0, 80, 0.5f), Actions.removeActor()));
      getStage().addActor(label);
      game.player.playSound(SoundCode.PERFECT);

      // Give time
      float givenTime = Constants.SECONDS - timer.getSeconds();
      timer.giveTime(givenTime, 4f);
    } else {
      // Was special?
      boolean special = givenScore != rows * cols;
      // Give score
      showPartialScore(givenScore, bounds, special);
      game.player.playSound(SoundCode.SUCCESS);

      // Give time
      float givenTime = 4f;
      timer.giveTime(givenTime, 0.25f);
    }
  }