/** * updates the Player card with animation from stack to the playerhand * @brief Playground::updatePlayerCard * @param fromCard * @param toCard * @param withAnimation */ void Playground::updatePlayerCard(CardItem& fromCard, CardItem& toCard, bool withAnimation) { fromCard.setPos(stack.getX(), stack.getY()); addItem(fromCard.createImg()); qreal x = toCard.getX(); qreal y = toCard.getY(); if (withAnimation) { QEventLoop pause; prepareNewAnimation(pause); addPositionAnimation(*fromCard.createImg(), *toCard.createImg()); startAnimation(); pause.exec(); } if ((&toCard) != NULL) { } toCard = CardItem(fromCard); toCard.setPos(x, y); toCard.createImg()->setZValue(zValue); zValue++; addItem(toCard.createImg()); update(sceneRect()); }
/** * MouseEvent for clicking on a humanCard or on the Stack * @brief Playground::mousePressEvent * @param event */ void Playground::mousePressEvent(QGraphicsSceneMouseEvent* event) { if (event->button() == Qt::LeftButton) { QGraphicsItem* item = itemAt(event->buttonDownScenePos(event->button()), QTransform()); if (item != NULL) { //Clicked on Stack if (item == stack.createImg()) { players.value(PlayerItem::direction::HUMAN)->unsetPlayableCards(); players.value(PlayerItem::direction::HUMAN)->setUnactive(); emit drawCard(); } //Clicked on Human Card PlayerItem* human = players.value(PlayerItem::direction::HUMAN); for (int j = 0; j < human->getCards()->size(); ++j) { CardItem* c = human->getCards()->at(j); if (c->createImg() == item && c->getPlayable()) { history.write("You play a Card", c->getCard().getSuit(), c->getCard().getValue()); Card::cardSuit chosenColor = Card::NONE; if (c->getCard().getValue() == wishSuitCard) { chosenColor = chooseColor(); } soundMgr.playCard(); updateDepotCard(*c, depot); soundMgr.drawCard(); human->removeCard(c->getCard()); human->unsetPlayableCards(); human->setUnactive(); emit playCard(depot.getCard(), chosenColor); } } } } }
/** * updates the Depot Card * @brief Playground::updateDepotCard * @param fromCard * @param toCard * @param withAnimation with Animation or without */ void Playground::updateDepotCard(CardItem& fromCard, CardItem& toCard, bool withAnimation) { qreal x = toCard.getX(); qreal y = toCard.getY(); if (withAnimation) { QEventLoop pause; prepareNewAnimation(pause); addPositionAnimation(*fromCard.createImg(), *toCard.createImg()); startAnimation(); pause.exec(QEventLoop::AllEvents); } removeItem(toCard.createImg()); toCard = CardItem(fromCard.getCard()); toCard.setPos(x, y); toCard.createImg()->setZValue(zValue); zValue++; addItem(toCard.createImg()); update(sceneRect()); }