Ejemplo n.º 1
0
/**
 * 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);
                }
            }
        }
    }
}