예제 #1
0
  public void OrganizeCards() {
    int size = mInPlayCards.GetCards().size();
    float width = Director.instance().getAssets().get("cards", CardResource.class).getWidth();
    int rows = (size / cardsHorizontal) + 1;
    int lastCol = size % cardsHorizontal;
    float height = (width * overlapPercentY * (size / (cardsHorizontal + 1)));
    setHeight(height + mCardHeight);
    float startY = getHeight() - mCardHeight;
    int i = 0, x = 0, y = 0;
    int col = 0;
    for (y = 0; y < rows; ++y) {
      if (y == rows - 1) col = lastCol;
      else col = cardsHorizontal;
      if (y % 2 == 0) { // even
        for (x = 0; x < col; ++x) {
          CardView cv = CardView.getCardView(mInPlayCards.GetCards().get(i));
          HandUtils.Reparent(this, cv);
          cv.setPosition(width * overlapPercentX * x, startY);
          cv.setRotation(0);
          cv.setSide(CardView.Side.FRONT);
          i++;
        }
      } else { // odd
        for (x = 0; x < col; ++x) {
          CardView cv = CardView.getCardView(mInPlayCards.GetCards().get(i));
          HandUtils.Reparent(this, cv);
          cv.setPosition(width * overlapPercentX * (cardsHorizontal - 1 - x), startY);
          cv.setRotation(0);
          cv.setSide(CardView.Side.FRONT);
          i++;
        }
      }
      startY -= (width * overlapPercentY);
    }
    float nextX = 0.0f;
    float nextY = 0.0f;
    if (x < cardsHorizontal) {
      y = rows - 1;
      nextY = startY + (width * overlapPercentY);
      if (y % 2 == 0) // even
      nextX = width * overlapPercentX * x;
      else nextX = width * overlapPercentX * (cardsHorizontal - 1 - x);
    } else {
      x = 0;
      y = rows;
      nextY = startY;
      if (y % 2 == 0) // even
      nextX = width * overlapPercentX * x;
      else nextX = width * overlapPercentX * (cardsHorizontal - 1 - x);
    }
    mNextPosition.set(nextX, nextY);

    if (rows - 1 == 0) setWidth(width + (width * overlapPercentX * (lastCol - 1)));
    else setWidth(width + (width * overlapPercentX * (cardsHorizontal - 1)));

    // reposition
    if (mDeck == null) return;
    setY(mDeck.getY() - (getHeight() - mCardHeight));
  }
예제 #2
0
 @Override
 public String toString() {
   int max = Math.max(mInPlayCards.GetCards().size(), getChildren().size);
   String s = "InPlayView:\n";
   for (int i = 0; i < max; ++i) {
     s +=
         String.format(
             "%s\t%s\n",
             i < mInPlayCards.GetCards().size() ? mInPlayCards.GetCards().get(i) : null,
             i < getChildren().size ? getChildren().get(i) : null);
   }
   return s;
 }
예제 #3
0
 public Vector2 GetNextPosition() {
   int size = mInPlayCards.GetCards().size();
   int width = mCardWidth;
   int rows = (size / cardsHorizontal) + 1;
   int currentRow = rows - 1;
   int lastCol = size % cardsHorizontal;
   float height = (width * overlapPercentY * (currentRow));
   if (size == 0) return new Vector2(0, getHeight() - mCardHeight);
   float y = -currentRow * width * overlapPercentY;
   float x;
   if (currentRow % 2 == 0) x = width * overlapPercentX * lastCol;
   else x = width * overlapPercentX * (cardsHorizontal - (lastCol + 1));
   y += getHeight() - mCardHeight;
   return new Vector2(x, y);
 }