示例#1
0
/**
 * 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());
}
示例#2
0
/**
 * writes a Text + the Card suit and value in the History doc
 * @brief GameHistory::write
 * @param text
 * @param suit
 * @param value
 */
void GameHistory::write(QString text, Card::cardSuit suit, Card::cardValue value)
{
    QString hand;
    Card c = Card(suit,value);
    CardItem item = CardItem(c);
    hand += cardToString(item);
    QString full(text + " - "+ hand);
    QTextStream out(file);
    out.setAutoDetectUnicode(true);
    out << full << "\n";
}
示例#3
0
/**
 * Starts the game and initializes the Depot/Stack and so on
 * @brief Playground::startGame
 */
void Playground::startGame()
{
    this->removeItem(textItem);
    history.write("Start new Game\n=====================");
    soundMgr.startSound();
    stack = (CardItem::specialCards::RED_VERTICAL);
    depot = CardItem(CardItem::specialCards::DEPOT);

    this->setDepotNStack();

    this->addItem(stack.createImg());
    this->addItem(depot.createImg());
    soundMgr.playBackgroundSong();
}
示例#4
0
/**
 * 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());
}
示例#5
0
void CardsList::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    if(!ls.empty())
    {
        int fmHeight = painter.fontMetrics().height();
        int h = height(), cardHeight = cardSize.height(),
                cardWidth = cardSize.width();

        cardsPerColumn = h / cardHeight;

        decltype(items) newItems;

        double varHeight = h - cardHeight * 1.0;

        for(int i : range(std::min(cardsPerColumn, ls.size() - pos)))
        {
            quint32 id = ls[i + pos];

            auto it = newItems.insert(i + pos, CardItem(id));

            auto &item = it.value();

            int y = varHeight * i / (cardsPerColumn - 1);


            current = itemAt(mapFromGlobal(QCursor::pos()));
            if(i + pos == current)
            {
                QBrush brush = painter.brush(), newBrush(Qt::lightGray);
                QPen pen = painter.pen();
                painter.setPen(Qt::transparent);
                QColor color(newBrush.color());
                color.setAlpha(160);
                newBrush.setColor(color);
                painter.setBrush(newBrush);
                painter.drawRect(QRect(QPoint(0,  y), QSize(sb->geometry().x(), cardSize.height())));
                painter.setBrush(brush);
                painter.setPen(pen);
            }

            item.setPos(QPoint(0, y));

            painter.drawPixmap(0, y, cardWidth, cardHeight,
                               *item.getPixmap().data());

            int lim = limitCards->getLimit(it->getId());
            if(lim < 3)
            {
                auto data = limitCards->getPixmap(lim);
                if(data)
                {
                    painter.drawPixmap(0, y, 16, 16, *data);
                }
            }

            call_with_ref([&](Card &card) {

                painter.drawText(cardWidth + 5, y + fmHeight, card.name);
                QString ot;
                QString level = (card.type & Const::TYPE_XYZ) ? "R" : "L";
                level = "[" + level + QString::number(card.level) + "]";
                if((card.ot & 0x3) == 1)
                {
                    ot = tr("[OCG]");
                }
                else if((card.ot & 0x3) == 2)
                {
                    ot = tr("[TCG]");
                }

                if(card.type & Const::TYPE_MONSTER)
                {
                    painter.drawText(cardWidth + 5, y + 5 + fmHeight * 2,
                                     card.cardRace() + "/" + card.cardAttr() + level);

                    painter.drawText(cardWidth + 5, y + 10 + fmHeight * 3,
                                     adToString(card.atk) + "/" +
                                     adToString(card.def) + ot);
                }
                else if(card.type & (Const::TYPE_SPELL | Const::TYPE_TRAP))
                {
                    painter.drawText(cardWidth + 5, y + 5 + fmHeight * 2,
                                     card.cardType());
                    painter.drawText(cardWidth + 5, y + 10 + fmHeight * 3, ot);
                }
            }, cardPool->getCard(id));
        }
        items.swap(newItems);
    }
    if(needRefreshId)
    {
        refreshCurrentId();
        needRefreshId = false;
    }
    refresh();
}