Example #1
0
Card *Deck::cardForDistanceFromEdge( int distanceFromEdge )
{
	if (distanceFromEdge <= root()->length() / 2) return 0L;
	if (distanceFromEdge >= length() - (tail()->length() / 2)) return tail();

	Card *target = 0L;
	int cCount = count();
	int previousCenter = root()->length() / 2, currentCenter = 0;
	for (int i = 1; i < cCount; i++)
	{
		Card *card = cardAt(i);
		int cardLength = card->length();
		currentCenter = previousCenter + (cardAt( i - 1)->length() / 2) + (cardLength / 2);

		if (distanceFromEdge >= previousCenter && distanceFromEdge < currentCenter)
		{
			target = cardAt( i - 1);
			break;
		}

		previousCenter = currentCenter;
	}

	return target;
}
Example #2
0
//move
Card *HumanPlayer::makeMove (Card *lMove, Card *rMove, Player *aLeftPlayer, Player *aRightPlayer, bool isPassOut) {
  Q_UNUSED(aLeftPlayer)
  Q_UNUSED(aRightPlayer)
  Q_UNUSED(isPassOut)
  Q_ASSERT(mDeskView);
  qDebug() << type() << "("<< mPlayerNo << ") moves";
  Card *res = 0;
  mClickX = mClickY = 0; mWaitingForClick = true;
  m_model->showMoveHint();
  draw();
  int cNo = -1;
  while (!res) {
    mDeskView->mySleep(-2);
    cNo = cardAt(mClickX, mClickY, !invisibleHand());
    if (cNo == -1) {
      mClickX = mClickY = 0;
      continue;
    }
    const int koz = mDeskView->model()->trumpSuit();
    res = mCards.at(cNo);
    // check if move accords with rules
    if (!isValidMove(res, lMove, rMove, koz)) {
      res = 0;
    }
  }
  clearCardArea();
  mPrevHiCardIdx = -1;
  mCards.remove(res);
  mCardsOut.insert(res);
  mClickX = mClickY = 0; mWaitingForClick = false;
  m_model->emitClearHint();
  draw();
  return res;
}
Example #3
0
void Deck::calculateDeckWidth( void )
{
	int maxWidth = -1;
	int cCount = count();
	for (int i = 0; i < cCount; i++)
	{
		int cW = calculateCardWidth(cardAt(i));
		if (cW > maxWidth) maxWidth = cW;
	}

	//now, resize all cards to this width
	for (int i = 0; i < cCount; i++)
	{
		setCardWidth(cardAt(i), maxWidth);
	}
}
Example #4
0
Deck* Deck::setPosition(double pos, ScreenEdge e, bool checkCollisions, int distanceFromEdge)
{
	if (pos < 0) pos = 0;
	else if (pos > 1.0) pos = 1.0;

	_position = pos;

	if (e != None)
	{
		setEdge(e);
	}

	Deck *deckTo =  Manager::instance()->positionDeck(this, _position, _edge,
	                                                  _screen, checkCollisions,
	                                                  distanceFromEdge);

	//now, propagate movement to all cards in this deck (except root, since it already knows)
	int nCards = count();
	for (int i = 1; i < nCards; i++)
	{
		Card *card = cardAt(i);
		if (card) card->followDeck(_position, _edge);
	}

	return deckTo;
}
Example #5
0
int Deck::indexOf(Card *c)
{
	int cCount = count();
	for (int i = 0; i < cCount; i++)
	{
		if (cardAt(i) == c)
		{
			return i;
		}
	}

	return -1;
}
Example #6
0
void HumanPlayer::highlightCard (int lx, int ly)
{
  if (!mWaitingForClick) {
    // not in "card selection" mode
    if (mPrevHiCardIdx == -1) return; // nothing selected --> nothing to redraw
    mPrevHiCardIdx = -1;
  } else {
    int cNo = cardAt(lx, ly, !invisibleHand());
    if (cNo == mPrevHiCardIdx) return; // same selected --> nothing to redraw
    mPrevHiCardIdx = cNo;
  }
  draw();
  m_model->emitClearHint();
}
Example #7
0
void Deck::applyShapeMask( void )
{
	QRegion mask(0, 0, width(), height());

	int r(width());
	int b(height());

	// Remove top-left corner.
	if (_shapeMask & TopLeft)
	{
		mask -= QRegion(0, 0, 5, 1);
		mask -= QRegion(0, 1, 3, 1);
		mask -= QRegion(0, 2, 2, 1);
		mask -= QRegion(0, 3, 1, 2);
	}

	// Remove top-right corner.
	if (_shapeMask & TopRight)
	{
		mask -= QRegion(r - 5, 0, 5, 1);
		mask -= QRegion(r - 3, 1, 3, 1);
		mask -= QRegion(r - 2, 2, 2, 1);
		mask -= QRegion(r - 1, 3, 1, 2);
	}

	// Remove bottom-left corner.
	if (_shapeMask & BottomLeft)
	{
		mask -= QRegion(0, b - 5, 1, 3);
		mask -= QRegion(0, b - 3, 2, 1);
		mask -= QRegion(0, b - 2, 3, 1);
		mask -= QRegion(0, b - 1, 5, 1);
	}

	// Remove bottom-right corner.
	if (_shapeMask & BottomRight)
	{
		mask -= QRegion(r - 5, b - 1, 5, 1);
		mask -= QRegion(r - 3, b - 2, 3, 1);
		mask -= QRegion(r - 2, b - 3, 2, 1);
		mask -= QRegion(r - 1, b - 5, 1, 2);
	}

	setMask(mask);

		/*
			now that the edge state has changed, make all cards in this
			deck repaint. They'll read the adjacentEdge() property to
			figure this stuff out.
		*/

	if (mask != _currentMask)
	{
		int cCount = count();
		for (int i = 0; i < cCount; i++)
		{
			Card *c = cardAt(i);
			if (c) c->repaintElements();
		}
	}

	_currentMask = mask;

}
Example #8
0
Card *Deck::tail( void )
{
	return cardAt(count() - 1);
}